Skip to content

Commit

Permalink
ビュー用に新しいネームスペースを作って、文字列で書いていた HTML を
Browse files Browse the repository at this point in the history
Hiccup を 使って書きなおした
  • Loading branch information
ayato-p committed Nov 23, 2015
1 parent 75cf9b1 commit 9093b10
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
9 changes: 3 additions & 6 deletions todo-clj/src/todo_clj/handler/main.clj
@@ -1,14 +1,11 @@
(ns todo-clj.handler.main
(:require [compojure.core :refer [defroutes GET]]
[compojure.route :as route]
[todo-clj.util.response :as res]))

(defn home-view [req]
"<h1>ホーム画面</h1>
<a href=\"/todo\">TODO 一覧</a>")
[todo-clj.util.response :as res]
[todo-clj.view.main :as view]))

(defn home [req]
(-> (home-view req)
(-> (view/home-view req)
res/response
res/html))

Expand Down
12 changes: 3 additions & 9 deletions todo-clj/src/todo_clj/handler/todo.clj
@@ -1,22 +1,16 @@
(ns todo-clj.handler.todo
(:require [compojure.core :refer [defroutes context GET POST]]
[todo-clj.util.response :as res]))
[todo-clj.util.response :as res]
[todo-clj.view.todo :as view]))

(def todo-list
[{:title "朝ごはんを作る"}
{:title "燃えるゴミを出す"}
{:title "卵を買って帰る"}
{:title "お風呂を洗う"}])

(defn todo-index-view [req]
`("<h1>TODO 一覧</h1>"
"<ul>"
~@(for [{:keys [title]} todo-list]
(str "<li>" title "</li>"))
"</ul>"))

(defn todo-index [req]
(-> (todo-index-view req)
(-> (view/todo-index-view req todo-list)
res/response
res/html))

Expand Down
8 changes: 8 additions & 0 deletions todo-clj/src/todo_clj/view/main.clj
@@ -0,0 +1,8 @@
(ns todo-clj.view.main
(:require [hiccup.core :as hc]))

(defn home-view [req]
(-> (list
[:h1 "ホーム画面"]
[:a {:href "/todo"} "TODO 一覧"])
hc/html))
9 changes: 9 additions & 0 deletions todo-clj/src/todo_clj/view/todo.clj
@@ -0,0 +1,9 @@
(ns todo-clj.view.todo
(:require [hiccup.core :as hc]))

(defn todo-index-view [req todo-list]
(-> `([:h1 "TODO 一覧"]
[:ul
~@(for [{:keys [title]} todo-list]
[:li title])])
hc/html))

0 comments on commit 9093b10

Please sign in to comment.