Browse Source

refactoring

master
Christian Mueller 14 years ago
parent
commit
ca9f044182
  1. 6
      messages
  2. 40
      src/NoteHub/views/pages.clj

6
messages

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
title = Free and Hassle-free Markdown Hosting.
title = Free and Hassle-free Hosting for Markdown Pages.
name = NoteHub
new-page = New Page
@ -6,10 +6,10 @@ column-why = Why? @@ -6,10 +6,10 @@ column-why = Why?
column-why-long = Not every person, who occasionally wants to express some thoughts, needs a blog. Blogs are __tedious__ for writers and for readers. Most people are not interested in thoughts of other random people. Moreover, nowadays everything rotates around social networks and not individual blogs. It makes much more sense to publish something somewhere and to share the link with the audience on the community or social network of your choice, than to maintain a blog trying to keep your readers interested. __NoteHub__ should be the place, where you can publish your thoughts without hassle.
column-how = How to Use?
column-how-long = First [create](/new) a new page using the [Markdown](http://daringfireball.net/projects/markdown/) syntax. Now, besides just sharing the link, you can view some rudimentary statistics by appending `/stats` to the note url: <pre>notehub.org/.../title/stats</pre> If you want to export a note in the original Markdown format, append `/export`: <pre>notehub.org/.../title/export</pre> You also can invert the color scheme by appending `?theme=dark` to the note url: <pre>notehub.org/.../title?theme=dark</pre>
column-how-long = First [create](/new) a new page using the [Markdown](http://daringfireball.net/projects/markdown/) syntax. Besides just sharing the link, you can view some rudimentary statistics by appending `/stats` to the note url: <pre>notehub.org/.../title/stats</pre> If you want to export a note in the original Markdown format, append `/export`: <pre>notehub.org/.../title/export</pre> You also can invert the color scheme by appending `?theme=dark` to the note url: <pre>notehub.org/.../title?theme=dark</pre>
column-geeks = For Geeks!
column-geeks-long = NoteHub was an one-app-one-language experiment and is implemented entirely in [Clojure](http://clojure.org) and ClojureScript. Its [source code](https://github.com/chmllr/NoteHub) can be found on GitHub. Look at the code to find some undocumented NoteHub features (or bugs) and &mdash; feel free to contribute! (If you are interested in more detailed code overview, read [this note](http://notehub.org).) NoteHub's design is intentionally kept extremelly simple and minimalistic, and should stay like this. NoteHub's persistence layer bases on the key-value store [redis](http://redis.io). Currently, NoteHub is hosted for free on [Heroku](http://heroku.com). Send your feedback and comments directly to [@chmllr](http://twitter.com/chmllr) or [open an issue](https://github.com/chmllr/NoteHub/issues) on GitHub.
column-geeks-long = NoteHub was an one-app-one-language experiment and is implemented entirely in [Clojure](http://clojure.org) and ClojureScript. The [source code](https://github.com/chmllr/NoteHub) can be found on GitHub. Look at the code to find some undocumented NoteHub features (or bugs) and &mdash; feel free to contribute! If you are interested in more detailed code overview, read [this](http://notehub.org) note. NoteHub's design is kept intentionally extremelly simple and minimalistic, and should stay so. NoteHub's persistence layer bases on the key-value store [redis](http://redis.io). Currently, NoteHub is hosted for free on [Heroku](http://heroku.com). Send your feedback and comments directly to [@chmllr](http://twitter.com/chmllr) or open an [issue](https://github.com/chmllr/NoteHub/issues) on GitHub.
status-404 = Nothing found.
status-400 = Bad Request.

40
src/NoteHub/views/pages.clj

@ -8,6 +8,7 @@ @@ -8,6 +8,7 @@
[clojure.string :rename {replace sreplace} :only [split replace lower-case]]
[clojure.core.incubator :only [-?>]]
[hiccup.form]
[hiccup.page]
[noir.session :only [flash-put! flash-get]]
[noir.response :only [redirect status]]
[noir.core :only [defpage render]]
@ -28,13 +29,6 @@ @@ -28,13 +29,6 @@
(do (flash-put! k true)
(print-str k))))
; Converts given markdwon to html and wraps with layout
(defn- wrap [params md-text]
(if md-text
(let [title (-?> md-text (split #"\n") first (sreplace #"[_\*#]" ""))]
(layout params title [:article (md-to-html md-text)]))
(status 404 (get-page 404))))
; Sets a custom message for each corresponding HTTP status
(doseq [code [400 404 500]]
(set-page! code
@ -42,6 +36,17 @@ @@ -42,6 +36,17 @@
(layout message
[:article [:h1 message]]))))
; shortcut for rendering an HTTP status
(defn- response [code]
(status code (get-page code)))
; Converts given markdwon to html and wraps with layout
(defn- wrap [params md-text]
(if md-text
(let [title (-?> md-text (split #"\n") first (sreplace #"[_\*#]" ""))]
(layout params title [:article (md-to-html md-text)]))
(status 404 (get-page 404))))
; Routes
; ======
@ -63,12 +68,10 @@ @@ -63,12 +68,10 @@
[:div.dashed-line]
[:table.central-element.helvetica-neue
[:tr
[:td.one-third-column
[:h2 (get-message :column-why)] (md-to-html (get-message :column-why-long))]
[:td.one-third-column
[:h2 (get-message :column-how)] (md-to-html (get-message :column-how-long))]
[:td.one-third-column
[:h2 (get-message :column-geeks)] (md-to-html (get-message :column-geeks-long))]]]
(for [e [:column-why :column-how :column-geeks]]
(html5
[:td.one-third-column
[:h2 (get-message e)] (md-to-html (get-message (keyword (str (name e) "-long"))))]))]]
[:div.centered.helvetica-neue (md-to-html (get-message :created-by))]))
; New Note Page
@ -97,22 +100,21 @@ @@ -97,22 +100,21 @@
; Provides Markdown of the specified note
(defpage "/:year/:month/:day/:title/export" {:keys [year month day title]}
(let [md-text (get-note [year month day] title)]
(if md-text md-text (status 404 (get-page 404)))))
(if md-text md-text (response 404))))
; Provides the number of views of the specified note
(defpage "/:year/:month/:day/:title/stat" {:keys [year month day title]}
(let [views (get-views [year month day] title)]
(if views
(layout (get-message :statistics)
[:article.helvetica-neue
[:table {:style "width: 100%"}
[:table.helvetica-neue.central-element
[:tr
[:td (get-message :published)]
[:td (interpose "-" [year month day])]]
[:tr
[:td (get-message :article-views)]
[:td views]]]])
(status 404 (get-page 404)))))
[:td views]]])
(response 404))))
; New Note Posting
(defpage [:post "/post-note"] {:keys [draft session-key session-value]}
@ -140,4 +142,4 @@ @@ -140,4 +142,4 @@
(set-note date title draft)
; TODO: the redirect is broken if title contains UTF chars
(redirect (apply str (interpose "/" ["" year month day title])))))
(status 400 ""))))
(response 400))))

Loading…
Cancel
Save