all note routes activated
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
# starts the app in :dev mode
|
# starts the app in :dev mode
|
||||||
run:
|
run:
|
||||||
@DEVMODE=1 lein ring server
|
@DEVMODE=1 lein ring server 8080
|
||||||
|
|
||||||
server:
|
server:
|
||||||
redis-server &
|
redis-server &
|
||||||
|
|||||||
+42
-40
@@ -104,45 +104,6 @@
|
|||||||
; Routes
|
; Routes
|
||||||
; ======
|
; ======
|
||||||
|
|
||||||
(defpage "/" {}
|
|
||||||
(layout (get-message :page-title)
|
|
||||||
[:div#hero
|
|
||||||
[:h1 (get-message :name)]
|
|
||||||
[:h2 (get-message :title)]
|
|
||||||
[:br]
|
|
||||||
[:a.landing-button {:href "/new" :style "color: white"} (get-message :new-page)]]
|
|
||||||
[:div#dashed-line]
|
|
||||||
(md-node :article.helvetica.bottom-space
|
|
||||||
{:style "font-size: 1em"}
|
|
||||||
(slurp "LANDING.md"))
|
|
||||||
(md-node :div.centered.helvetica (get-message :footer))))
|
|
||||||
|
|
||||||
(defpage "/:year/:month/:day/:title/export" {:keys [year month day title]}
|
|
||||||
(when-let [md-text (:note (api/get-note (api/build-key [year month day] title)))]
|
|
||||||
(content-type "text/plain; charset=utf-8" md-text)))
|
|
||||||
|
|
||||||
(defpage "/:year/:month/:day/:title/stats" {:keys [year month day title]}
|
|
||||||
(when-let [stats (:statistics (api/get-note (api/build-key [year month day] title)))]
|
|
||||||
(layout (get-message :statistics)
|
|
||||||
[:table#stats.helvetica.central-element
|
|
||||||
(map
|
|
||||||
#(when (% stats)
|
|
||||||
[:tr [:td (str (get-message %) ":")] [:td (% stats)]])
|
|
||||||
[:published :edited :publisher :views])])))
|
|
||||||
|
|
||||||
|
|
||||||
(defpage "/:year/:month/:day/:title/edit" {:keys [year month day title]}
|
|
||||||
(let [noteID (api/build-key [year month day] title)]
|
|
||||||
(input-form "/update-note" :update
|
|
||||||
(html (hidden-field :noteID noteID))
|
|
||||||
(:note (api/get-note noteID)) :enter-passwd)))
|
|
||||||
|
|
||||||
(defpage "/new" {}
|
|
||||||
(input-form "/post-note" :publish
|
|
||||||
(html (hidden-field :session (storage/create-session))
|
|
||||||
(hidden-field {:id :signature} :signature))
|
|
||||||
(get-message :loading) :set-passwd))
|
|
||||||
|
|
||||||
(defpage [:post "/post-note"] {:keys [session note signature password version]}
|
(defpage [:post "/post-note"] {:keys [session note signature password version]}
|
||||||
(if (= signature (api/get-signature session note))
|
(if (= signature (api/get-signature session note))
|
||||||
(let [pid "NoteHub"
|
(let [pid "NoteHub"
|
||||||
@@ -177,6 +138,10 @@
|
|||||||
:headers {"Location" (str url)}
|
:headers {"Location" (str url)}
|
||||||
:body ""})
|
:body ""})
|
||||||
|
|
||||||
|
(defn return-content-type [ctype content]
|
||||||
|
{:headers {"Content-Type" ctype}
|
||||||
|
:body content})
|
||||||
|
|
||||||
(defroutes api-routes
|
(defroutes api-routes
|
||||||
|
|
||||||
(GET "/" [] (layout (get-message :api-title)
|
(GET "/" [] (layout (get-message :api-title)
|
||||||
@@ -199,7 +164,44 @@
|
|||||||
|
|
||||||
(defroutes app-routes
|
(defroutes app-routes
|
||||||
(context "/api" [] api-routes)
|
(context "/api" [] api-routes)
|
||||||
(GET "/" [] "Hello World")
|
|
||||||
|
(GET "/" []
|
||||||
|
(layout (get-message :page-title)
|
||||||
|
[:div#hero
|
||||||
|
[:h1 (get-message :name)]
|
||||||
|
[:h2 (get-message :title)]
|
||||||
|
[:br]
|
||||||
|
[:a.landing-button {:href "/new" :style "color: white"} (get-message :new-page)]]
|
||||||
|
[:div#dashed-line]
|
||||||
|
(md-node :article.helvetica.bottom-space
|
||||||
|
{:style "font-size: 1em"}
|
||||||
|
(slurp "LANDING.md"))
|
||||||
|
(md-node :div.centered.helvetica (get-message :footer))))
|
||||||
|
|
||||||
|
(GET "/:year/:month/:day/:title/export" [year month day title]
|
||||||
|
(when-let [md-text (:note (api/get-note (api/build-key [year month day] title)))]
|
||||||
|
(return-content-type "text/plain; charset=utf-8" md-text)))
|
||||||
|
|
||||||
|
(GET "/:year/:month/:day/:title/stats" [year month day title]
|
||||||
|
(when-let [stats (:statistics (api/get-note (api/build-key [year month day] title)))]
|
||||||
|
(layout (get-message :statistics)
|
||||||
|
[:table#stats.helvetica.central-element
|
||||||
|
(map
|
||||||
|
#(when (% stats)
|
||||||
|
[:tr [:td (str (get-message %) ":")] [:td (% stats)]])
|
||||||
|
[:published :edited :publisher :views])])))
|
||||||
|
|
||||||
|
(GET "/:year/:month/:day/:title/edit" [year month day title]
|
||||||
|
(let [noteID (api/build-key [year month day] title)]
|
||||||
|
(input-form "/update-note" :update
|
||||||
|
(html (hidden-field :noteID noteID))
|
||||||
|
(:note (api/get-note noteID)) :enter-passwd)))
|
||||||
|
|
||||||
|
(GET "/new" []
|
||||||
|
(input-form "/post-note" :publish
|
||||||
|
(html (hidden-field :session (storage/create-session))
|
||||||
|
(hidden-field {:id :signature} :signature))
|
||||||
|
(get-message :loading) :set-passwd))
|
||||||
|
|
||||||
(GET "/:year/:month/:day/:title" [year month day title :as params]
|
(GET "/:year/:month/:day/:title" [year month day title :as params]
|
||||||
(let [params (assoc (:query-params params)
|
(let [params (assoc (:query-params params)
|
||||||
|
|||||||
@@ -3,6 +3,12 @@
|
|||||||
ring.mock.request
|
ring.mock.request
|
||||||
notehub.handler))
|
notehub.handler))
|
||||||
|
|
||||||
|
(defn substring? [a b] (not (= nil (re-matches (re-pattern (str "(?s).*" a ".*")) b))))
|
||||||
|
(def date [2012 6 3])
|
||||||
|
(def test-title "some-title")
|
||||||
|
(def test-note "# This is a test note.\nHello _world_. Motörhead, тест.")
|
||||||
|
|
||||||
|
|
||||||
#_(
|
#_(
|
||||||
|
|
||||||
(ns NoteHub.test.views.pages
|
(ns NoteHub.test.views.pages
|
||||||
@@ -12,10 +18,6 @@
|
|||||||
[NoteHub.storage]
|
[NoteHub.storage]
|
||||||
[clojure.test]))
|
[clojure.test]))
|
||||||
|
|
||||||
(defn substring? [a b] (not (= nil (re-matches (re-pattern (str "(?s).*" a ".*")) b))))
|
|
||||||
(def date [2012 6 3])
|
|
||||||
(def test-title "some-title")
|
|
||||||
(def test-note "# This is a test note.\nHello _world_. Motörhead, тест.")
|
|
||||||
|
|
||||||
(defn create-testnote-fixture [f]
|
(defn create-testnote-fixture [f]
|
||||||
(add-note (build-key date test-title) test-note "testPID")
|
(add-note (build-key date test-title) test-note "testPID")
|
||||||
@@ -133,7 +135,7 @@
|
|||||||
(testing "main route"
|
(testing "main route"
|
||||||
(let [response (app (request :get "/"))]
|
(let [response (app (request :get "/"))]
|
||||||
(is (= (:status response) 200))
|
(is (= (:status response) 200))
|
||||||
(is (= (:body response) "Hello World"))))
|
(is (substring? "free and hassle-free" (:body response)))))
|
||||||
|
|
||||||
(testing "not-found route"
|
(testing "not-found route"
|
||||||
(let [response (app (request :get "/invalid"))]
|
(let [response (app (request :get "/invalid"))]
|
||||||
|
|||||||
Reference in New Issue
Block a user