refactoring: api usage eliminated from views
This commit is contained in:
@@ -64,14 +64,15 @@
|
||||
(return-content-type "text/plain; charset=utf-8" md-text)))
|
||||
|
||||
(GET "/:year/:month/:day/:title/stats" [year month day title]
|
||||
(let [note-id (api/build-key year month day title)
|
||||
resp {:statistics (storage/get-note-statistics note-id)
|
||||
:note (storage/get-note note-id)
|
||||
:noteID note-id}]
|
||||
(statistics-page resp)))
|
||||
(let [note-id (api/build-key year month day title)]
|
||||
(statistics-page (api/derive-title (storage/get-note note-id))
|
||||
(storage/get-note-statistics note-id))))
|
||||
|
||||
(GET "/:year/:month/:day/:title/edit" [year month day title]
|
||||
(note-update-page year month day title))
|
||||
(let [note-id (api/build-key year month day title)]
|
||||
(note-update-page
|
||||
note-id
|
||||
(:note (api/get-note {:noteID note-id})))))
|
||||
|
||||
(GET "/new" [] (new-note-page
|
||||
(str
|
||||
@@ -89,7 +90,8 @@
|
||||
(swap! C cache/hit short-url)
|
||||
(storage/increment-note-view note-id))
|
||||
(swap! C cache/miss short-url
|
||||
(note-page note-id short-url)))
|
||||
(note-page (api/get-note {:noteID note-id})
|
||||
(api/url short-url))))
|
||||
(cache/lookup @C short-url))))
|
||||
|
||||
(GET "/:short-url" [short-url]
|
||||
|
||||
+16
-24
@@ -7,8 +7,6 @@
|
||||
[hiccup.element]
|
||||
[hiccup.util :only [escape-html]]
|
||||
[hiccup.page :only [include-js html5]])
|
||||
(:require
|
||||
[notehub.api :as api])
|
||||
(:import (org.pegdown PegDownProcessor Extensions)))
|
||||
|
||||
(def get-message (get-map "messages"))
|
||||
@@ -52,7 +50,6 @@
|
||||
[:div.central-element.helvetica {:style "margin-bottom: 3em"}
|
||||
(form-to {:autocomplete :off} [:post form-url]
|
||||
(hidden-field :action command)
|
||||
(hidden-field :version api/version)
|
||||
(hidden-field :password)
|
||||
fields
|
||||
(text-area {:class :max-width} :note content)
|
||||
@@ -76,12 +73,11 @@
|
||||
[:div#footer (md-to-html (get-message :footer))]))
|
||||
|
||||
|
||||
(defn statistics-page [resp]
|
||||
(let [stats (:statistics resp)
|
||||
title (get-message :statistics)]
|
||||
(layout :no-js title
|
||||
[:h2.central-element (api/derive-title (:note resp))]
|
||||
[:h3.central-element.helvetica title]
|
||||
(defn statistics-page [note-title stats]
|
||||
(let [page-title (get-message :statistics)]
|
||||
(layout :no-js page-title
|
||||
[:h2.central-element note-title]
|
||||
[:h3.central-element.helvetica page-title]
|
||||
[:table#stats.helvetica.central-element
|
||||
(map
|
||||
#(when-let [v (% stats)]
|
||||
@@ -91,11 +87,12 @@
|
||||
(str (java.util.Date. (Long/parseLong v))) v)]])
|
||||
[:published :edited :publisher :views])])))
|
||||
|
||||
(defn note-update-page [year month day title]
|
||||
(let [note-id (api/build-key year month day title)]
|
||||
(input-form "/update-note" :update
|
||||
(defn note-update-page [note-id note]
|
||||
(input-form "/update-note"
|
||||
:update
|
||||
(html (hidden-field :noteID note-id))
|
||||
(:note (api/get-note {:noteID note-id})) :enter-passwd)))
|
||||
note
|
||||
:enter-passwd))
|
||||
|
||||
(defn new-note-page [session]
|
||||
(input-form "/post-note" :publish
|
||||
@@ -103,18 +100,13 @@
|
||||
(hidden-field {:id :signature} :signature))
|
||||
(get-message :loading) :set-passwd))
|
||||
|
||||
(defn note-page [note-id short-url]
|
||||
(let [note (api/get-note {:noteID note-id})
|
||||
sanitized-note (sanitize (:note note))]
|
||||
(defn note-page [note short-url]
|
||||
(layout :no-js (:title note)
|
||||
[:article.bottom-space (md-to-html sanitized-note)]
|
||||
(let [urls {:short-url (api/url short-url)
|
||||
[:article.bottom-space (md-to-html (sanitize (:note note)))]
|
||||
(let [urls {:short-url short-url
|
||||
:notehub "/"}
|
||||
links (map #(link-to
|
||||
(if (urls %)
|
||||
(urls %)
|
||||
(str (:longURL note) "/" (name %)))
|
||||
(urls % (str (:longURL note) "/" (name %)))
|
||||
(get-message %))
|
||||
[:notehub :stats :edit :export :short-url])
|
||||
links (interpose [:span.middot "·"] links)]
|
||||
[:div#footer links]))))
|
||||
[:notehub :stats :edit :export :short-url])]
|
||||
[:div#footer (interpose [:span.middot "·"] links)])))
|
||||
|
||||
Reference in New Issue
Block a user