Parcourir la Source

Cleanup Twitter plugin and update docs a bit.

Brit Butler il y a 11 ans
Parent
commit
947ad9023b
3 fichiers modifiés avec 22 ajouts et 42 suppressions
  1. 2 1
      NEWS.md
  2. 5 5
      docs/plugin-api.md
  3. 15 36
      plugins/twitter.lisp

+ 2 - 1
NEWS.md

@@ -3,7 +3,8 @@
3 3
 * A Twitter plugin to tweet your new posts. Thanks to @PuercoPop!
4 4
 * Coleslaw now exports a `get-updated-files` function which can be
5 5
   used to get a list of file-status/file-name pairs that were changed
6
-  in the last git push.
6
+  in the last git push. There is also an exported `find-content-by-path`
7
+  function to retrieve content objects from the above file-name.
7 8
 
8 9
 ## Changes for 0.9.4 (2014-05-05):
9 10
 

+ 5 - 5
docs/plugin-api.md

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

+ 15 - 36
plugins/twitter.lisp

@@ -22,8 +22,8 @@
22 22
 coleslaw:post and returns the tweet content.")
23 23
 
24 24
 (defvar *tweet-format-dsl-mapping*
25
-  '((:title . title-of)
26
-    (:author . author-of)))
25
+  '((:title  title-of)
26
+    (:author author-of)))
27 27
 
28 28
 (define-condition malformed-tweet-format (error)
29 29
   ((item :initarg :item :reader item))
@@ -33,38 +33,17 @@ coleslaw:post and returns the tweet content.")
33 33
              (item condition)))))
34 34
 
35 35
 (defun compile-tweet-format (tweet-format)
36
-  (multiple-value-bind
37
-        (fmt-ctrl-str accesors) (%compile-tweet-format tweet-format nil nil)
38
-    (let
39
-        ((fmt-ctrl-str (format nil "~{~A~^ ~}" (reverse fmt-ctrl-str)))
40
-         (accesors (reverse accesors)))
41
-      (lambda (post)
42
-        (apply #'format nil fmt-ctrl-str
43
-               (loop
44
-                  :for accesor :in accesors
45
-                  :collect (funcall accesor post)))))))
46
-
47
-(defun %compile-tweet-format (tweet-format fmt-ctrl-str accesors)
48
-  "Transform tweet-format into a format control string and a list of values."
49
-  (if (null tweet-format)
50
-      (values fmt-ctrl-str accesors)
51
-      (let ((next (car tweet-format)))
52
-        (cond
53
-          ((keywordp next)
54
-           (if (assoc next *tweet-format-dsl-mapping*)
55
-               (%compile-tweet-format
56
-                (cdr tweet-format)
57
-                (cons "~A" fmt-ctrl-str)
58
-                (cons (cdr (assoc next *tweet-format-dsl-mapping*))
59
-                      accesors))
60
-               (error 'malformed-tweet-format :item next)))
61
-          ((stringp next)
62
-           (%compile-tweet-format (cdr tweet-format)
63
-                                  (cons next fmt-ctrl-str)
64
-                                  accesors))
65
-          (t (error 'malformed-tweet-format :item next))))))
66
-
67
-(setf *tweet-format-fn* (compile-tweet-format *tweet-format*))
36
+  (flet ((accessor-for (x)
37
+           (rest (assoc x *tweet-format-dsl-mapping*))))
38
+    (lambda (post)
39
+      (apply #'format nil "~{~A~^ ~}"
40
+             (loop for item in *tweet-format*
41
+                unless (or (keywordp item) (stringp item))
42
+                  (error 'malformed-tweet-format :item item)
43
+                when (keywordp item)
44
+                  collect (funcall (accessor-for item) post)
45
+                when (stringp item)
46
+                  collect item)))))
68 47
 
69 48
 (defun enable (&key api-key api-secret access-token access-secret tweet-format)
70 49
   (if (and api-key api-secret access-token access-secret)
@@ -78,8 +57,8 @@ coleslaw:post and returns the tweet content.")
78 57
   ;; fallback to chirp for credential erros
79 58
   (chirp:account/verify-credentials)
80 59
   (when tweet-format
81
-    (setf *tweet-format* tweet-format)))
82
-
60
+    (setf *tweet-format* tweet-format))
61
+  (setf *tweet-format-fn* (compile-tweet-format *tweet-format*)))
83 62
 
84 63
 (defmethod deploy :after (staging)
85 64
   (declare (ignore staging))