-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcompact.cirru
199 lines (198 loc) · 8.92 KB
/
compact.cirru
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
{} (:package |app)
:configs $ {} (:init-fn |app.main/main!) (:reload-fn |app.main/reload!) (:version |0.0.1)
:modules $ [] |respo.calcit/ |lilac/ |memof/ |respo-ui.calcit/ |respo-markdown.calcit/ |reel.calcit/
:entries $ {}
:files $ {}
|app.comp.container $ %{} :FileEntry
:defs $ {}
|comp-container $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-container (reel)
let
store $ :store reel
states $ :states store
div
{} $ :style
merge ui/global ui/fullscreen ui/row $ {} (:justify-content :center)
div
{} $ :style
{} (:max-width 800) (:width "\"60%")
:border $ str "\"1px solid " (hsl 0 0 90)
:padding 16
:padding-bottom 200
:overflow :auto
comp-md-block (slurp "\"docs/guide.md")
{} (:class-name "\"markdown-body")
:highlight $ fn (code lang)
if (= lang "\"cirru") (color/generate code)
.-value $ .!highlight hljs code
js-object $ :language lang
when dev? $ comp-reel (>> states :reel) reel ({})
|slurp $ %{} :CodeEntry (:doc |)
:code $ quote
defmacro slurp (path) (read-file path)
:ns $ %{} :CodeEntry (:doc |)
:code $ quote
ns app.comp.container $ :require
[] respo-ui.core :refer $ [] hsl
[] respo-ui.core :as ui
[] respo.core :refer $ [] defcomp >> <> div button textarea span
[] respo.comp.space :refer $ [] =<
[] reel.comp.reel :refer $ [] comp-reel
[] respo-md.comp.md :refer $ [] comp-md
[] app.config :refer $ [] dev?
[] respo-md.comp.md :refer $ [] comp-md-block
[] "\"highlight.js" :default hljs
"\"cirru-color" :as color
|app.config $ %{} :FileEntry
:defs $ {}
|cdn? $ %{} :CodeEntry (:doc |)
:code $ quote
def cdn? $ cond
exists? js/window
, false
(exists? js/process) (= "\"true" js/process.env.cdn)
:else false
|dev? $ %{} :CodeEntry (:doc |)
:code $ quote
def dev? $ = "\"dev" (get-env "\"mode" "\"release")
|site $ %{} :CodeEntry (:doc |)
:code $ quote
def site $ {} (:dev-ui "\"http://localhost:8100/main-fonts.css") (:release-ui "\"http://cdn.tiye.me/favored-fonts/main-fonts.css") (:cdn-url "\"http://cdn.tiye.me/cumulo-org/") (:title "\"Cumulo Home Page") (:icon "\"http://cdn.tiye.me/logo/respo.png") (:storage-key "\"cumulo.org")
:ns $ %{} :CodeEntry (:doc |)
:code $ quote (ns app.config)
|app.main $ %{} :FileEntry
:defs $ {}
|*reel $ %{} :CodeEntry (:doc |)
:code $ quote
defatom *reel $ -> reel-schema/reel (assoc :base schema/store) (assoc :store schema/store)
|dispatch! $ %{} :CodeEntry (:doc |)
:code $ quote
defn dispatch! (op) (; println |Dispatch: op)
reset! *reel $ reel-updater updater @*reel op
|main! $ %{} :CodeEntry (:doc |)
:code $ quote
defn main! ()
println "\"Running mode:" $ if config/dev? "\"dev" "\"release"
if ssr? $ render-app! realize-ssr!
.!registerLanguage hljs "\"clojure" clojure-lang
.!registerLanguage hljs "\"bash" bash-lang
render-app! render!
add-watch *reel :changes $ fn (r p) (render-app! render!)
listen-devtools! |k dispatch!
.!addEventListener js/window |beforeunload persist-storage!
js/setInterval persist-storage! $ * 1000 60
let
raw $ js/localStorage.getItem (:storage-key config/site)
when (some? raw)
dispatch! $ :: :hydrate-storage (parse-cirru-edn raw)
println "|App started."
|mount-target $ %{} :CodeEntry (:doc |)
:code $ quote
def mount-target $ js/document.querySelector |.app
|persist-storage! $ %{} :CodeEntry (:doc |)
:code $ quote
defn persist-storage! (? e)
js/localStorage.setItem (:storage-key config/site)
format-cirru-edn $ :store @*reel
|reload! $ %{} :CodeEntry (:doc |)
:code $ quote
defn reload! () (clear-cache!)
reset! *reel $ refresh-reel @*reel schema/store updater
println "|Code updated."
|render-app! $ %{} :CodeEntry (:doc |)
:code $ quote
defn render-app! (renderer)
renderer mount-target (comp-container @*reel) dispatch!
|ssr? $ %{} :CodeEntry (:doc |)
:code $ quote
def ssr? $ some? (js/document.querySelector |meta.respo-ssr)
:ns $ %{} :CodeEntry (:doc |)
:code $ quote
ns app.main $ :require
[] respo.core :refer $ [] render! clear-cache! realize-ssr!
[] app.comp.container :refer $ [] comp-container
[] app.updater :refer $ [] updater
[] app.schema :as schema
[] reel.util :refer $ [] listen-devtools!
[] reel.core :refer $ [] reel-updater refresh-reel
[] reel.schema :as reel-schema
[] cljs.reader :refer $ [] read-string
[] app.config :as config
[] "\"highlight.js" :default hljs
[] "\"highlight.js/lib/languages/clojure" :default clojure-lang
[] "\"highlight.js/lib/languages/bash" :default bash-lang
|app.page $ %{} :FileEntry
:defs $ {}
|base-info $ %{} :CodeEntry (:doc |)
:code $ quote
def base-info $ {}
:title $ :title config/site
:icon $ :icon config/site
:ssr nil
:inline-html nil
|dev-page $ %{} :CodeEntry (:doc |)
:code $ quote
defn dev-page () $ make-page |
merge base-info $ {}
:styles $ [] (<< "\"http://~(get-ip!):8100/main.css") "\"/entry/main.css"
:scripts $ [] |/client.js
:inline-styles $ [] (slurp "\"entry/github-gist.css") (slurp "\"node_modules/github-markdown-css/github-markdown.css")
|main! $ %{} :CodeEntry (:doc |)
:code $ quote
defn main! ()
println "\"Running mode:" $ if config/dev? "\"dev" "\"release"
if config/dev?
spit "\"target/index.html" $ dev-page
spit "\"dist/index.html" $ prod-page
|prod-page $ %{} :CodeEntry (:doc |)
:code $ quote
defn prod-page () $ let
reel $ -> reel-schema/reel (assoc :base schema/store) (assoc :store schema/store)
html-content $ make-string (comp-container reel)
assets $ read-string (slurp |dist/assets.edn)
cdn $ if config/cdn? (:cdn-url config/site) "\""
prefix-cdn $ fn (x) (str cdn x)
make-page html-content $ merge base-info
{}
:styles $ [] (:release-ui config/site)
:scripts $ map ("#()" -> % :output-name prefix-cdn) assets
:ssr |respo-ssr
:inline-styles $ [] (slurp "\"entry/github-gist.css") (slurp "\"node_modules/github-markdown-css/github-markdown.css") (slurp |./entry/main.css)
:ns $ %{} :CodeEntry (:doc |)
:code $ quote
ns app.page
:require
[] respo.render.html :refer $ [] make-string
[] shell-page.core :refer $ [] make-page spit slurp
[] app.comp.container :refer $ [] comp-container
[] app.schema :as schema
[] reel.schema :as reel-schema
[] cljs.reader :refer $ [] read-string
[] app.config :as config
[] cumulo-util.build :refer $ [] get-ip!
:require-macros $ [] clojure.core.strint :refer ([] <<)
|app.schema $ %{} :FileEntry
:defs $ {}
|store $ %{} :CodeEntry (:doc |)
:code $ quote
def store $ {}
:states $ {}
:content |
:ns $ %{} :CodeEntry (:doc |)
:code $ quote (ns app.schema)
|app.updater $ %{} :FileEntry
:defs $ {}
|updater $ %{} :CodeEntry (:doc |)
:code $ quote
defn updater (store op op-id op-time)
tag-match op
:states cursor s
update-states store cursor s
(:content c) (assoc store :content c)
(:hydrate-storage d) d
_ $ do (eprintln "\"Unknown op:" op) store
:ns $ %{} :CodeEntry (:doc |)
:code $ quote
ns app.updater $ :require
[] respo.cursor :refer $ [] update-states