Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Move the all-pastes page to mustache.

  • Loading branch information...
commit 6c9d343c5223859ec4f59fbfdb71d4427400d01d 1 parent f660e08
@Raynes Raynes authored
View
10 src/refheap/views/common.clj
@@ -26,8 +26,8 @@
(def header nil)
(defn page-buttons [base n per page]
- [:div.centered
- (when-not (= 1 page)
- [:a#newer.pagebutton {:href (str base "?page=" (dec page))} "newer"])
- (when-not (or (zero? n) (= page (paste/count-pages n per)))
- [:a.pagebutton {:href (str base "?page=" (inc page))} "older"])])
+ (stencil/render-file
+ "refheap/views/templates/pagination"
+ {:newer (when-not (= 1 page) {:base base, :page (dec page)})
+ :older (when-not (or (zero? n) (= page (paste/count-pages n per)))
+ {:base base, :page (inc page)})}))
View
40 src/refheap/views/paste.clj
@@ -52,21 +52,15 @@
(defpage "/paste/:id/framed" {:keys [id]}
(fullscreen-paste id))
-(defn render-paste-preview [paste]
- (let [{:keys [paste-id lines summary date user]} paste]
- (list
- [:div.preview-header
- (if user
- (let [user (:username (users/get-user-by-id user))]
- (ph/link-to (str "/users/" user) user))
- "anonymous")
- " on "
- (date-string date)
- [:div.right
- "[" (ph/link-to (str "/paste/" paste-id) "Link") "]"]]
- [:div.syntax summary
- (if (> lines 5) [:div.more (ph/link-to (str "/paste/" paste-id) "more...")])]
- [:br])))
+(defn render-paste-previews [pastes]
+ (stencil/render-file
+ "refheap/views/templates/preview"
+ {:pastes (for [{:keys [paste-id lines summary date user]} pastes]
+ {:user (when user (users/get-user-by-id user))
+ :date (date-string date)
+ :id paste-id
+ :summary summary
+ :more (> lines 5)})}))
(defn render-embed-page [paste]
(let [{:keys [paste-id content]} paste]
@@ -76,20 +70,14 @@
[:p "Please copy the following html element onto your webpage, and change the inline size/styling as needed:"]
[:p "<iframe style=\"width: 648px; height: 400px; border: 0px;\" src=\"http://refheap.com/paste/" paste-id "/framed\" />"]]))))
-(defn pastes [ps]
- [:div#preview-container
- (for [paste ps]
- (render-paste-preview paste))])
-
(defn all-pastes-page [page]
(let [paste-count (paste/count-pastes false)]
(if (> page (paste/count-pages paste-count 20))
(redirect "/paste")
- (layout
- [:div
- (pastes (paste/get-pastes page))
- (page-buttons "/pastes" paste-count 20 page)
- [:div.clear]]))))
+ (stencil/render-file
+ "refheap/views/templates/all"
+ {:pastes (render-paste-previews (paste/get-pastes page))
+ :paste-buttons (page-buttons "/pastes" paste-count 20 page)}))))
(defn fail [error]
(layout
@@ -149,4 +137,4 @@
(layout (show-paste-page id)))
(defpage "/pastes" {:keys [page]}
- (all-pastes-page (paste/proper-page (Long. (or page "1")))))
+ (layout (all-pastes-page (paste/proper-page (Long. (or page "1"))))))
View
4 src/refheap/views/templates/all.mustache
@@ -0,0 +1,4 @@
+<div class="clearfix">
+ {{{pastes}}}
+ {{{paste-buttons}}}
+</div>
View
8 src/refheap/views/templates/pagination.mustache
@@ -0,0 +1,8 @@
+<div class="centered">
+ {{#newer}}
+ <a id="newer" class="pagebutton" href="{{base}}?page={{page}}">newer</a>
+ {{/newer}}
+ {{#older}}
+ <a class="pagebutton" href="{{base}}?page={{page}}">older</a>
+ {{/older}}
+</div>
View
22 src/refheap/views/templates/preview.mustache
@@ -0,0 +1,22 @@
+<div id="preview-container">
+ {{#pastes}}
+ <div class="preview-header">
+ {{#user}}
+ <a href="/users/{{username}}">{{username}}</a>
+ {{/user}}
+ {{^user}}
+ anonymous
+ {{/user}}
+ on {{date}}
+ <div class="right">
+ [<a href="/paste/{{id}}">Link</a>]
+ </div>
+ <div class="syntax">
+ {{{summary}}}
+ {{#more}}
+ <a href="paste/{{id}}">more...</a>
+ {{/more}}
+ </div>
+ </div>
+ {{/pastes}}
+</div>
Please sign in to comment.
Something went wrong with that request. Please try again.