Permalink
Browse files

Cleanups. Add stub for atom-feed view.

  • Loading branch information...
1 parent 1bf2ab1 commit e66611814f7169a826adbe8cebd79d2d2290effe @thorwil committed Oct 12, 2011
View
@@ -5,6 +5,7 @@
(def articles-per-journal-page 3)
(def articles-per-admin-page 5)
+(def articles-per-feed-page 10)
(def blobs-per-page 3)
@@ -41,10 +41,10 @@
(ds/delete! old)
(ds/save! (b/SlugRel. to id))))
-;; Specialize articles-paginated* for a view including bodies:
+;; Specialize b/articles-paginated* for a view including bodies:
(def articles-paginated (partial b/articles-paginated* #(b/unText-body %)))
-;; Specialize articles-paginated* for just listing deletion-queue, title, link:
+;; Specialize b/articles-paginated* for just listing deletion-queue, title, link:
(def articles-heads-paginated (partial b/articles-paginated* #(select-keys % [:slug :title])))
@@ -7,9 +7,12 @@
(:use [ring.util.response :only [response redirect]]
[net.cgrand.moustache :only [alter-response]]
[clojure.string :only [join]]
- [appengine-magic.services.user :only [user-logged-in? user-admin?]]))
+ [appengine-magic.services.user :only [user-logged-in? user-admin?]]
+ [tlog.models.for_validators :only [articles-default-range]]))
+;; Utility
+
(defn- roles
"Return list of roles of the current user as keys."
[]
@@ -20,6 +23,7 @@
[]
(conj (models/article-slugs) "admin" "login" "logout" "comment"))
+
;; Event handlers
(defn on-slugs-change!
@@ -63,13 +67,6 @@
:token (chan/create-channel "trigger-on-slugs-change")
:slugs (slugs)}))
-;; Admin/Visitor GET handlers
-
-(defn not-found
- []
- (-> (views/not-found (roles) {:title "Not found"})
- (alter-response #(assoc % :status 404))))
-
;; Admin POST handlers
@@ -118,26 +115,35 @@
(response "OK"))
-;; Visitor GET handlers
+;; Visitor/Admin GET handlers
(defn journal
"List of Articles with full bodies."
- [range-or-nothing]
- (views/journal (roles) (models/articles-paginated range-or-nothing conf/articles-per-journal-page)))
+ [from-to]
+ (views/journal (roles) (models/articles-paginated from-to conf/articles-per-journal-page)))
(defn tree
"Article with (nested) Comments."
[slug->tree]
(views/tree (roles) (assoc slug->tree :token (chan/create-channel "trigger-on-slugs-change")
:slugs (slugs))))
-
(defn serve-file
"Take a __BlobInfo__ key and request, serve file from blobstore."
[key request]
(blobs/serve request key))
+(defn not-found
+ []
+ (-> (views/not-found (roles) {:title "Not found"})
+ (alter-response #(assoc % :status 404))))
+
+(defn atom-feed
+ []
+ (views/atom-feed (roles) (models/articles-paginated (articles-default-range conf/articles-per-feed-page)
+ conf/articles-per-journal-page)))
+
-;; Visitor POST handlers
+;; Visitor/Admin POST handlers
(defn add-comment!
"Handle Publish-button triggered POST for adding Comments."
@@ -43,6 +43,7 @@
;; Match for root, using default range, or match given index range:
["login" &] (-> (user/login-url) redirect constantly)
["logout" &] (-> (user/logout-url) redirect constantly)
+ ["atom" &] (h/atom-feed)
[[filename valid/filename->blob-key]] (partial h/serve-file filename)
[[range-or-nothing valid/articles-range-journal]] (h/journal range-or-nothing)
[[slug->tree valid/slug->tree]] (h/tree slug->tree)
@@ -83,8 +83,8 @@
(defn articles-range
"items-range-or-default specialized for articles."
- [from-to-default maybe-from-to]
- (items-range-or-default maybe-from-to #(models/articles-default-range from-to-default)))
+ [default-count maybe-from-to]
+ (items-range-or-default maybe-from-to #(models/articles-default-range default-count)))
(defn articles-range-admin
[from-to]
@@ -0,0 +1,6 @@
+(ns tlog.views.atom-feed
+ "Functions for buidling an atom feed.")
+
+(defn stub
+ [x]
+ "Lorem")
View
@@ -2,7 +2,7 @@
(:use [clojure.java.io :only [resource]]
[ring.util.response :only [response content-type]]
tlog.views.utility
- tlog.views.parts))
+ [tlog.views.parts :only [base]]))
(defn content-type-html
[r]
@@ -36,17 +36,19 @@
(defn comp-view
"Compose functions to build a view. Functions are applied right to left, thus need to be listed
from outer to inner."
- [fs is-post]
+ [fs shell*]
(let [wrapped (map wrap-map->map fs)
- shell (if is-post
- [content-type-html response extract-buildup] ;; For a response to POST
- [constantly content-type-html response base])] ;; For a response to GET
+ shell (case shell*
+ ;; For finalizing responses to a POST, to deliver a feed, or response to a GET (default):
+ :on-post [content-type-html response extract-buildup]
+ :atom-feed [constantly response extract-buildup]
+ [constantly content-type-html response base])]
#(apply comp (concat shell wrapped))))
(defmacro defview
"Macro for defining a view. Takes a vector with a name, a map with vectors per role and an
optional argument, that if present, causes construction of a view for answering a POST."
- [name per-role* & [is-post]]
+ [name per-role* & [shell]]
;; If :everyone is not specified, default to an empty vector for it:
(let [per-role (into {:everyone []} per-role*)]
`(defn ~name
@@ -60,7 +62,7 @@
[fs# ds#] (filter-split fn? ss#)]
;; Compose all functions. Assemble argument map from key-value pairs
;; from the defs and the view's argument map:
- (((comp-view (cons identity fs#) ~is-post)) (into m# ds#))))))
+ (((comp-view (cons identity fs#) ~shell)) (into m# ds#))))))
(defn macro-for-each
"Take a quoted macro name and a vector. Return a do form with lists forming macro and vector element pairs."
View
@@ -1,12 +1,14 @@
(ns tlog.views.views
(:use [ring.util.response :only [response]]
tlog.views.parts
+ tlog.views.atom-feed
[tlog.views.compose :only [defview defviews]]))
-;; Views taking roles into consideration
-
(defviews
+ ;; Views with no admin specific parts:
+ [atom-feed {:everyone [stub]}
+ :atom-feed]
;; Visitor/admin views:
[journal {:everyone [journal-rendition
option-time-offset
@@ -47,16 +49,11 @@
switch-comment-deleter-false]
:admin [option-comments-admin-editable
switch-comment-deleter-true]}
- true])
+ :on-post])
-;; Views independent of roles
+;; Special views
(defn plain
- [s]
- ((comp constantly response) s))
-
-(defn list-slugs
- "Plain text, space-separated list of slugs."
- [slugs]
- (plain (interpose " " slugs)))
+[s]
+((comp constantly response) s))
View
@@ -1,10 +1,15 @@
+Rename parts.clj html.clj
+Decide on home page content and journal URL
+
Features
--------
-Tags
-Series
RSS
+ <link rel=”alternate” type=”application/rss+xml” title=”Atom feed” href=”link+to+your+feed”/>
Channels
+Tags
+Series
Pingbacks
+Email notifications/subscriptions
G-channel update blob list
G-channel update admin article list
Handle delete/cancel-delete asynchronously

0 comments on commit e666118

Please sign in to comment.