Browse code
Switched to araneus + cleanup web frameworky stuff
fiddlerwoaroof authored on 22/05/2016 07:55:54
Showing 1 changed files
Showing 1 changed files
... | ... |
@@ -1,6 +1,8 @@ |
1 | 1 |
(in-package :cl-user) |
2 | 2 |
(ql:quickload :clack-middleware-postmodern) |
3 | 3 |
|
4 |
+(ql:quickload :fwoar.lisputils) |
|
5 |
+(ql:quickload :araneus) |
|
4 | 6 |
(ql:quickload :cl-markup) |
5 | 7 |
(ql:quickload :colors) |
6 | 8 |
(ql:quickload :lquery) |
... | ... |
@@ -37,23 +39,13 @@ |
37 | 39 |
|
38 | 40 |
|
39 | 41 |
(in-package :whitespace) |
42 |
+(use-package :fwoar.lisputils) |
|
43 |
+(use-package :araneus) |
|
40 | 44 |
(ubiquitous:restore :whitespace) |
41 | 45 |
|
42 | 46 |
|
43 | 47 |
(defparameter *app* (make-instance 'ningle:<app>)) |
44 | 48 |
|
45 |
-(cl-oid-connect:def-route ("/login" (params) :app *app*) |
|
46 |
- (cl-who:with-html-output-to-string (s) |
|
47 |
- (:html |
|
48 |
- (:head (:title "Login")) |
|
49 |
- (:body |
|
50 |
- (:div |
|
51 |
- :class "login-button facebook" |
|
52 |
- (:a :href "/login/facebook" "Facebook")) |
|
53 |
- (:div |
|
54 |
- :class "login-button google" |
|
55 |
- (:a :href "/login/google" "Google")))))) |
|
56 |
- |
|
57 | 49 |
|
58 | 50 |
(handler-bind ((warning #'sb-ext::muffle-warning)) |
59 | 51 |
(let* ((feed-urls (ubiquitous:value 'feed 'urls)) |
... | ... |
@@ -61,11 +53,14 @@ |
61 | 53 |
(docs (map 'vector (lambda (x) (plump:parse (drakma:http-request x))) feed-urls))) |
62 | 54 |
(defparameter *feeds* (map 'vector (lambda (x) (make-rss-feed x)) docs)))) |
63 | 55 |
|
64 |
-(defparameter *db-connection-info* (ubiquitous:value 'db 'connection 'info)) |
|
56 |
+(defparameter *db-connection-info* (ubiquitous:value 'db)) |
|
57 |
+ |
|
65 | 58 |
(defmacro with-whitespace-db (&body body) |
66 | 59 |
`(postmodern:with-connection *db-connection-info* |
67 | 60 |
,@body)) |
61 |
+ |
|
68 | 62 |
(defmacro wc (&body body) |
63 |
+ "Utility function for the REPL" |
|
69 | 64 |
`(with-whitespace-db ,@body)) |
70 | 65 |
|
71 | 66 |
(defmacro with-xml-tags (&body body) |
... | ... |
@@ -136,10 +131,6 @@ |
136 | 131 |
(list :|success| success |
137 | 132 |
:|result| result))) |
138 | 133 |
|
139 |
-(defmacro neither (&rest forms) `(not (or ,@forms))) |
|
140 |
-(defmacro neither-null (&rest forms) |
|
141 |
- `(neither ,@(loop for form in forms collecting `(null ,form)))) |
|
142 |
- |
|
143 | 134 |
; ; ; Ultimately, this will only serialize the feed if the client |
144 | 135 |
(cl-oid-connect:def-route ("/feeds/add" (params) :method :post :app *app*) |
145 | 136 |
(ningle.context:with-context-variables (session) |
... | ... |
@@ -161,7 +152,7 @@ |
161 | 152 |
() |
162 | 153 |
(when api |
163 | 154 |
(setf result |
164 |
- `(400 () ,(jsonapi-encoder nil "Feed already saved")))))))) |
|
155 |
+ `(400 () ',(jsonapi-encoder nil "Feed already saved")))))))) |
|
165 | 156 |
result))) |
166 | 157 |
|
167 | 158 |
;;; TODO: add needs to return the new content, so that angular can append it |
... | ... |
@@ -173,7 +164,7 @@ |
173 | 164 |
(*feeds* (if user-info (deserialize user-info) *feeds*))) |
174 | 165 |
(setf *userasdfs* user-info) |
175 | 166 |
`(200 (:content-type "application/json" :cache-control "private, max-age=300") |
176 |
- ,(jsonapi-encoder t *feeds*))))) |
|
167 |
+ (,(jsonapi-encoder t *feeds*)))))) |
|
177 | 168 |
|
178 | 169 |
(cl-oid-connect:def-route ("/feeds/:feeds/html" (params) :app *app*) |
179 | 170 |
(ningle.context:with-context-variables (session) |
... | ... |
@@ -194,14 +185,6 @@ |
194 | 185 |
#|(cl-oid-connect:require-login |
195 | 186 |
))|# |
196 | 187 |
|
197 |
-(cl-oid-connect:def-route ("/" (params) :app *app*) |
|
198 |
- (ningle:with-context-variables (session) |
|
199 |
- (cl-oid-connect.utils:require-login |
|
200 |
- (cl-oid-connect:redirect-if-necessary session |
|
201 |
- (let* ((user-info (gethash :app-user session)) |
|
202 |
- (*feeds* (deserialize user-info))) |
|
203 |
- (base-template-f)))))) |
|
204 |
- |
|
205 | 188 |
;;; this will be bound by calls to with-palette |
206 | 189 |
;;; probably should be refactored out |
207 | 190 |
(defparameter *palette* nil) |
... | ... |
@@ -291,28 +274,80 @@ |
291 | 274 |
`((:or (:and .link-header :hover) (.link.closed (:and .link-header :hover))) |
292 | 275 |
:background-color ,(colors:colorscheme-hover-highlight *colorscheme*))))) |
293 | 276 |
(declare (ignorable main-right-margin)) ; TODO: use this!!! |
294 |
- `(200 (:content-type "text/css") ,ss))))) |
|
277 |
+ `(200 (:content-type "text/css") (,ss)))))) |
|
295 | 278 |
|
296 |
-(cl-oid-connect:def-route ("/theme/dark.css" (params) :app *app*) |
|
279 |
+(define-view dark-css (params) |
|
297 | 280 |
(colors:let-palette (make-instance 'colors:palette) |
298 | 281 |
(eval '(get-theme-css)))) |
299 | 282 |
|
300 |
-(cl-oid-connect:def-route ("/theme/light.css" (params) :app *app*) |
|
283 |
+(define-view light-css (params) |
|
301 | 284 |
(colors:let-palette (colors:invert-palette (make-instance 'colors:palette)) |
302 | 285 |
(eval '(get-theme-css)))) |
303 | 286 |
|
304 |
-(cl-oid-connect:def-route ("/userinfo.json" (params) :app *app*) |
|
287 |
+(define-view css (colorscheme) |
|
288 |
+ (string-case:string-case (colorscheme :default "") |
|
289 |
+ ("light" (view 'light-css colorscheme)) |
|
290 |
+ ("dark" (view 'dark-css colorscheme)))) |
|
291 |
+ |
|
292 |
+(define-view userinfo (params) |
|
305 | 293 |
(declare (ignore params)) |
306 | 294 |
(ningle:with-context-variables (session) |
307 | 295 |
(cl-oid-connect:require-login |
308 | 296 |
(cl-oid-connect::with-endpoints (gethash :endpoint-schema session) |
309 |
- `(200 (:content-type "application/json") ,(cl-json:encode-json-to-string (gethash :userinfo session))))))) |
|
297 |
+ `(200 |
|
298 |
+ (:content-type "application/json") |
|
299 |
+ (,(cl-json:encode-json-to-string |
|
300 |
+ (gethash :userinfo session)))))))) |
|
301 |
+ |
|
302 |
+(define-controller css (params) |
|
303 |
+ (cl-oid-connect.utils:assoc-cdr :scheme params)) |
|
304 |
+ |
|
305 |
+(define-controller id (params) |
|
306 |
+ params) |
|
307 |
+ |
|
308 |
+(define-view redirect (destination) |
|
309 |
+ `(302 (:location ,destination))) |
|
310 |
+ |
|
311 |
+(define-view login (params) |
|
312 |
+ (cl-who:with-html-output-to-string (s) |
|
313 |
+ (:html |
|
314 |
+ (:head (:title "Login")) |
|
315 |
+ (:body |
|
316 |
+ (:div |
|
317 |
+ :class "login-button facebook" |
|
318 |
+ (:a :href "/login/facebook" "Facebook")) |
|
319 |
+ (:div |
|
320 |
+ :class "login-button google" |
|
321 |
+ (:a :href "/login/google" "Google")))))) |
|
310 | 322 |
|
311 |
-(cl-oid-connect:def-route ("/logout" (params) :app *app*) |
|
323 |
+(define-controller logout (params) |
|
312 | 324 |
(declare (ignore params)) |
313 | 325 |
(ningle:with-context-variables (session) |
314 | 326 |
(setf (gethash :userinfo session) nil) |
315 |
- '(302 (:location "/")))) |
|
327 |
+ "/")) |
|
328 |
+ |
|
329 |
+(define-view root (feeds) |
|
330 |
+ (let ((*feeds* feeds)) |
|
331 |
+ (base-template-f))) |
|
332 |
+ |
|
333 |
+(define-controller root (params) |
|
334 |
+ (cl-oid-connect.utils::with-login |
|
335 |
+ (ningle:with-context-variables (session) |
|
336 |
+ (cl-oid-connect:redirect-if-necessary session |
|
337 |
+ (let* ((user-info (gethash :app-user session))) |
|
338 |
+ (deserialize user-info)))) |
|
339 |
+ (:unauthorized (c) |
|
340 |
+ (declare (ignore c)) |
|
341 |
+ (format t "hmm...") |
|
342 |
+ (araneus::switch-view 'redirect) |
|
343 |
+ "/login"))) |
|
344 |
+ |
|
345 |
+(defroutes *app* |
|
346 |
+ (("/theme/:scheme.css") (araneus::compose-route (css) css)) |
|
347 |
+ (("/userinfo.json") (araneus::compose-route (id) userinfo)) |
|
348 |
+ (("/login") (araneus::compose-route (id) login)) |
|
349 |
+ (("/logout") (araneus::compose-route (logout) redirect)) |
|
350 |
+ (("/") (araneus:as-route 'root))) |
|
316 | 351 |
|
317 | 352 |
(defun assoc-cdr-alternatives (alist alt1 alt2 &optional (test #'eql)) |
318 | 353 |
(aif (cl-oid-connect:assoc-cdr alt1 alist test) |
... | ... |
@@ -322,7 +357,7 @@ |
322 | 357 |
(cl-oid-connect::setup-oid-connect *app* (userinfo &rest args) |
323 | 358 |
(declare (ignore args) (optimize (speed 0) (safety 3) (debug 3))) |
324 | 359 |
(flet ((get-received-id (userinfo) (assoc-cdr-alternatives userinfo :id :sub)) |
325 |
- (get-db-user (received-id) (car (postmodern:select-dao 'reader_user (:= :foreign-id received-id)))) |
|
360 |
+ (get-db-user (received-id) (car (postmodern:select-dao 'reader_user (:= :foreign-id received-id)))) |
|
326 | 361 |
(get-first-name (userinfo) (assoc-cdr-alternatives userinfo :first--name :given--name)) |
327 | 362 |
(get-last-name (userinfo) (assoc-cdr-alternatives userinfo :last--name :family--name)) |
328 | 363 |
(get-link (userinfo) (assoc-cdr-alternatives userinfo :link :profile))) |