Permalink
Browse files

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...
1 parent 35416fe commit 2596ce111ca1cc3b589638e7de09cc16cec28938 @Raynes Raynes committed Feb 14, 2012
View
@@ -2,7 +2,8 @@
:description "This is like, totally a pastebin, dude."
:url "https://refheap.com"
:dependencies [[org.clojure/clojure "1.3.0"]
- [noir "1.3.0-alpha8"]
+ [stencil "0.2.0"]
+ [noir "1.3.0-alpha9"]
[congomongo "0.1.8"]
[clj-config "0.2.0"]
[clj-http "0.3.1"]
@@ -60,11 +60,13 @@ div.headerlinks {
}
div#useri {
- padding-left: 10px;
- border-left: 1px solid #DDD;
float: right;
}
+a#userbutton {
+ font-weight: bold;
+}
+
div#user {
padding-top: 15px;
}
@@ -291,6 +293,10 @@ div#login {
text-align: center;
}
+#starting {
+ float: left;
+}
+
.error {
color: #CF0000;
font-weight: bold;
@@ -301,6 +307,11 @@ a#newer {
margin-right: 10px;
}
+a.borderedbutton {
+ border-right: 1px solid #DDD;
+ padding-right: 10px;
+ margin-right: 8px;
+}
.pagebutton {
font-size: 15px;
padding: 5px 10px;
@@ -352,3 +363,15 @@ button#gentoken {
height: 24px;
border-radius: 5px;
}
+
+.clearfix:after {
+ visibility: hidden;
+ display: block;
+ font-size: 0;
+ content: " ";
+ clear: both;
+ height: 0;
+}
+
+* html .clearfix { zoom: 1; } /* IE6 */
+*:first-child+html .clearfix { zoom: 1; } /* IE7 */
View
@@ -21,5 +21,5 @@
port (Integer. (or (get (System/getenv) "PORT") (str (config :port))))]
(server/start port {:mode mode
:ns 'refheap
- :session-store (mongo-session :refheap-sessions)})))
+ :session-store (mongo-session :sessions)})))
@@ -1,71 +1,29 @@
(ns refheap.views.common
(:use [clavatar.core :only [gravatar]])
(:require [noir.session :as session]
+ [stencil.core :as stencil]
+ [hiccup.core :as hiccup]
[hiccup.page-helpers :as ph]
[refheap.models.paste :as paste]))
(defn avatar [email size]
(ph/image (gravatar email :size size)))
-(defn analytics []
- (ph/javascript-tag
- "var _gaq = _gaq || [];
- _gaq.push(['_setAccount', 'UA-28074244-1']);
- _gaq.push(['_trackPageview']);
-
- (function() {
- var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
- ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
- var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
- })();"))
-
-(defn header []
- [:head
- [:title "RefHeap"]
- [:link {:rel "shortcut icon" :href "/img/favicon.ico"}]
- (ph/include-css "https://fonts.googleapis.com/css?family=Open+Sans")
- (ph/include-css "/css/refheap.css")
- (ph/include-css "/css/tomorrow-night-bright.css")
- (ph/include-css "/css/chosen.css")
- (ph/include-js "/js/jquery-1.7.1.min.js")
- (ph/include-js "https://browserid.org/include.js")
- (ph/include-js "/js/chosen.jquery.min.js")
- (ph/include-js "/js/refheap.js")
- (analytics)])
-
(defn logged-in [username]
- (if-let [user (or username
- (and (bound? #'session/*noir-session*)
- (:username (session/get :user))))]
- [:div
- [:b (ph/link-to (str "/users/" user) user)]
- (ph/link-to "/users/logout" "logout")]
- [:img#signin.imgbutton {:src "/img/browserid.png"}]))
+ (stencil/render-file
+ "refheap/views/templates/loggedin"
+ {:user (when-let [user (or username
+ (and (bound? #'session/*noir-session*)
+ (:username (session/get :user))))]
+ {:username user})}))
+
+(defn layout [body]
+ (stencil/render-file
+ "refheap/views/templates/common"
+ {:user (logged-in nil)
+ :content (hiccup/html body)}))
-(defn layout [& content]
- (ph/html5
- (header)
- [:body
- [:div#site-container
- [:div#header
- [:a#site {:href "/paste"} "The Reference Heap"]
- [:div.headerlinks
- (ph/link-to {:style "border-right: 1px solid #DDD;"} "/pastes" "Latest")
- (ph/link-to {:style "margin-left: 10px;"} "http://blog.refheap.com" "Blog")
- [:div#useri (logged-in nil)]]]
- [:div#content
- [:div#container content]
- [:div#footer
- [:p.centered
- (ph/link-to "https://github.com/Raynes/refheap" "Refheap")
- " is powered by " (ph/link-to "http://clojure.org" "Clojure") ", "
- (ph/link-to "http://webnoir.org" "Noir") ", "
- (ph/link-to "http://mongodb.org" "MongoDB") ", "
- (ph/link-to "http://pygments.org/" "Pygments")
- ", and "
- (ph/link-to "http://photos.geni.com/p13/45/9a/44/22/5344483904b52482/img_7798_large.jpg" "Iguana") ". Please read: the "
- (ph/link-to "/legal/tos" "terms of service") ", and "
- (ph/link-to "/legal/privacy" "privacy") " policy."]]]]]))
+(def header nil)
(defn page-buttons [base n per page]
[:div.centered
@@ -3,9 +3,9 @@
[refheap.views.common :only [layout logged-in]]
[noir.core :only [defpage]]
[noir.response :only [redirect json]]
- [hiccup.core :only [html]]
- [refheap.views.paste :only [private-checkbox]])
+ [hiccup.core :only [html]])
(:require [refheap.models.login :as login]
+ [stencil.core :as stencil]
[noir.session :as session]))
(defn create-user-page [email]
@@ -39,8 +39,7 @@
(defpage [:post "/user/verify"] {:keys [assertion]}
(when-let [{:keys [email]} (login/verify-assertion assertion)]
(if-let [username (login/user-exists email)]
- (json {:login-html (html (logged-in username))
- :private-html (html (private-checkbox {:private false}))})
+ (json {:login-html (logged-in username)})
(do
(session/flash-put! :email email)
- (json {:chooselogin-html (html (create-user-page email))})))))
+ (json {:chooselogin-html (html (create-user-page email))})))))
View
@@ -6,80 +6,20 @@
(:require [refheap.models.paste :as paste]
[refheap.models.users :as users]
[noir.session :as session]
+ [stencil.core :as stencil]
[hiccup.form-helpers :as fh]
[hiccup.page-helpers :as ph]))
-
-(defn private-checkbox [old]
- (list (fh/check-box :private (:private old))
- (fh/label :private "Private")))
-
(defn create-paste-page [lang & [old]]
- (layout
- [:div#main-container
- [:div#paste-container
- (fh/form-to
- [:post (if old
- (str "/paste/" (:paste-id old) "/edit")
- "/paste/create")]
- [:div#paste-header
- (fh/drop-down "language"
- (sort #(.compareToIgnoreCase % %2)
- (keys paste/lexers))
- (or lang (:language old "Clojure")))
- (private-checkbox old)
- (fh/submit-button (if old "Edit!" "Paste!"))]
- (fh/text-area :paste (:raw-contents old)))]
- [:div#main-right
- (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."])
- [: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: \""
- (ph/link-to "http://refheap.com/paste?lang=Ruby" "http://refheap.com/paste?lang=Ruby") "\""]
- [:p "We have an API! Generate a token "
- (ph/link-to "/api" "here")
- " and find examples in our "
- (ph/link-to "https://github.com/Raynes/refheap/wiki/Documentation:-API" "documentation")
- ". Happy hacking!"]
- [:p "Send feedback, feature requests, and bug reports "
- (ph/link-to "http://github.com/raynes/refheap/issues" "here") "."]]]
- [:div.clear]))
-
-(defn show-paste-page [id]
- (when-let [{:keys [lines private user contents language date fork] :as all} (paste/get-paste id)]
- (layout
- (list
- [:div.floater
- [:div#pasteinfo
- [:span.info language]
- [:span.info "Lines: " lines]
- (when private
- [:span {:class "info private"} "Private"])
- [:span#last.info
- (if fork "Forked by " "Pasted by ")
- (if user
- (let [user (:username (users/get-user-by-id user))]
- (ph/link-to (str "/users/" user) user))
- "anonymous")
- (when fork
- (list
- " from "
- (if-let [paste (:paste-id (paste/get-paste-by-id fork))]
- (ph/link-to (str "/paste/" paste) paste)
- "[deleted]")))
- " on "
- (date-string date)
- [:div#edit
- (ph/link-to (str "/paste/" id "/embed") "embed")
- (ph/link-to (str "/paste/" id "/raw") "raw")
- (ph/link-to (str "/paste/" id "/fullscreen") "maximize")
- (when-not (= user (:id (session/get :user)))
- (ph/link-to (str "/paste/" id "/fork") "fork"))
- (when (and user (= user (:id (session/get :user))))
- (list
- [:a {:href (str "/paste/" id "/edit")} "edit"]
- [:a#delete.evil {:href (str "/paste/" id "/delete")} "delete"]))]]]
- [:div#paste.syntax
- contents]]
- [:div.clear]))))
+ (stencil/render-file
+ "refheap/views/templates/paste"
+ {:url (if old
+ (str "/paste/" (:paste-id old) "/edit")
+ "/paste/create")
+ :languages (for [lang (sort #(.compareToIgnoreCase % %2)
+ (keys (dissoc paste/lexers "Clojure")))]
+ {:language lang})
+ :old (:raw-contents old)}))
(defn fullscreen-paste [id]
(when-let [contents (:contents (paste/get-paste id))]
@@ -88,6 +28,25 @@
[:body#fullscreen
[:div.syntax contents]])))
+(defn show-paste-page [id]
+ (when-let [{:keys [lines private user contents language date fork]
+ :as all}
+ (paste/get-paste id)]
+ (stencil/render-file
+ "refheap/views/templates/pasted"
+ {:language language
+ :lines lines
+ :id id
+ :username (if user
+ (let [user (:username (users/get-user-by-id user))]
+ (str "<a href=\"/users/" user "\">" user "</a>"))
+ "anonymous")
+ :date (date-string date)
+ :forked (when fork {:from (if-let [paste (:paste-id (paste/get-paste-by-id fork))]
+ (str "<a href=\"/paste/" paste "\">" paste "</a>")
+ "[deleted]")})
+ :contents contents})))
+
(defpage "/paste/:id/fullscreen" {:keys [id]}
(fullscreen-paste id))
@@ -138,7 +97,7 @@
[:p.error error]))
(defpage "/paste" {:keys [lang]}
- (create-paste-page lang))
+ (layout (create-paste-page lang)))
(defpage "/paste/:id/edit" {:keys [id]}
(let [paste (paste/get-paste id)]
@@ -188,7 +147,7 @@
(fail paste))))
(defpage "/paste/:id" {:keys [id]}
- (show-paste-page id))
+ (layout (show-paste-page id)))
(defpage "/pastes" {:keys [page]}
- (all-pastes-page (paste/proper-page (Long. (or page "1")))))
+ (all-pastes-page (paste/proper-page (Long. (or page "1")))))
@@ -0,0 +1,58 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>RefHeap</title>
+ <link href="/img/favicon.ico" rel="shortcut icon" />
+ <link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet" type="text/css" />
+ <link href="/css/refheap.css" rel="stylesheet" type="text/css" />
+ <link href="/css/tomorrow-night-bright.css" rel="stylesheet" type="text/css" />
+ <link href="/css/chosen.css" rel="stylesheet" type="text/css" />
+
+ <script src="/js/jquery-1.7.1.min.js" type="text/javascript"></script>
+ <script src="https://browserid.org/include.js" type="text/javascript"></script>
+ <script src="/js/chosen.jquery.min.js" type="text/javascript"></script>
+ <script src="/js/refheap.js" type="text/javascript"></script>
+ <script type="text/javascript">//<![CDATA[
+ var _gaq = _gaq || [];
+ _gaq.push(['_setAccount', 'UA-28074244-1']);
+ _gaq.push(['_trackPageview']);
+
+ (function() {
+ var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
+ ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
+ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
+ })();
+ //]]>
+ </script>
+ </head>
+
+ <body>
+ <div id="site-container">
+ <div id="header">
+ <a id="site" href="/paste">The Reference Heap</a>
+ <div class="headerlinks">
+ <div id="starting">
+ <a class="borderedbutton" href="/pastes">Latest</a>
+ <a class="borderedbutton" href="http://blog.refheap.com">Blog</a>
+ </div>
+ <div id="useri">
+ {{{user}}}
+ </div>
+ </div>
+ </div>
+ <div id="content">
+ <div id="container" class="clearfix">
+ {{{content}}}
+ </div>
+ <div id="footer">
+ <p class="centered">
+ <a href="https://github.com/Raynes/refheap">RefHeap</a> is powered by
+ <a href="http://clojure.org">Clojure</a>, <a href="http://webnoir.org">Noir</a>,
+ <a href="http://mongodb.org">MongoDB</a>, and <a href="http://pygments.org">Pygments</a>.
+ Please read our <a href="/legal/tos">terms of service</a> and
+ <a href="/legal/privacy">privacy policy</a>.
+ </div>
+ </div>
+ </div>
+ </body>
+</html>
@@ -0,0 +1,9 @@
+{{#user}}
+<div>
+ <a id="userbutton" href="/users/{{username}}">{{username}}</a>
+ <a href="/users/logout">logout</a>
+</div>
+{{/user}}
+{{^user}}
+<img id="signin" class="imgbutton" src="/img/browserid.png" alt="BrowserID">
+{{/user}}
Oops, something went wrong.

0 comments on commit 2596ce1

Please sign in to comment.