git.fiddlerwoaroof.com
Browse code

Update exports, improve clim client

fiddlerwoaroof authored on 19/07/2017 15:59:55
Showing 2 changed files
... ...
@@ -3,40 +3,82 @@
3 3
 
4 4
 (in-package :alimenta-clim)
5 5
 
6
+(defclass feed-list (clim:view)
7
+  ((%feeds :initarg :feeds :initform '() :accessor feeds)))
8
+
9
+(defmethod initialize-instance :after ((object feed-list) &key feeds)
10
+  (setf (feeds object) (copy-seq feeds)))
11
+
6 12
 (defclass feed-view (clim:view) ())
7 13
 (defclass item-view (clim:view) ((%item :initarg :item :accessor item)))
8 14
 
15
+(defclass feed-url ()
16
+  ((%uri :initarg :uri :reader uri)))
17
+
18
+(defmethod displayed-feeds ((feed-list feed-list))
19
+  (feeds feed-list))
20
+
21
+(defparameter *feed-list* (make-instance 'feed-list))
9 22
 (defparameter *feed-view* (make-instance 'feed-view))
10 23
 
11 24
 (clim:define-application-frame alimenta ()
12
-  ()
25
+  ((%feed-list :initarg :feed-list :initform (make-instance 'feed-list) :reader feed-list))
26
+  (:menu-bar t)
13 27
   (:pointer-documentation t)
14 28
   (: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))
29
+   (feeds :application
30
+          :height 400
31
+          ;; :width 100
32
+          :display-function 'display-app
33
+          :default-view (clim:with-application-frame (frame)
34
+                          (feed-list frame)))
35
+   (items :application
36
+          :height 400
37
+          ;; :width  200
38
+          :display-function #'display-app
39
+          :default-view *feed-view*)
40
+   (articles :application
41
+             :height 400
42
+             ;; :width 300
43
+             :display-function 'display-app
44
+             )
45
+   (int :interactor
46
+        :height 200
47
+        :width 600))
23 48
   (:layouts
24
-    (default (clim:vertically () app int))  
25
-    (flopped (clim:horizontally () app int))))
49
+   (default (clim:vertically () (clim:horizontally ()
50
+                                  feeds
51
+                                  items
52
+                                  articles)
53
+                             int))  
54
+   (flopped (clim:horizontally () feeds items articles int))))
55
+
56
+(defparameter *feeds* '("https://sancrucensis.com/feed/"
57
+                        "https://thomism.wordpress.com/feed/"))
26 58
 
27 59
 (defparameter *articles*
28 60
   (let ((errors 0))
29 61
     (handler-bind ((simple-error (lambda (c) c
30
-                                   (incf errors)
31
-                                   (when (< errors 1000)
32
-                                     (invoke-restart 'alimenta.rss::pop-token)))))
62
+                                         (incf errors)
63
+                                         (when (< errors 1000)
64
+                                           (invoke-restart 'alimenta.rss::pop-token)))))
33 65
       (alimenta.pull-feed:pull-feed "http://planet.lisp.org/rss20.xml" :type :rss))))
34 66
 
35 67
 (defgeneric display-pane-with-view (frame pane view))
36 68
 
69
+(defmethod display-pane-with-view (frame pane view)
70
+  (format pane "~&No content~%"))
71
+
37 72
 (defun display-app (frame pane)
38 73
   (display-pane-with-view frame pane (clim:stream-default-view pane)))
39 74
 
75
+(defmethod display-pane-with-view (frame pane (view feed-list))
76
+  (clim:with-text-style (pane (clim:make-text-style :serif :bold :larger))
77
+    (format pane "Feeds~%"))
78
+  (dolist (feed (displayed-feeds view))
79
+    (clim:with-output-as-presentation (pane feed 'feed-url)
80
+      (format pane "~a~%" (uri feed)))))
81
+
40 82
 (defmethod display-pane-with-view (frame pane (view feed-view))
41 83
   (clim:with-text-style (pane (clim:make-text-style :serif :bold :larger))
42 84
     (format pane "~a <~a>~%"
... ...
@@ -46,7 +88,13 @@
46 88
     (clim:with-output-as-presentation (pane item 'alimenta:item)
47 89
       (format pane "~a~%" (alimenta::title item)))))
48 90
 
91
+(defun format-content (node)
92
+  (lquery:$ (initialize (alimenta:content node)) "> p" (text)
93
+            (filter (op (string/= "" _)))
94
+            (map (op (trim-whitespace _)))))
95
+
49 96
 (defmethod display-pane-with-view (frame pane (view item-view))
97
+  ;; (format *xxx* "~&Displaying view~%")
50 98
   (let ((item (item view)))
51 99
     (with-accessors ((title alimenta::title)) item
52 100
       (clim:with-output-as-presentation (pane item 'alimenta:item)
... ...
@@ -61,38 +109,46 @@
61 109
                                  (split-sequence #\newline
62 110
                                                  text)))))))
63 111
 
64
-(define-alimenta-command (com-inspect :name t) ()
65
-  (clouseau:inspector
66
-    *articles*))
112
+;; (define-alimenta-command (com-inspect :name t) ()
113
+;;   (clouseau:inspector
114
+;;    *articles*))
67 115
 
68
-(define-alimenta-command (com-quite :name t) ()
116
+(define-alimenta-command (com-quit :name t :menu t) ()
69 117
   (clim:frame-exit clim:*application-frame*))
70 118
 
71 119
 (defmacro with-interactor ((interactor-symbol) &body body)
72 120
   `(let ((,interactor-symbol (clim:find-pane-named clim:*application-frame* 'int)))
73 121
      ,@body))
74 122
 
75
-(define-alimenta-command (open-feed :name t) ((url string))
123
+(define-alimenta-command (add-feed :name t) ((url string))
124
+  (let ((int (clim:find-pane-named clim:*application-frame* 'int)))
125
+    (push (make-instance 'feed-url :uri url)
126
+          (feeds (feed-list clim:*application-frame*)))
127
+    (format int "~&Added feed ~A~%" url)))
128
+
129
+(define-alimenta-command (open-feed :name t) ((url feed-url :gesture :select))
76 130
   (let ((int (clim:find-pane-named clim:*application-frame* 'int))
77
-        (app (clim:find-pane-named clim:*application-frame* 'app)))
78
-    (setf *articles* (alimenta.pull-feed:pull-feed url :detect t))
131
+        (app (clim:find-pane-named clim:*application-frame* 'items)))
132
+    (setf *articles* (alimenta.pull-feed:pull-feed (uri url)))
79 133
     (format int "~&Switching to the feed view~%")
80 134
     (setf (clim:stream-default-view app) *feed-view*)))
81 135
 
82 136
 (define-alimenta-command (to-feed :name t) ()
83 137
   (let ((int (clim:find-pane-named clim:*application-frame* 'int))
84
-        (app (clim:find-pane-named clim:*application-frame* 'app)))
138
+        (app (clim:find-pane-named clim:*application-frame* 'items)))
85 139
     (format int "~&Switching to the feed view~%")
86 140
     (setf (clim:stream-default-view app) *feed-view*)))
87 141
 
88 142
 (define-alimenta-command (com-pick-item :name t) ((item 'alimenta:item :gesture :select))
89
-  (let ((pane (clim:find-pane-named clim:*application-frame* 'app)))
143
+  (let ((pane (clim:find-pane-named clim:*application-frame* 'articles)))
144
+    (format pane "~&ARTICLE PANE~%")
90 145
     (with-interactor (int)
91 146
       (format int "~&Switching to the item: ")
92 147
       (clim:with-output-as-presentation (int item 'alimenta:item)
93 148
         (format int "~a" (alimenta:title item)))
94 149
       (terpri int))
95
-    (setf (clim:stream-default-view pane) (make-instance 'item-view :item item))))
150
+    (setf (clim:stream-default-view pane)
151
+          (make-instance 'item-view :item item))))
96 152
 
97 153
 (define-alimenta-command (flop-layout :name t) ()
98 154
   (let ((old-view (clim:frame-current-layout clim:*application-frame*)))
... ...
@@ -101,7 +157,15 @@
101 157
             ('default  'flopped)
102 158
             (t 'default)))))
103 159
 
104
-#|
105
-(clim:run-frame-top-level
106
-  (clim:make-application-frame 'alimenta-clim::alimenta))
107
-|#
160
+
161
+(defun main ()
162
+  (clim:run-frame-top-level
163
+   (clim:make-application-frame 'alimenta-clim::alimenta
164
+                                :feed-list
165
+                                (make-instance 'feed-list
166
+                                               :feeds (list (make-instance 'feed-url
167
+                                                                           :uri
168
+                                                                           "http://thomism.wordpress.com/feed")
169
+                                                            (make-instance 'feed-url
170
+                                                                           :uri
171
+                                                                           "http://planet.lisp.org/rss20.xml"))))))
... ...
@@ -17,7 +17,7 @@
17 17
            #:doc #:source-type #:id #:date #:content #:item #:description
18 18
            #:%generate-xml #:%to-feed #:get-items #:make-item #:complex-value
19 19
            #:primary-value #:render #:author #:content-el #:feed-type-unsupported
20
-	   #:pop-token #:filter-feed))
20
+	   #:pop-token #:filter-feed #:feed-entity))
21 21
 
22 22
 (defpackage #:alimenta.html
23 23
   (:use #:cl #:should-test #:lquery #:alexandria #:anaphora #:alimenta #:data-class