From 7ae057ca13241bce1a15565bc784442f27f421ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20M=C3=BCller?= Date: Sat, 4 Oct 2014 09:08:33 +0200 Subject: [PATCH] refactoring: api usage eliminated from views --- src/notehub/handler.clj | 16 +++++++------ src/notehub/views.clj | 50 +++++++++++++++++------------------------ 2 files changed, 30 insertions(+), 36 deletions(-) diff --git a/src/notehub/handler.clj b/src/notehub/handler.clj index f8ce87a..ff72417 100644 --- a/src/notehub/handler.clj +++ b/src/notehub/handler.clj @@ -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] diff --git a/src/notehub/views.clj b/src/notehub/views.clj index abd1055..9d6f466 100644 --- a/src/notehub/views.clj +++ b/src/notehub/views.clj @@ -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 - (html (hidden-field :noteID note-id)) - (:note (api/get-note {:noteID note-id})) :enter-passwd))) +(defn note-update-page [note-id note] + (input-form "/update-note" + :update + (html (hidden-field :noteID note-id)) + 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))] - (layout :no-js (:title note) - [:article.bottom-space (md-to-html sanitized-note)] - (let [urls {:short-url (api/url short-url) - :notehub "/"} - links (map #(link-to - (if (urls %) - (urls %) - (str (:longURL note) "/" (name %))) - (get-message %)) - [:notehub :stats :edit :export :short-url]) - links (interpose [:span.middot "·"] links)] - [:div#footer links])))) +(defn note-page [note short-url] + (layout :no-js (:title note) + [:article.bottom-space (md-to-html (sanitize (:note note)))] + (let [urls {:short-url short-url + :notehub "/"} + links (map #(link-to + (urls % (str (:longURL note) "/" (name %))) + (get-message %)) + [:notehub :stats :edit :export :short-url])] + [:div#footer (interpose [:span.middot "·"] links)])))