/
parts.clj
86 lines (76 loc) · 2.61 KB
/
parts.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
(ns ashikasoft.webstack.view.parts
(:require
[ashikasoft.webstack.util.json :as json]
[ashikasoft.webstack.form :as form]
[hiccup.core :as hc]
[hiccup.page :as page])
(:import
org.apache.commons.text.StringEscapeUtils))
(defn js-script [& contents]
[:script {:type "text/javascript"}
(apply str contents)])
(defn js-var [name value]
(str "var " name " = " value ";"))
(defn js-quot [value]
(str "'" value "'"))
(defn js-dquot [value]
(str \" value \"))
(defn escape-json [data]
(StringEscapeUtils/escapeJson data))
(defn js-transit-var [name value]
(js-script
(js-var name (-> value json/write-utf8 escape-json js-dquot))))
(defn main [glossary headitems content]
(page/html5
[:head
[:meta {:http-equiv "Content-Type" :content "text/html; charset=UTF-8"}]
[:meta {:name "viewport" :content "width=device-width, initial-scale=1.0"}]
[:link {:rel "shortcut icon" :type "image/png" :href "/img/favicon.png"}]
[:title (:title glossary)]
(page/include-css
"/css/screen.css"
"/assets/bootstrap/css/bootstrap.min.css"
"/assets/font-awesome/css/font-awesome.min.css")
(page/include-js
"/assets/jquery/jquery.min.js"
"/assets/bootstrap/js/bootstrap.min.js")
headitems]
[:body content]))
(defn appbase [{:keys [glossary servlet-context csrf-token]} headitems content]
(page/html5
[:head
[:meta {:charset "UTF-8"}]
[:meta {:http-equiv "Content-Type" :content "text/html; charset=UTF-8"}]
[:meta {:name "viewport" :content "width=device-width, initial-scale=1.0"}]
[:link {:rel "shortcut icon" :type "image/png" :href "/img/favicon.png"}]
[:title (:title glossary)]
(page/include-css
"/css/screen.css"
"/assets/bootstrap/css/bootstrap.min.css"
"/assets/font-awesome/css/font-awesome.min.css"
"/css/main.css")
(page/include-js
"/assets/jquery/jquery.min.js"
"/assets/bootstrap/js/bootstrap.min.js")
(js-script
(js-var "csrfToken" (js-quot csrf-token)))
headitems]
[:body
[:div#app
[:div.container
[:div.three-quarters-loader "Loading… (uses javascript)"]
(or
content
[:noscript
[:p "This page uses javascript, but it seems to be disabled. Please enable it and reload."]])]]]))
(defn spa-appbase [view-data init-state app-js]
(appbase
view-data
(js-transit-var
"transitState"
init-state)
(list
(page/include-js "/js/app.js")
[:script
{:type "text/javascript"}
(str app-js ";")])))