瀏覽代碼

Add a simple view for the full list, serve api on different url.

Lucas Stadler 13 年之前
父節點
當前提交
c7b1641aee
共有 2 個文件被更改,包括 34 次插入3 次删除
  1. 2 1
      clj/project.clj
  2. 32 2
      clj/shame.clj

+ 2 - 1
clj/project.clj

@ -3,7 +3,8 @@
3 3
  :dependencies [[org.clojure/clojure "1.4.0"]
4 4
                 [org.clojure/data.json "0.2.1"]
5 5
                 [compojure "1.1.5"]
6
                 [ring-middleware-format "0.2.4"]]
6
                 [ring-middleware-format "0.2.4"]
7
                 [hiccup "1.0.2"]]
7 8
  :plugins [[lein-ring "0.8.2"]]
8 9
  :ring {:handler shame/serve}
9 10
  :source-paths ["."])

+ 32 - 2
clj/shame.clj

@ -7,7 +7,8 @@
7 7
  (:use ring.middleware.reload)
8 8
  (:use ring.middleware.stacktrace)
9 9
  (:use [ring.middleware.format-response :only [wrap-restful-response]])
10
  (:use [ring.middleware.format-params :only [wrap-restful-params]]))
10
  (:use [ring.middleware.format-params :only [wrap-restful-params]])
11
  (:use hiccup.core))
11 12
12 13
13 14
; roadmap:
@ -93,7 +94,7 @@
93 94
                %1)
94 95
             {} map))
95 96
96
(defroutes shame-routes
97
(defroutes shame-api
97 98
  (GET "/" [] (response @*shaming*))
98 99
  (POST "/" [item] (dosync (ref-set *shaming*
99 100
                                      (add-item item @*shaming*))))
@ -113,6 +114,35 @@
113 114
                           (close-item item-name (or status "failed") @*shaming*))))
114 115
  (route/not-found "404 - Alternate Reality Monsters"))
115 116
117
(defn render-item [item]
118
  [:div.shame.current
119
   [:h2 (:name item)]
120
   (when (count (:notes item))
121
     [:ul (for [note (:notes item)]
122
            [:li (if (string? note)
123
                   note
124
                   (:content note))])])])
125
126
(defn shame-index []
127
  (html
128
    (let [title (str "shame on me, I'm " (count (:current @*shaming*)) " things behind!")]
129
      [:html
130
       [:head
131
        [:title title]
132
        [:style {:rel "stylesheet", :href "todo.css"}]]
133
       [:body
134
        [:h1 title]
135
        (for [item (:current @*shaming*)]
136
          (render-item item))]])))
137
138
(defroutes shame-routes
139
  (context "/todos" [] shame-api)
140
  (GET "/" []
141
       (content-type
142
         (response (shame-index))
143
         "text/html"))
144
  (route/not-found "404 - Alternate Reality Monsters (in App)"))
145
116 146
(def serve
117 147
  (-> (handler/site shame-routes)
118 148
    (wrap-reload {:dirs ["."]})