Cleanup Twitter plugin and update docs a bit.

This commit is contained in:
Brit Butler 2014-05-09 11:54:22 -04:00
parent a4d7b8505c
commit 947ad9023b
3 changed files with 22 additions and 42 deletions

View file

@ -3,7 +3,8 @@
* A Twitter plugin to tweet your new posts. Thanks to @PuercoPop! * A Twitter plugin to tweet your new posts. Thanks to @PuercoPop!
* Coleslaw now exports a `get-updated-files` function which can be * 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 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): ## Changes for 0.9.4 (2014-05-05):

View file

@ -50,8 +50,8 @@
The PAGE content type cheats a bit by reusing the existing POST template. The PAGE content type cheats a bit by reusing the existing POST template.
* **New service integrations**, for example crossposting to * **New service integrations**, for example crossposting to
twitter/facebook/tumblr/livejournal/etc, should also be possible by twitter/facebook/tumblr/livejournal/etc, is also possible by
adding an :after hook to the deploy method as with adding an :after hook to the deploy method. The hook can iterate
hosting but this is dependent on knowing which posts are new over the results of the `get-updated-files` to crosspost any new content.
which should become possible before 1.0. See the incremental compilation The [Twitter plugin](https://github.com/redline6561/coleslaw/blob/master/plugins/twitter.lisp)
notes in the hacking docs for further details. is a good example of this.

View file

@ -22,8 +22,8 @@
coleslaw:post and returns the tweet content.") coleslaw:post and returns the tweet content.")
(defvar *tweet-format-dsl-mapping* (defvar *tweet-format-dsl-mapping*
'((:title . title-of) '((:title title-of)
(:author . author-of))) (:author author-of)))
(define-condition malformed-tweet-format (error) (define-condition malformed-tweet-format (error)
((item :initarg :item :reader item)) ((item :initarg :item :reader item))
@ -33,38 +33,17 @@ coleslaw:post and returns the tweet content.")
(item condition))))) (item condition)))))
(defun compile-tweet-format (tweet-format) (defun compile-tweet-format (tweet-format)
(multiple-value-bind (flet ((accessor-for (x)
(fmt-ctrl-str accesors) (%compile-tweet-format tweet-format nil nil) (rest (assoc x *tweet-format-dsl-mapping*))))
(let (lambda (post)
((fmt-ctrl-str (format nil "~{~A~^ ~}" (reverse fmt-ctrl-str))) (apply #'format nil "~{~A~^ ~}"
(accesors (reverse accesors))) (loop for item in *tweet-format*
(lambda (post) unless (or (keywordp item) (stringp item))
(apply #'format nil fmt-ctrl-str (error 'malformed-tweet-format :item item)
(loop when (keywordp item)
:for accesor :in accesors collect (funcall (accessor-for item) post)
:collect (funcall accesor post))))))) when (stringp item)
collect item)))))
(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*))
(defun enable (&key api-key api-secret access-token access-secret tweet-format) (defun enable (&key api-key api-secret access-token access-secret tweet-format)
(if (and api-key api-secret access-token access-secret) (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 ;; fallback to chirp for credential erros
(chirp:account/verify-credentials) (chirp:account/verify-credentials)
(when tweet-format (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) (defmethod deploy :after (staging)
(declare (ignore staging)) (declare (ignore staging))