Cleanup Twitter plugin and update docs a bit.
This commit is contained in:
parent
a4d7b8505c
commit
947ad9023b
3 changed files with 22 additions and 42 deletions
3
NEWS.md
3
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):
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Add table
Reference in a new issue