Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Start moving to mustache for templates.

Common, the paste creation page, and the show paste page has been
updated. The hiccup stuff still around is so that the rest keeps
compiling while I incrementally move things to mustache.
  • Loading branch information...
commit 2596ce111ca1cc3b589638e7de09cc16cec28938 1 parent 35416fe
Anthony Grimes Raynes authored
3  project.clj
@@ -2,7 +2,8 @@
2 2 :description "This is like, totally a pastebin, dude."
3 3 :url "https://refheap.com"
4 4 :dependencies [[org.clojure/clojure "1.3.0"]
5   - [noir "1.3.0-alpha8"]
  5 + [stencil "0.2.0"]
  6 + [noir "1.3.0-alpha9"]
6 7 [congomongo "0.1.8"]
7 8 [clj-config "0.2.0"]
8 9 [clj-http "0.3.1"]
27 resources/public/css/refheap.css
@@ -60,11 +60,13 @@ div.headerlinks {
60 60 }
61 61
62 62 div#useri {
63   - padding-left: 10px;
64   - border-left: 1px solid #DDD;
65 63 float: right;
66 64 }
67 65
  66 +a#userbutton {
  67 + font-weight: bold;
  68 +}
  69 +
68 70 div#user {
69 71 padding-top: 15px;
70 72 }
@@ -291,6 +293,10 @@ div#login {
291 293 text-align: center;
292 294 }
293 295
  296 +#starting {
  297 + float: left;
  298 +}
  299 +
294 300 .error {
295 301 color: #CF0000;
296 302 font-weight: bold;
@@ -301,6 +307,11 @@ a#newer {
301 307 margin-right: 10px;
302 308 }
303 309
  310 +a.borderedbutton {
  311 + border-right: 1px solid #DDD;
  312 + padding-right: 10px;
  313 + margin-right: 8px;
  314 +}
304 315 .pagebutton {
305 316 font-size: 15px;
306 317 padding: 5px 10px;
@@ -352,3 +363,15 @@ button#gentoken {
352 363 height: 24px;
353 364 border-radius: 5px;
354 365 }
  366 +
  367 +.clearfix:after {
  368 + visibility: hidden;
  369 + display: block;
  370 + font-size: 0;
  371 + content: " ";
  372 + clear: both;
  373 + height: 0;
  374 +}
  375 +
  376 +* html .clearfix { zoom: 1; } /* IE6 */
  377 +*:first-child+html .clearfix { zoom: 1; } /* IE7 */
2  src/refheap/server.clj
@@ -21,5 +21,5 @@
21 21 port (Integer. (or (get (System/getenv) "PORT") (str (config :port))))]
22 22 (server/start port {:mode mode
23 23 :ns 'refheap
24   - :session-store (mongo-session :refheap-sessions)})))
  24 + :session-store (mongo-session :sessions)})))
25 25
72 src/refheap/views/common.clj
... ... @@ -1,71 +1,29 @@
1 1 (ns refheap.views.common
2 2 (:use [clavatar.core :only [gravatar]])
3 3 (:require [noir.session :as session]
  4 + [stencil.core :as stencil]
  5 + [hiccup.core :as hiccup]
4 6 [hiccup.page-helpers :as ph]
5 7 [refheap.models.paste :as paste]))
6 8
7 9 (defn avatar [email size]
8 10 (ph/image (gravatar email :size size)))
9 11
10   -(defn analytics []
11   - (ph/javascript-tag
12   - "var _gaq = _gaq || [];
13   - _gaq.push(['_setAccount', 'UA-28074244-1']);
14   - _gaq.push(['_trackPageview']);
15   -
16   - (function() {
17   - var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
18   - ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
19   - var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
20   - })();"))
21   -
22   -(defn header []
23   - [:head
24   - [:title "RefHeap"]
25   - [:link {:rel "shortcut icon" :href "/img/favicon.ico"}]
26   - (ph/include-css "https://fonts.googleapis.com/css?family=Open+Sans")
27   - (ph/include-css "/css/refheap.css")
28   - (ph/include-css "/css/tomorrow-night-bright.css")
29   - (ph/include-css "/css/chosen.css")
30   - (ph/include-js "/js/jquery-1.7.1.min.js")
31   - (ph/include-js "https://browserid.org/include.js")
32   - (ph/include-js "/js/chosen.jquery.min.js")
33   - (ph/include-js "/js/refheap.js")
34   - (analytics)])
35   -
36 12 (defn logged-in [username]
37   - (if-let [user (or username
38   - (and (bound? #'session/*noir-session*)
39   - (:username (session/get :user))))]
40   - [:div
41   - [:b (ph/link-to (str "/users/" user) user)]
42   - (ph/link-to "/users/logout" "logout")]
43   - [:img#signin.imgbutton {:src "/img/browserid.png"}]))
  13 + (stencil/render-file
  14 + "refheap/views/templates/loggedin"
  15 + {:user (when-let [user (or username
  16 + (and (bound? #'session/*noir-session*)
  17 + (:username (session/get :user))))]
  18 + {:username user})}))
  19 +
  20 +(defn layout [body]
  21 + (stencil/render-file
  22 + "refheap/views/templates/common"
  23 + {:user (logged-in nil)
  24 + :content (hiccup/html body)}))
44 25
45   -(defn layout [& content]
46   - (ph/html5
47   - (header)
48   - [:body
49   - [:div#site-container
50   - [:div#header
51   - [:a#site {:href "/paste"} "The Reference Heap"]
52   - [:div.headerlinks
53   - (ph/link-to {:style "border-right: 1px solid #DDD;"} "/pastes" "Latest")
54   - (ph/link-to {:style "margin-left: 10px;"} "http://blog.refheap.com" "Blog")
55   - [:div#useri (logged-in nil)]]]
56   - [:div#content
57   - [:div#container content]
58   - [:div#footer
59   - [:p.centered
60   - (ph/link-to "https://github.com/Raynes/refheap" "Refheap")
61   - " is powered by " (ph/link-to "http://clojure.org" "Clojure") ", "
62   - (ph/link-to "http://webnoir.org" "Noir") ", "
63   - (ph/link-to "http://mongodb.org" "MongoDB") ", "
64   - (ph/link-to "http://pygments.org/" "Pygments")
65   - ", and "
66   - (ph/link-to "http://photos.geni.com/p13/45/9a/44/22/5344483904b52482/img_7798_large.jpg" "Iguana") ". Please read: the "
67   - (ph/link-to "/legal/tos" "terms of service") ", and "
68   - (ph/link-to "/legal/privacy" "privacy") " policy."]]]]]))
  26 +(def header nil)
69 27
70 28 (defn page-buttons [base n per page]
71 29 [:div.centered
9 src/refheap/views/login.clj
@@ -3,9 +3,9 @@
3 3 [refheap.views.common :only [layout logged-in]]
4 4 [noir.core :only [defpage]]
5 5 [noir.response :only [redirect json]]
6   - [hiccup.core :only [html]]
7   - [refheap.views.paste :only [private-checkbox]])
  6 + [hiccup.core :only [html]])
8 7 (:require [refheap.models.login :as login]
  8 + [stencil.core :as stencil]
9 9 [noir.session :as session]))
10 10
11 11 (defn create-user-page [email]
@@ -39,8 +39,7 @@
39 39 (defpage [:post "/user/verify"] {:keys [assertion]}
40 40 (when-let [{:keys [email]} (login/verify-assertion assertion)]
41 41 (if-let [username (login/user-exists email)]
42   - (json {:login-html (html (logged-in username))
43   - :private-html (html (private-checkbox {:private false}))})
  42 + (json {:login-html (logged-in username)})
44 43 (do
45 44 (session/flash-put! :email email)
46   - (json {:chooselogin-html (html (create-user-page email))})))))
  45 + (json {:chooselogin-html (html (create-user-page email))})))))
105 src/refheap/views/paste.clj
@@ -6,80 +6,20 @@
6 6 (:require [refheap.models.paste :as paste]
7 7 [refheap.models.users :as users]
8 8 [noir.session :as session]
  9 + [stencil.core :as stencil]
9 10 [hiccup.form-helpers :as fh]
10 11 [hiccup.page-helpers :as ph]))
11 12
12   -
13   -(defn private-checkbox [old]
14   - (list (fh/check-box :private (:private old))
15   - (fh/label :private "Private")))
16   -
17 13 (defn create-paste-page [lang & [old]]
18   - (layout
19   - [:div#main-container
20   - [:div#paste-container
21   - (fh/form-to
22   - [:post (if old
23   - (str "/paste/" (:paste-id old) "/edit")
24   - "/paste/create")]
25   - [:div#paste-header
26   - (fh/drop-down "language"
27   - (sort #(.compareToIgnoreCase % %2)
28   - (keys paste/lexers))
29   - (or lang (:language old "Clojure")))
30   - (private-checkbox old)
31   - (fh/submit-button (if old "Edit!" "Paste!"))]
32   - (fh/text-area :paste (:raw-contents old)))]
33   - [:div#main-right
34   - (ph/unordered-list ["Throw some text in that big white box over on the left" "Select what language you want to use for syntax highlighting" "Hit 'Paste!'" "Share, edit, refine; enjoy."])
35   - [:p "Protip: if you get tired of selecting your language every time you drop in, you can specify it in the URL and bookmark the link. Example: \""
36   - (ph/link-to "http://refheap.com/paste?lang=Ruby" "http://refheap.com/paste?lang=Ruby") "\""]
37   - [:p "We have an API! Generate a token "
38   - (ph/link-to "/api" "here")
39   - " and find examples in our "
40   - (ph/link-to "https://github.com/Raynes/refheap/wiki/Documentation:-API" "documentation")
41   - ". Happy hacking!"]
42   - [:p "Send feedback, feature requests, and bug reports "
43   - (ph/link-to "http://github.com/raynes/refheap/issues" "here") "."]]]
44   - [:div.clear]))
45   -
46   -(defn show-paste-page [id]
47   - (when-let [{:keys [lines private user contents language date fork] :as all} (paste/get-paste id)]
48   - (layout
49   - (list
50   - [:div.floater
51   - [:div#pasteinfo
52   - [:span.info language]
53   - [:span.info "Lines: " lines]
54   - (when private
55   - [:span {:class "info private"} "Private"])
56   - [:span#last.info
57   - (if fork "Forked by " "Pasted by ")
58   - (if user
59   - (let [user (:username (users/get-user-by-id user))]
60   - (ph/link-to (str "/users/" user) user))
61   - "anonymous")
62   - (when fork
63   - (list
64   - " from "
65   - (if-let [paste (:paste-id (paste/get-paste-by-id fork))]
66   - (ph/link-to (str "/paste/" paste) paste)
67   - "[deleted]")))
68   - " on "
69   - (date-string date)
70   - [:div#edit
71   - (ph/link-to (str "/paste/" id "/embed") "embed")
72   - (ph/link-to (str "/paste/" id "/raw") "raw")
73   - (ph/link-to (str "/paste/" id "/fullscreen") "maximize")
74   - (when-not (= user (:id (session/get :user)))
75   - (ph/link-to (str "/paste/" id "/fork") "fork"))
76   - (when (and user (= user (:id (session/get :user))))
77   - (list
78   - [:a {:href (str "/paste/" id "/edit")} "edit"]
79   - [:a#delete.evil {:href (str "/paste/" id "/delete")} "delete"]))]]]
80   - [:div#paste.syntax
81   - contents]]
82   - [:div.clear]))))
  14 + (stencil/render-file
  15 + "refheap/views/templates/paste"
  16 + {:url (if old
  17 + (str "/paste/" (:paste-id old) "/edit")
  18 + "/paste/create")
  19 + :languages (for [lang (sort #(.compareToIgnoreCase % %2)
  20 + (keys (dissoc paste/lexers "Clojure")))]
  21 + {:language lang})
  22 + :old (:raw-contents old)}))
83 23
84 24 (defn fullscreen-paste [id]
85 25 (when-let [contents (:contents (paste/get-paste id))]
@@ -88,6 +28,25 @@
88 28 [:body#fullscreen
89 29 [:div.syntax contents]])))
90 30
  31 +(defn show-paste-page [id]
  32 + (when-let [{:keys [lines private user contents language date fork]
  33 + :as all}
  34 + (paste/get-paste id)]
  35 + (stencil/render-file
  36 + "refheap/views/templates/pasted"
  37 + {:language language
  38 + :lines lines
  39 + :id id
  40 + :username (if user
  41 + (let [user (:username (users/get-user-by-id user))]
  42 + (str "<a href=\"/users/" user "\">" user "</a>"))
  43 + "anonymous")
  44 + :date (date-string date)
  45 + :forked (when fork {:from (if-let [paste (:paste-id (paste/get-paste-by-id fork))]
  46 + (str "<a href=\"/paste/" paste "\">" paste "</a>")
  47 + "[deleted]")})
  48 + :contents contents})))
  49 +
91 50 (defpage "/paste/:id/fullscreen" {:keys [id]}
92 51 (fullscreen-paste id))
93 52
@@ -138,7 +97,7 @@
138 97 [:p.error error]))
139 98
140 99 (defpage "/paste" {:keys [lang]}
141   - (create-paste-page lang))
  100 + (layout (create-paste-page lang)))
142 101
143 102 (defpage "/paste/:id/edit" {:keys [id]}
144 103 (let [paste (paste/get-paste id)]
@@ -188,7 +147,7 @@
188 147 (fail paste))))
189 148
190 149 (defpage "/paste/:id" {:keys [id]}
191   - (show-paste-page id))
  150 + (layout (show-paste-page id)))
192 151
193 152 (defpage "/pastes" {:keys [page]}
194   - (all-pastes-page (paste/proper-page (Long. (or page "1")))))
  153 + (all-pastes-page (paste/proper-page (Long. (or page "1")))))
58 src/refheap/views/templates/common.mustache
... ... @@ -0,0 +1,58 @@
  1 +<!DOCTYPE html>
  2 +<html>
  3 + <head>
  4 + <title>RefHeap</title>
  5 + <link href="/img/favicon.ico" rel="shortcut icon" />
  6 + <link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet" type="text/css" />
  7 + <link href="/css/refheap.css" rel="stylesheet" type="text/css" />
  8 + <link href="/css/tomorrow-night-bright.css" rel="stylesheet" type="text/css" />
  9 + <link href="/css/chosen.css" rel="stylesheet" type="text/css" />
  10 +
  11 + <script src="/js/jquery-1.7.1.min.js" type="text/javascript"></script>
  12 + <script src="https://browserid.org/include.js" type="text/javascript"></script>
  13 + <script src="/js/chosen.jquery.min.js" type="text/javascript"></script>
  14 + <script src="/js/refheap.js" type="text/javascript"></script>
  15 + <script type="text/javascript">//<![CDATA[
  16 + var _gaq = _gaq || [];
  17 + _gaq.push(['_setAccount', 'UA-28074244-1']);
  18 + _gaq.push(['_trackPageview']);
  19 +
  20 + (function() {
  21 + var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  22 + ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  23 + var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  24 + })();
  25 + //]]>
  26 + </script>
  27 + </head>
  28 +
  29 + <body>
  30 + <div id="site-container">
  31 + <div id="header">
  32 + <a id="site" href="/paste">The Reference Heap</a>
  33 + <div class="headerlinks">
  34 + <div id="starting">
  35 + <a class="borderedbutton" href="/pastes">Latest</a>
  36 + <a class="borderedbutton" href="http://blog.refheap.com">Blog</a>
  37 + </div>
  38 + <div id="useri">
  39 + {{{user}}}
  40 + </div>
  41 + </div>
  42 + </div>
  43 + <div id="content">
  44 + <div id="container" class="clearfix">
  45 + {{{content}}}
  46 + </div>
  47 + <div id="footer">
  48 + <p class="centered">
  49 + <a href="https://github.com/Raynes/refheap">RefHeap</a> is powered by
  50 + <a href="http://clojure.org">Clojure</a>, <a href="http://webnoir.org">Noir</a>,
  51 + <a href="http://mongodb.org">MongoDB</a>, and <a href="http://pygments.org">Pygments</a>.
  52 + Please read our <a href="/legal/tos">terms of service</a> and
  53 + <a href="/legal/privacy">privacy policy</a>.
  54 + </div>
  55 + </div>
  56 + </div>
  57 + </body>
  58 +</html>
9 src/refheap/views/templates/loggedin.mustache
... ... @@ -0,0 +1,9 @@
  1 +{{#user}}
  2 +<div>
  3 + <a id="userbutton" href="/users/{{username}}">{{username}}</a>
  4 + <a href="/users/logout">logout</a>
  5 +</div>
  6 +{{/user}}
  7 +{{^user}}
  8 +<img id="signin" class="imgbutton" src="/img/browserid.png" alt="BrowserID">
  9 +{{/user}}
42 src/refheap/views/templates/paste.mustache
... ... @@ -0,0 +1,42 @@
  1 +<div id="main-container">
  2 + <div id="paste-container">
  3 + <form name="paste" action="{{url}}" method="post">
  4 + <div id="paste-header">
  5 + <select id="language" name="language">
  6 + {{#languages}}
  7 + <option value="{{language}}">{{language}}</option>
  8 + {{/languages}}
  9 + <option selected value="Clojure">Clojure</option>
  10 + </select>
  11 + <input name="private" type="checkbox" />
  12 + <label for="private">Private</label>
  13 + <input value="Paste!" type="submit" />
  14 + </div>
  15 + <textarea name="paste" id="paste">{{old}}</textarea>
  16 + </form>
  17 + </div>
  18 +
  19 + <div id="main-right">
  20 + <ul>
  21 + <li>Throw some text in that big white box over on the left</li>
  22 + <li>Select what language you want to use for syntax highlighting</li>
  23 + <li>Hit 'Paste!'</li>
  24 + <li>Share, edit, refine; enjoy.</li>
  25 + </ul>
  26 + <p>
  27 + Protip: if you get tired of selecting your language every time you drop in,
  28 + you can specify it in the URL and bookmark the link. Example:
  29 + <a href="https://refheap.com/paste?lang=Ruby">http://refheap.com/paste?lang=Ruby</a>
  30 + </p>
  31 + <p>
  32 + We have an API! Generate a token <a href="/api">here</a> and find examples in our
  33 + <a href="https://github.com/Raynes/refheap/wiki/Documentation:-API">documentation</a>.
  34 + Happy hacking!
  35 + </p>
  36 + <p>
  37 + Send feedback, feature requests, and bug reports
  38 + <a href="http://github.com/raynes/refheap/issues">here</a>
  39 + </p>
  40 + </div>
  41 +
  42 +</div>
33 src/refheap/views/templates/pasted.mustache
... ... @@ -0,0 +1,33 @@
  1 +<div class="floater clearfix">
  2 + <div id="pasteinfo">
  3 + <span class="info">{{language}}</span>
  4 + <span class="info">{{lines}}</span>
  5 + <span class="info private">Private</span>
  6 + <span lass="info">
  7 + {{#forked}}
  8 + Forked by
  9 + {{/forked}}
  10 + {{^forked}}
  11 + Pasted by
  12 + {{/forked}}
  13 + {{{username}}}
  14 + {{#forked}}
  15 + from {{{from}}}
  16 + {{/forked}}
  17 + on {{date}}
  18 + </span>
  19 + <div id="edit">
  20 + <a href="/paste/{{id}}/embed">embed</a>
  21 + <a href="/paste/{{id}}/raw">raw</a>
  22 + <a href="/paste/{{id}}/fullscreen">maximize</a>
  23 + <a href="/paste/{{id}}/fork">fork</a>
  24 + {{#owner}}
  25 + <a href="/paste/{{id}}/edit">edit</a>
  26 + <a href="/paste/{{id}}/delete" class="evil">delete</a>
  27 + {{/owner}}
  28 + </div>
  29 + </div>
  30 + <div id="paste" class="syntax">
  31 + {{{contents}}}
  32 + </div>
  33 +</div>

0 comments on commit 2596ce1

Please sign in to comment.
Something went wrong with that request. Please try again.