Browse code
splitting whitespace and cl-oid-connect
fiddlerwoaroof authored on 05/11/2015 05:37:36
Showing 5 changed files
Showing 5 changed files
... | ... |
@@ -2,7 +2,6 @@ |
2 | 2 |
(ql:quickload :clack-middleware-postmodern) |
3 | 3 |
|
4 | 4 |
(ql:quickload :cl-markup) |
5 |
-(ql:quickload :cl-oid-connect) |
|
6 | 5 |
(ql:quickload :colors) |
7 | 6 |
(ql:quickload :lquery) |
8 | 7 |
(ql:quickload :plump) |
... | ... |
@@ -16,6 +15,8 @@ |
16 | 15 |
(ql:quickload :jonathan) |
17 | 16 |
(ql:quickload :cl-actors) |
18 | 17 |
(ql:quickload :simple-tasks) |
18 |
+(ql:quickload :cl-oid-connect) |
|
19 |
+(ql:quickload :fwoar.lisputils) |
|
19 | 20 |
|
20 | 21 |
(declaim (optimize (speed 0) (safety 3) (debug 2))) |
21 | 22 |
|
... | ... |
@@ -24,11 +25,9 @@ |
24 | 25 |
(push (cons "text" "rss+xml") drakma:*text-content-types*) |
25 | 26 |
|
26 | 27 |
;(load "utils.lisp") |
28 |
+(load "package.lisp") |
|
27 | 29 |
(load "rss.lisp") |
28 | 30 |
|
29 |
-(defpackage :whitespace |
|
30 |
- (:use #:cl #:anaphora #:whitespace.utils #:whitespace.feeds.rss #:whitespace.tables)) |
|
31 |
- |
|
32 | 31 |
(in-package plump-dom) |
33 | 32 |
|
34 | 33 |
(defmethod serialize-object :around ((node element)) |
... | ... |
@@ -1,32 +1,29 @@ |
1 | 1 |
;;;; package.lisp |
2 |
+(in-package :cl-user) |
|
3 |
+ |
|
4 |
+(defpackage :whitespace.tables |
|
5 |
+ (:use #:cl #:alexandria #:postmodern #:annot.class #:iterate #:fwoar.lisputils)) |
|
6 |
+ |
|
7 |
+(defpackage :whitespace.feeds.autodiscovery |
|
8 |
+ (:use #:cl #:alexandria #:postmodern #:lquery #:cl-syntax #:cl-annot.syntax #:cl-annot.class |
|
9 |
+ #:whitespace.tables #:iterate #:fwoar.lisputils) |
|
10 |
+ (:import-from anaphora it) |
|
11 |
+ (:export :discover-feeds)) |
|
12 |
+ |
|
13 |
+(defpackage :whitespace.feeds.opml |
|
14 |
+ (:use #:cl #:alexandria #:postmodern #:lquery #:cl-syntax #:cl-annot.syntax #:cl-annot.class |
|
15 |
+ #:whitespace.tables #:iterate #:fwoar.lisputils) |
|
16 |
+ (:import-from anaphora it)) |
|
17 |
+ |
|
18 |
+(defpackage :whitespace.feeds.rss |
|
19 |
+ (:use #:cl #:alexandria #:postmodern #:lquery #:cl-syntax #:cl-annot.syntax #:cl-annot.class |
|
20 |
+ #:whitespace.tables #:iterate #:fwoar.lisputils #:whitespace.feeds.autodiscovery) |
|
21 |
+ (:import-from anaphora it) |
|
22 |
+ (:export :get-elements :get-elements-by-tagname :extract-text :xml-text-bind :upsert-feed :deserialize |
|
23 |
+ :deserialize-feed :deserialize-items :deserialize-item :subscribe-to-feed :store-feed |
|
24 |
+ :make-rss-feed :make-rss-item)) |
|
25 |
+ |
|
26 |
+(defpackage :whitespace |
|
27 |
+ (:use #:cl #:anaphora #:fwoar.lisputils #:whitespace.feeds.rss #:whitespace.tables)) |
|
2 | 28 |
|
3 |
-(defpackage :cl-oid-connect |
|
4 |
- (:use |
|
5 |
- #:cl |
|
6 |
- #:alexandria |
|
7 |
- #:anaphora |
|
8 |
- #:clack |
|
9 |
- #:cl-json |
|
10 |
- #:cljwt |
|
11 |
- #:cl-who |
|
12 |
- #:drakma |
|
13 |
- ;#:lack-middleware-session |
|
14 |
- #:iterate |
|
15 |
- #:ningle |
|
16 |
- #:lquery |
|
17 |
- #:plump |
|
18 |
- #:sheeple |
|
19 |
- #:whitespace.utils |
|
20 |
- ) |
|
21 |
- (:export |
|
22 |
- #:redirect-if-necessary |
|
23 |
- #:def-route |
|
24 |
- #:require-login |
|
25 |
- #:oauth2-login-middleware |
|
26 |
- #:with-session |
|
27 |
- #:assoc-cdr |
|
28 |
- #:session ; private!! |
|
29 |
- #:vars-to-symbol-macrolets |
|
30 |
- #:initialize-oid-connect |
|
31 |
- )) |
|
32 | 29 |
|
... | ... |
@@ -1,6 +1,12 @@ |
1 |
+(declaim (optimize (safety 3) (speed 0) (debug 3))) |
|
2 |
+ |
|
3 |
+(load "tables.lisp") |
|
4 |
+ |
|
1 | 5 |
(in-package :cl-user) |
6 |
+(cl-annot.syntax:enable-annot-syntax) |
|
7 |
+ |
|
8 |
+ |
|
2 | 9 |
(use-package :lquery) |
3 |
-(declaim (optimize (safety 3) (speed 0) (debug 3))) |
|
4 | 10 |
|
5 | 11 |
(define-lquery-list-function where-attr (els attr &key is) |
6 | 12 |
(remove-if-not (lambda (y) (string= (plump:attribute y attr) is)) |
... | ... |
@@ -18,12 +24,6 @@ |
18 | 24 |
|
19 | 25 |
|
20 | 26 |
|
21 |
-(load "tables.lisp") |
|
22 |
- |
|
23 |
-(defpackage :whitespace.feeds.autodiscovery |
|
24 |
- (:use #:cl #:alexandria #:postmodern #:lquery #:cl-syntax #:cl-annot.syntax #:cl-annot.class |
|
25 |
- #:whitespace.tables #:iterate #:whitespace.utils) |
|
26 |
- (:import-from anaphora it)) |
|
27 | 27 |
(in-package #:whitespace.feeds.autodiscovery) |
28 | 28 |
|
29 | 29 |
(defun discover-feeds (doc) |
... | ... |
@@ -31,32 +31,16 @@ |
31 | 31 |
Returns a vector " |
32 | 32 |
(coerce |
33 | 33 |
(lquery:$ (inline doc) |
34 |
- "link" |
|
35 |
- (where-attr "rel" :is "alternate") |
|
36 |
- (combine (attr "href") |
|
37 |
- (attr "type"))) |
|
34 |
+ "link" |
|
35 |
+ (where-attr "rel" :is "alternate") |
|
36 |
+ (combine (attr "href") |
|
37 |
+ (attr "type"))) |
|
38 | 38 |
'list)) |
39 |
-(export 'discover-feeds) |
|
40 | 39 |
|
41 |
-(defpackage :whitespace.feeds.opml |
|
42 |
- (:use #:cl #:alexandria #:postmodern #:lquery #:cl-syntax #:cl-annot.syntax #:cl-annot.class |
|
43 |
- #:whitespace.tables #:iterate #:whitespace.utils) |
|
44 |
- (:import-from anaphora it)) |
|
45 | 40 |
(in-package #:whitespace.feeds.opml) |
46 | 41 |
|
42 |
+(in-package #:whitespace.feeds.rss) |
|
47 | 43 |
|
48 |
- |
|
49 |
-(in-package :cl-user) |
|
50 |
-(defpackage :whitespace.feeds.rss |
|
51 |
- (:use #:cl #:alexandria #:postmodern #:lquery #:cl-syntax #:cl-annot.syntax #:cl-annot.class |
|
52 |
- #:whitespace.tables #:iterate #:whitespace.utils #:whitespace.feeds.autodiscovery) |
|
53 |
- (:import-from anaphora it)) |
|
54 |
- |
|
55 |
- |
|
56 |
-(in-package :whitespace.feeds.rss) |
|
57 |
-(cl-annot.syntax:enable-annot-syntax) |
|
58 |
- |
|
59 |
-@export |
|
60 | 44 |
(defmacro get-elements (feed &optional (filter nil)) |
61 | 45 |
(let ((feed-sym (gensym)) |
62 | 46 |
(filter-lis `(lambda (x) (and (plump-dom:element-p x) ,@(loop for x in filter |
... | ... |
@@ -64,15 +48,12 @@ |
64 | 48 |
`(let ((,feed-sym ,feed)) |
65 | 49 |
(remove-if-not ,filter-lis (plump:children ,feed-sym))))) |
66 | 50 |
|
67 |
-@export |
|
68 | 51 |
(defmacro get-elements-by-tagname (feed tagname) |
69 | 52 |
`(get-elements ,feed ((lambda (x) (string= ,tagname (plump:tag-name x)))))) |
70 | 53 |
|
71 |
-@export |
|
72 | 54 |
(defmacro extract-text (selector &optional (default "")) |
73 | 55 |
`(or (lquery:$ ,selector (text) (node)) ,default)) |
74 | 56 |
|
75 |
-@export |
|
76 | 57 |
(defmacro xml-text-bind (syms &body body) |
77 | 58 |
"Bind the symbols passed in the second arg to the text of the matching |
78 | 59 |
elements in the document lquery has been initialized with and then run the |
... | ... |
@@ -101,7 +82,6 @@ |
101 | 82 |
((item :accessor rss-item-item :initarg :item) |
102 | 83 |
(title :accessor rss-item-title :initarg :title) |
103 | 84 |
(link :accessor rss-item-link :initarg :link) |
104 |
- (description-raw :accessor rss-item-description-raw :initarg :description-raw) |
|
105 | 85 |
(description :accessor rss-item-description :initarg :description) |
106 | 86 |
(category :accessor rss-item-category :initarg :category) |
107 | 87 |
(comments :accessor rss-item-comments :initarg :comments) |
... | ... |
@@ -110,7 +90,6 @@ |
110 | 90 |
(pub-date :accessor rss-item-pub-date :initarg :pub-date) |
111 | 91 |
(source :accessor rss-item-source :initarg :source))) |
112 | 92 |
|
113 |
-@export |
|
114 | 93 |
(defun make-rss-item (item fallback-date) |
115 | 94 |
(lquery:initialize item) |
116 | 95 |
(flet ((dehtml (h) (plump:text (plump:parse h))) |
... | ... |
@@ -125,24 +104,22 @@ |
125 | 104 |
(description-element (default-when content-encoded (emptyp content-encoded) |
126 | 105 |
(lquery:$ (children "description")))) |
127 | 106 |
|
128 |
- (description-raw (normalize-html |
|
129 |
- (default-when description-element (emptyp description-element) |
|
130 |
- (extract-text "description"))))) |
|
131 |
- ;(enclosure) --- TODO: implement comment / enclosure handling |
|
107 |
+ (description (normalize-html |
|
108 |
+ (default-when description-element (emptyp description-element) |
|
109 |
+ (extract-text "description"))))) |
|
110 |
+ ;(enclosure) --- TODO: implement comment / enclosure handling |
|
132 | 111 |
|
133 | 112 |
(xml-text-bind (title link guid pubdate source comments) |
134 | 113 |
(when (string= pubdate "") |
135 | 114 |
(setf pubdate fallback-date)) |
136 | 115 |
(make-instance-from-symbols 'rss-item |
137 | 116 |
item title link |
138 |
- description-raw |
|
139 |
- (description (dehtml description-raw)) |
|
117 |
+ description |
|
140 | 118 |
(category (get-category-names (lquery:$ "category"))) |
141 | 119 |
guid (pub-date pubdate) source comments))))) |
142 |
- ;(setf (rss-item-enclosure result) enclosure) -- TODO: comment/enclosure . . . |
|
120 |
+;(setf (rss-item-enclosure result) enclosure) -- TODO: comment/enclosure . . . |
|
143 | 121 |
|
144 | 122 |
|
145 |
-@export |
|
146 | 123 |
(defun make-rss-feed (feed) |
147 | 124 |
(lquery:initialize feed) |
148 | 125 |
(let* ((channel (lquery:$ "channel" (node))) |
... | ... |
@@ -156,10 +133,10 @@ |
156 | 133 |
(fallback-date (if (string= pub-date "") "2015-01-01 0:0:0+00" pub-date))) |
157 | 134 |
(format t "fallback-date: ~a~%" fallback-date) |
158 | 135 |
(xml-text-bind (title description) |
159 |
- (make-instance-from-symbols 'rss-feed |
|
160 |
- feed title link description channel fetch-url |
|
161 |
- (items (iterate (for it in-sequence items) |
|
162 |
- (collecting (make-rss-item it fallback-date)))))))) |
|
136 |
+ (make-instance-from-symbols 'rss-feed |
|
137 |
+ feed title link description channel fetch-url |
|
138 |
+ (items (iterate (for it in-sequence items) |
|
139 |
+ (collecting (make-rss-item it fallback-date)))))))) |
|
163 | 140 |
|
164 | 141 |
; These are the interface I'm planning to remove as duplicate |
165 | 142 |
(defserializer (rss-feed) |
... | ... |
@@ -168,7 +145,7 @@ |
168 | 145 |
(collect item)))) |
169 | 146 |
|
170 | 147 |
(defserializer (rss-item) |
171 |
- title link (description description-raw :bind-from description-raw) guid pub-date source) |
|
148 |
+ title link (description :bind-from description) guid pub-date source) |
|
172 | 149 |
|
173 | 150 |
(defmethod jonathan:%to-json ((obj rss-feed)) |
174 | 151 |
(jonathan:%to-json (serialize obj #'alexandria:alist-hash-table #'%json-pair-transform))) |
... | ... |
@@ -186,19 +163,19 @@ |
186 | 163 |
; NOTE: this won't make dao objects for the _items_ when called on the feed! |
187 | 164 |
; also NOTE: this _prefers_ the passed object |
188 | 165 |
(defmethod get-dao-for ((obj rss-feed) &optional linked-objects) |
189 |
- (declare (ignore linked-objects)) |
|
190 |
- (with-slots (title link description fetch-url) obj |
|
191 |
- (get-id-for-object (rss_feed_store link) link |
|
192 |
- (make-instance-from-symbols 'rss_feed_store id title link description fetch-url (fetch-defaults t))) )) |
|
166 |
+ (declare (ignore linked-objects)) |
|
167 |
+ (with-slots (title link description fetch-url) obj |
|
168 |
+ (get-id-for-object (rss_feed_store link) link |
|
169 |
+ (make-instance-from-symbols 'rss_feed_store id title link description fetch-url (fetch-defaults t))) )) |
|
193 | 170 |
|
194 | 171 |
(defmethod get-dao-for ((obj rss-item) &optional feed) |
195 |
- (with-slots (title link description-raw guid pub-date source) obj |
|
196 |
- (get-id-for-object (rss_item_store guid) guid |
|
197 |
- (let ((result (make-instance-from-symbols 'rss_item_store title link (description description-raw) |
|
198 |
- guid pub-date source feed (fetch-defaults t)))) |
|
199 |
- (unless (null id) |
|
200 |
- (setf (ris-id result) id)) |
|
201 |
- result)))) |
|
172 |
+ (with-slots (title link description guid pub-date source) obj |
|
173 |
+ (get-id-for-object (rss_item_store guid) guid |
|
174 |
+ (let ((result (make-instance-from-symbols 'rss_item_store title link description |
|
175 |
+ guid pub-date source feed (fetch-defaults t)))) |
|
176 |
+ (unless (null id) |
|
177 |
+ (setf (ris-id result) id)) |
|
178 |
+ result)))) |
|
202 | 179 |
|
203 | 180 |
(defun get-and-possibly-store-feed (rss-feed) |
204 | 181 |
"Given an rss-feed, return the db's feed-id, persisting it if it doesn't already exist." |
... | ... |
@@ -207,14 +184,13 @@ |
207 | 184 |
(car anaphora:it) ;; The postmodern query returns a nested list |
208 | 185 |
(store-feed-dao (serialize rss-feed))))) |
209 | 186 |
|
210 |
-@export |
|
211 | 187 |
(defun store-feed (doc) |
212 | 188 |
(postmodern:with-transaction () |
213 | 189 |
(let ((rss-feed (make-rss-feed doc))) |
214 | 190 |
(values rss-feed |
215 | 191 |
(get-and-possibly-store-feed rss-feed))))) |
216 | 192 |
|
217 |
-@export ; TODO: this should eventually take a username/userobject rather than ids . . . |
|
193 |
+; TODO: this should eventually take a username/userobject rather than ids . . . |
|
218 | 194 |
(defun subscribe-to-feed (uid feedid) |
219 | 195 |
(postmodern:query |
220 | 196 |
(:insert-into 'subscriptions :set 'uid uid 'feedid feedid))) |
... | ... |
@@ -222,19 +198,17 @@ |
222 | 198 |
#| |
223 | 199 |
(:documentation |
224 | 200 |
"Store a serialized rss object into rhe database: the basic idea here is |
225 |
- that the quasi-quoted expression generates a form that would insert the |
|
226 |
- item and then we eval it.") |
|
201 |
+ that the quasi-quoted expression generates a form that would insert the |
|
202 |
+ item and then we eval it.") |
|
227 | 203 |
|# |
228 | 204 |
|
229 |
-@export |
|
230 | 205 |
(defun deserialize-item (item) |
231 | 206 |
(let ((result (make-instance 'rss-item))) |
232 |
- (copy-slots (title link (description description-raw) comments enclosure guid pub-date source) |
|
207 |
+ (copy-slots (title link description comments enclosure guid pub-date source) |
|
233 | 208 |
item |
234 | 209 |
result) |
235 | 210 |
result)) |
236 | 211 |
|
237 |
-@export |
|
238 | 212 |
(defun deserialize-items (feed-id) |
239 | 213 |
(let ((items (postmodern:query-dao 'rss_item_store |
240 | 214 |
(:order-by |
... | ... |
@@ -243,14 +217,12 @@ |
243 | 217 |
(:desc 'pub-date))))) |
244 | 218 |
(loop for item in items collect (deserialize-item item)))) |
245 | 219 |
|
246 |
-@export |
|
247 | 220 |
(defun deserialize-feed (feed) |
248 | 221 |
(let ((result (make-instance 'rss-feed))) |
249 | 222 |
(copy-slots (title link description fetch-url) feed result) |
250 | 223 |
(setf (rss-feed-items result) (deserialize-items (rfs-id feed))) |
251 | 224 |
result)) |
252 | 225 |
|
253 |
-@export |
|
254 | 226 |
(defun deserialize (&optional user-info) |
255 | 227 |
(default-when #() (not (null user-info)) |
256 | 228 |
(let ((feeds |
... | ... |
@@ -271,7 +243,6 @@ |
271 | 243 |
(collect (get-dao-for item (slot-value feed-dao 'id))))))))) |
272 | 244 |
|
273 | 245 |
|
274 |
-@export |
|
275 | 246 |
(defun upsert-feed (rss-feed) |
276 | 247 |
(postmodern:ensure-transaction |
277 | 248 |
(destructuring-bind (feed items) (get-feed-from-dao rss-feed) |