Skip to content

Commit 072f119

Browse files
committed
section8 video3
1 parent e5fbe42 commit 072f119

File tree

4 files changed

+37
-14
lines changed

4 files changed

+37
-14
lines changed

project.clj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
[cheshire "5.1.1"]
1818
[ring "1.2.0"]
1919
[compojure "1.1.6"]
20-
[hiccup "1.0.4"]]
20+
[hiccup "1.0.4"]
21+
[enlive "1.1.5"]]
2122
:cljsbuild {:builds [{:source-paths ["cljs"]
2223
:compiler {:output-to "resources/public/app.js"}}]})
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<p>Params:</p>
2+
<pre id="params"/>
3+
<p>Query string params:</p>
4+
<pre id="query-params"/>
5+
<p>Form params:</p>
6+
<pre id="form-params"/>
7+
<p>Multipart params:</p>
8+
<pre id="multipart-params"/>

resources/templates/layout.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!DOCTYPE html>
2+
3+
<html>
4+
<head>
5+
<title></title>
6+
</head>
7+
<body style="background-color: #2c3e50; color: #fff">
8+
</body>
9+
</html>

src/project1/core.clj

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,22 @@
1313
[core :as hiccup]
1414
[page :as page]
1515
[util]]
16+
[net.cgrand.enlive-html :as enlive]
1617
[project1.route :as route]
1718
[project1.blog :as blog]
1819
[clojure.string]))
1920

21+
(enlive/deftemplate layout-template "templates/layout.html"
22+
[contents]
23+
[:body] (enlive/html-content (apply str contents)))
24+
25+
(enlive/deftemplate form-handler-template "templates/form-handler.html"
26+
[params query-params form-params multipart-params]
27+
[:pre#params] (enlive/content (str params))
28+
[:pre#query-params] (enlive/content (str query-params))
29+
[:pre#form-params] (enlive/content (str form-params))
30+
[:pre#multipart-params] (enlive/content (str multipart-params)))
31+
2032
(defn layout [contents]
2133
(page/html5
2234
[:body {:style "background-color: #363636; color: #fff;"}
@@ -93,19 +105,12 @@
93105
:cookies {:username login}
94106
:session {:username login
95107
:cnt (inc (or (:cnt (:session request)) 0))}
96-
:body (layout
97-
[:div
98-
[:p "Params:"]
99-
[:pre (hiccup.util/escape-html (:params request))]
100-
[:p "Query string params:"]
101-
[:pre (hiccup.util/escape-html (:query-params request))]
102-
[:p "Form params:"]
103-
[:pre (hiccup.util/escape-html (:form-params request))]
104-
[:p "Multipart params:"]
105-
[:pre (hiccup.util/escape-html (:multipart-params request))]
106-
[:p "Local path:"]
107-
[:b (when-let [f (get-in request [:params :file :tempfile])]
108-
(hiccup.util/escape-html (.getAbsolutePath f)))]])})
108+
:body (apply str (layout-template
109+
(form-handler-template
110+
(:params request)
111+
(:query-params request)
112+
(:form-params request)
113+
(:multipart-params request))))})
109114

110115
(compojure/defroutes route-handler
111116
(compojure/context "/entries" []

0 commit comments

Comments
 (0)