git.fiddlerwoaroof.com
Browse code

updating demo apps

fiddlerwoaroof authored on 19/07/2016 08:49:41
Showing 2 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,88 @@
1
+(defpackage :alimenta-clim
2
+  (:use :clim-lisp :alexandria :serapeum :fw.lu))
3
+
4
+(in-package :alimenta-clim)
5
+
6
+(defclass feed-view (clim:view) ())
7
+(defclass item-view (clim:view) ((%item :initarg :item :accessor item)))
8
+
9
+(defparameter *feed-view* (make-instance 'feed-view))
10
+
11
+(clim:define-application-frame alimenta ()
12
+  ()
13
+  (:pointer-documentation t)
14
+  (:panes
15
+    (app :application
16
+         :height 500
17
+         :width  500
18
+         :display-function #'display-app
19
+         :default-view *feed-view*)
20
+    (int :interactor
21
+         :height 500
22
+         :width 500))
23
+  (:layouts
24
+    (default (clim:vertically () app int))  
25
+    (flopped (clim:horizontally () app int))))
26
+
27
+(defparameter *articles*
28
+  (let ((errors 0))
29
+    (handler-bind ((simple-error (lambda (c) c
30
+                                   (incf errors)
31
+                                   (when (< errors 1000)
32
+                                     (invoke-restart 'alimenta.rss::pop-token)))))
33
+      (alimenta.pull-feed:pull-feed "http://planet.lisp.org/rss20.xml" :type :rss))))
34
+
35
+(defgeneric display-pane-with-view (frame pane view))
36
+
37
+(defun display-app (frame pane)
38
+  (display-pane-with-view frame pane (clim:stream-default-view pane)))
39
+
40
+(defmethod display-pane-with-view (frame pane (view feed-view))
41
+  (clim:with-text-style (pane (clim:make-text-style :serif :bold :larger))
42
+    (format pane "~a <~a>~%"
43
+            (alimenta::title *articles*)
44
+            (alimenta::link *articles*)))
45
+  (dolist (item (alimenta::items *articles*))
46
+    (clim:with-output-as-presentation (pane item 'alimenta:item)
47
+      (format pane "~a~%" (alimenta::title item)))))
48
+
49
+(defmethod display-pane-with-view (frame pane (view item-view))
50
+  (let ((item (item view)))
51
+    (with-accessors ((title alimenta::title)) item
52
+      (clim:with-output-as-presentation (pane item 'alimenta:item)
53
+        (clim:with-text-style (pane (clim:make-text-style :serif :bold :larger))
54
+          (format pane "~a <~a>~%"
55
+                  (alimenta::title item)
56
+                  (alimenta::link item)))))
57
+    (let ((text (funcall (compose #'plump:text #'plump:parse)
58
+                         (alimenta::content item))))
59
+      (format pane "~&~{~{~a~^ ~}~^~%~}~2&"
60
+              (remove-if #'null
61
+                         (mapcar #'tokens
62
+                                 (split-sequence #\newline
63
+                                                 text)))))))
64
+
65
+(define-alimenta-command (com-inspect :name t) ()
66
+  (clouseau:inspector
67
+    *articles*))
68
+
69
+(define-alimenta-command (com-quite :name t) ()
70
+  (clim:frame-exit clim:*application-frame*))
71
+
72
+(define-alimenta-command (to-feed :name t) ()
73
+  (let ((pane (clim:find-pane-named clim:*application-frame* 'app)))
74
+    (setf (clim:stream-default-view pane) *feed-view*)))
75
+
76
+(define-alimenta-command (com-pick-item :name t) ((item 'alimenta:item))
77
+  (let ((pane (clim:find-pane-named clim:*application-frame* 'app)))
78
+    (setf (clim:stream-default-view pane) (make-instance 'item-view :item item))))
79
+
80
+(define-alimenta-command (flop-layout :name t) ()
81
+  (let ((old-view (clim:frame-current-layout clim:*application-frame*)))
82
+    (setf (clim:frame-current-layout clim:*application-frame*)
83
+          (case old-view
84
+            ('default  'flopped)
85
+            (t 'default)))))
86
+
87
+(clim:run-frame-top-level
88
+  (clim:make-application-frame 'alimenta-clim::alimenta))
... ...
@@ -1,3 +1,4 @@
1
+(in-package :cl-user)
1 2
 (ql:quickload :clack)
2 3
 (ql:quickload :ningle )
3 4
 (ql:quickload :araneus)
... ...
@@ -23,22 +24,39 @@
23 24
        :padding "1em")
24 25
 
25 26
     `(div.articles
26
-       :display "flex"
27
+       :display "block"
27 28
        :flex-flow "row"
28 29
        :flex-wrap "wrap-reverse"
29 30
        :align-items "baseline"
30 31
        :justify-content "space-around"
31 32
        :align-content "space-between"
33
+
32 34
        )
33 35
 
34 36
     `(article
35 37
        :padding "1em"
36 38
        :border "4px double #888"
37 39
        :vertical-align "middle"
38
-       :width "30%"
40
+       :width "100%"
39 41
        :overflow "hidden"
40 42
        :min-height "4em"
41 43
        :background "#aaa"
44
+
45
+       (div.title
46
+         :float "left"
47
+         :width "50%")
48
+
49
+       (a.link
50
+         :float "left"
51
+         :clear "left"
52
+         :width "50%")
53
+
54
+       (div.content
55
+         :margin-top "-3em"
56
+         :padding-right "5em"
57
+         :float "right"
58
+         :width "50%")
59
+
42 60
        )
43 61
     ))
44 62
 
... ...
@@ -73,7 +91,8 @@
73 91
                     do (araneus:view 'root item)))))))))
74 92
 
75 93
 (araneus:define-controller root (params)
76
-  (let* ((url "http://reddit.com/r/programming.rss")
94
+  (declare (optimize (debug 3)))
95
+  (let* ((url "http://reddit.com/r/prolog.rss")
77 96
          (feed (alimenta.pull-feed::fetch-doc-from-url url)))
78 97
     (alimenta:to-feed feed :feed-link url)))
79 98
 
... ...
@@ -82,7 +101,7 @@
82 101
     (:content-type "application/xml+atom")
83 102
     (,(concatenate 'string
84 103
                "<?xml version=\"1.0\"?>"
85
-               (plump:serialize (alimenta:generate-xml feed :feed-type :atom)
104
+               (plump:serialize (alimenta:generate-xml feed :atom)
86 105
                    nil)))))
87 106
 
88 107
 (araneus:define-view feed-to-rss (feed)
... ...
@@ -90,14 +109,14 @@
90 109
     (:content-type "application/xml+rss")
91 110
     (,(concatenate 'string
92 111
                "<?xml version=\"1.0\"?>"
93
-               (plump:serialize (alimenta:generate-xml feed :feed-type :rss)
112
+               (plump:serialize (alimenta:generate-xml feed :rss)
94 113
                    nil)))))
95 114
 
96
-(defvar *app* (make-instance 'ningle:<app>))
115
+(defparameter *app* (make-instance 'ningle:<app>))
97 116
 
98 117
 (araneus:defroutes *app*
99 118
   (("/") (araneus:as-route 'root))
100 119
   (("/.rss") (araneus::compose-route (root) feed-to-rss)) 
101 120
   (("/.atom") (araneus::compose-route (root) feed-to-atom)))
102 121
 
103
-(defvar *handler* (clack:clackup *app* :port 9090 ))
122
+(defparameter *handler* (clack:clackup *app* :port 9091 ))