From 947ad9023bfaa9747b341457324cb9933e0a40ea Mon Sep 17 00:00:00 2001 From: Brit Butler Date: Fri, 9 May 2014 11:54:22 -0400 Subject: [PATCH] Cleanup Twitter plugin and update docs a bit. --- NEWS.md | 3 ++- docs/plugin-api.md | 10 ++++----- plugins/twitter.lisp | 51 +++++++++++++------------------------------- 3 files changed, 22 insertions(+), 42 deletions(-) diff --git a/NEWS.md b/NEWS.md index 1c192cf..6fa1655 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,7 +3,8 @@ * A Twitter plugin to tweet your new posts. Thanks to @PuercoPop! * Coleslaw now exports a `get-updated-files` function which can be used to get a list of file-status/file-name pairs that were changed - in the last git push. + in the last git push. There is also an exported `find-content-by-path` + function to retrieve content objects from the above file-name. ## Changes for 0.9.4 (2014-05-05): diff --git a/docs/plugin-api.md b/docs/plugin-api.md index 6d25d78..f2108aa 100644 --- a/docs/plugin-api.md +++ b/docs/plugin-api.md @@ -50,8 +50,8 @@ The PAGE content type cheats a bit by reusing the existing POST template. * **New service integrations**, for example crossposting to - twitter/facebook/tumblr/livejournal/etc, should also be possible by - adding an :after hook to the deploy method as with - hosting but this is dependent on knowing which posts are new - which should become possible before 1.0. See the incremental compilation - notes in the hacking docs for further details. + twitter/facebook/tumblr/livejournal/etc, is also possible by + adding an :after hook to the deploy method. The hook can iterate + over the results of the `get-updated-files` to crosspost any new content. + The [Twitter plugin](https://github.com/redline6561/coleslaw/blob/master/plugins/twitter.lisp) + is a good example of this. diff --git a/plugins/twitter.lisp b/plugins/twitter.lisp index e1fdb24..2244630 100644 --- a/plugins/twitter.lisp +++ b/plugins/twitter.lisp @@ -22,8 +22,8 @@ coleslaw:post and returns the tweet content.") (defvar *tweet-format-dsl-mapping* - '((:title . title-of) - (:author . author-of))) + '((:title title-of) + (:author author-of))) (define-condition malformed-tweet-format (error) ((item :initarg :item :reader item)) @@ -33,38 +33,17 @@ coleslaw:post and returns the tweet content.") (item condition))))) (defun compile-tweet-format (tweet-format) - (multiple-value-bind - (fmt-ctrl-str accesors) (%compile-tweet-format tweet-format nil nil) - (let - ((fmt-ctrl-str (format nil "~{~A~^ ~}" (reverse fmt-ctrl-str))) - (accesors (reverse accesors))) - (lambda (post) - (apply #'format nil fmt-ctrl-str - (loop - :for accesor :in accesors - :collect (funcall accesor post))))))) - -(defun %compile-tweet-format (tweet-format fmt-ctrl-str accesors) - "Transform tweet-format into a format control string and a list of values." - (if (null tweet-format) - (values fmt-ctrl-str accesors) - (let ((next (car tweet-format))) - (cond - ((keywordp next) - (if (assoc next *tweet-format-dsl-mapping*) - (%compile-tweet-format - (cdr tweet-format) - (cons "~A" fmt-ctrl-str) - (cons (cdr (assoc next *tweet-format-dsl-mapping*)) - accesors)) - (error 'malformed-tweet-format :item next))) - ((stringp next) - (%compile-tweet-format (cdr tweet-format) - (cons next fmt-ctrl-str) - accesors)) - (t (error 'malformed-tweet-format :item next)))))) - -(setf *tweet-format-fn* (compile-tweet-format *tweet-format*)) + (flet ((accessor-for (x) + (rest (assoc x *tweet-format-dsl-mapping*)))) + (lambda (post) + (apply #'format nil "~{~A~^ ~}" + (loop for item in *tweet-format* + unless (or (keywordp item) (stringp item)) + (error 'malformed-tweet-format :item item) + when (keywordp item) + collect (funcall (accessor-for item) post) + when (stringp item) + collect item))))) (defun enable (&key api-key api-secret access-token access-secret tweet-format) (if (and api-key api-secret access-token access-secret) @@ -78,8 +57,8 @@ coleslaw:post and returns the tweet content.") ;; fallback to chirp for credential erros (chirp:account/verify-credentials) (when tweet-format - (setf *tweet-format* tweet-format))) - + (setf *tweet-format* tweet-format)) + (setf *tweet-format-fn* (compile-tweet-format *tweet-format*))) (defmethod deploy :after (staging) (declare (ignore staging))