|
@@ -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))
|