clementine 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/Gemfile +4 -0
- data/README.md +52 -0
- data/Rakefile +1 -0
- data/clementine.gemspec +23 -0
- data/lib/clementine.rb +27 -0
- data/lib/clementine/clementine_rails.rb +8 -0
- data/lib/clementine/clojurescript_engine.rb +49 -0
- data/lib/clementine/clojurescript_engine_mri.rb +65 -0
- data/lib/clementine/clojurescript_template.rb +21 -0
- data/lib/clementine/options.rb +9 -0
- data/lib/clementine/version.rb +3 -0
- data/test/clojurescript_engine_test.rb +46 -0
- data/test/options_test.rb +22 -0
- data/vendor/assets/bin/cljsc.clj +21 -0
- data/vendor/assets/lib/clojure.jar +0 -0
- data/vendor/assets/lib/compiler.jar +0 -0
- data/vendor/assets/lib/goog.jar +0 -0
- data/vendor/assets/lib/js.jar +0 -0
- data/vendor/assets/src/clj/cljs/closure.clj +823 -0
- data/vendor/assets/src/clj/cljs/compiler.clj +1341 -0
- data/vendor/assets/src/clj/cljs/core.clj +702 -0
- data/vendor/assets/src/clj/cljs/repl.clj +162 -0
- data/vendor/assets/src/clj/cljs/repl/browser.clj +341 -0
- data/vendor/assets/src/clj/cljs/repl/rhino.clj +170 -0
- data/vendor/assets/src/cljs/cljs/core.cljs +3330 -0
- data/vendor/assets/src/cljs/cljs/nodejs.cljs +11 -0
- data/vendor/assets/src/cljs/cljs/nodejs_externs.js +2 -0
- data/vendor/assets/src/cljs/cljs/nodejscli.cljs +9 -0
- data/vendor/assets/src/cljs/cljs/reader.cljs +360 -0
- data/vendor/assets/src/cljs/clojure/browser/dom.cljs +106 -0
- data/vendor/assets/src/cljs/clojure/browser/event.cljs +100 -0
- data/vendor/assets/src/cljs/clojure/browser/net.cljs +182 -0
- data/vendor/assets/src/cljs/clojure/browser/repl.cljs +109 -0
- data/vendor/assets/src/cljs/clojure/set.cljs +162 -0
- data/vendor/assets/src/cljs/clojure/string.cljs +160 -0
- data/vendor/assets/src/cljs/clojure/walk.cljs +94 -0
- data/vendor/assets/src/cljs/clojure/zip.cljs +291 -0
- metadata +103 -0
@@ -0,0 +1,11 @@
|
|
1
|
+
; Projects compiled with :target :nodejs can 'require' this namespace
|
2
|
+
; to get the nodejs globals loaded into cljs.nodejs and get
|
3
|
+
; ClojureScript's 'print' set up correctly.
|
4
|
+
(ns cljs.nodejs)
|
5
|
+
|
6
|
+
; Define namespaced references to Node's externed globals:
|
7
|
+
(def require (js* "require"))
|
8
|
+
(def process (js* "process"))
|
9
|
+
|
10
|
+
; Have ClojureScript print using Node's sys.print function
|
11
|
+
(set! cljs.core/string-print (.print (require "sys")))
|
@@ -0,0 +1,9 @@
|
|
1
|
+
; Projects compiled with :target :nodejs have this file appended. Its
|
2
|
+
; job is to make sure cljs.nodejs is loaded and that the *main-cli-fn*
|
3
|
+
; is called with the script's command-line arguments.
|
4
|
+
(ns cljs.nodejscli
|
5
|
+
(:require [cljs.nodejs :as nodejs]))
|
6
|
+
|
7
|
+
; Call the user's main function
|
8
|
+
(apply cljs.core/*main-cli-fn* (drop 2 (.argv nodejs/process)))
|
9
|
+
|
@@ -0,0 +1,360 @@
|
|
1
|
+
; Copyright (c) Rich Hickey. All rights reserved.
|
2
|
+
; The use and distribution terms for this software are covered by the
|
3
|
+
; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
|
4
|
+
; which can be found in the file epl-v10.html at the root of this distribution.
|
5
|
+
; By using this software in any fashion, you are agreeing to be bound by
|
6
|
+
; the terms of this license.
|
7
|
+
; You must not remove this notice, or any other, from this software.
|
8
|
+
|
9
|
+
(ns cljs.reader
|
10
|
+
(:require [goog.string :as gstring]))
|
11
|
+
|
12
|
+
(defprotocol PushbackReader
|
13
|
+
(read-char [reader] "Returns the next char from the Reader,
|
14
|
+
nil if the end of stream has been reached")
|
15
|
+
(unread [reader ch] "Push back a single character on to the stream"))
|
16
|
+
|
17
|
+
; Using two atoms is less idomatic, but saves the repeat overhead of map creation
|
18
|
+
(deftype StringPushbackReader [s index-atom buffer-atom]
|
19
|
+
PushbackReader
|
20
|
+
(read-char [reader]
|
21
|
+
(if (empty? @buffer-atom)
|
22
|
+
(let [idx @index-atom]
|
23
|
+
(swap! index-atom inc)
|
24
|
+
(nth s idx))
|
25
|
+
(let [buf @buffer-atom]
|
26
|
+
(swap! buffer-atom rest)
|
27
|
+
(first buf))))
|
28
|
+
(unread [reader ch] (swap! buffer-atom #(cons ch %))))
|
29
|
+
|
30
|
+
(defn push-back-reader [s]
|
31
|
+
"Creates a StringPushbackReader from a given string"
|
32
|
+
(StringPushbackReader. s (atom 0) (atom nil)))
|
33
|
+
|
34
|
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
35
|
+
;; predicates
|
36
|
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
37
|
+
|
38
|
+
(defn- whitespace?
|
39
|
+
"Checks whether a given character is whitespace"
|
40
|
+
[ch]
|
41
|
+
(or (gstring/isBreakingWhitespace ch) (= \, ch)))
|
42
|
+
|
43
|
+
(defn- numeric?
|
44
|
+
"Checks whether a given character is numeric"
|
45
|
+
[ch]
|
46
|
+
(gstring/isNumeric ch))
|
47
|
+
|
48
|
+
(defn- comment-prefix?
|
49
|
+
"Checks whether the character begins a comment."
|
50
|
+
[ch]
|
51
|
+
(= \; ch))
|
52
|
+
|
53
|
+
(defn- number-literal?
|
54
|
+
"Checks whether the reader is at the start of a number literal"
|
55
|
+
[reader initch]
|
56
|
+
(or (numeric? initch)
|
57
|
+
(and (or (= \+ initch) (= \- initch))
|
58
|
+
(numeric? (let [next-ch (read-char reader)]
|
59
|
+
(unread reader next-ch)
|
60
|
+
next-ch)))))
|
61
|
+
|
62
|
+
(declare read macros dispatch-macros)
|
63
|
+
|
64
|
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
65
|
+
;; read helpers
|
66
|
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
67
|
+
|
68
|
+
; later will do e.g. line numbers...
|
69
|
+
(defn reader-error
|
70
|
+
[rdr & msg]
|
71
|
+
(throw (apply str msg)))
|
72
|
+
|
73
|
+
(defn macro-terminating? [ch]
|
74
|
+
(and (not= ch "#") (not= ch \') (not= ch ":") (contains? macros ch)))
|
75
|
+
|
76
|
+
(defn read-token
|
77
|
+
[rdr initch]
|
78
|
+
(loop [sb (gstring/StringBuffer. initch)
|
79
|
+
ch (read-char rdr)]
|
80
|
+
(if (or (nil? ch)
|
81
|
+
(whitespace? ch)
|
82
|
+
(macro-terminating? ch))
|
83
|
+
(do (unread rdr ch) (. sb (toString)))
|
84
|
+
(recur (do (.append sb ch) sb) (read-char rdr)))))
|
85
|
+
|
86
|
+
(defn skip-line
|
87
|
+
"Advances the reader to the end of a line. Returns the reader"
|
88
|
+
[reader _]
|
89
|
+
(loop []
|
90
|
+
(let [ch (read-char reader)]
|
91
|
+
(if (or (= ch \n) (= ch \r) (nil? ch))
|
92
|
+
reader
|
93
|
+
(recur)))))
|
94
|
+
|
95
|
+
(def int-pattern (re-pattern "([-+]?)(?:(0)|([1-9][0-9]*)|0[xX]([0-9A-Fa-f]+)|0([0-7]+)|([1-9][0-9]?)[rR]([0-9A-Za-z]+)|0[0-9]+)(N)?"))
|
96
|
+
(def ratio-pattern (re-pattern "([-+]?[0-9]+)/([0-9]+)"))
|
97
|
+
(def float-pattern (re-pattern "([-+]?[0-9]+(\\.[0-9]*)?([eE][-+]?[0-9]+)?)(M)?"))
|
98
|
+
(def symbol-pattern (re-pattern "[:]?([^0-9/].*/)?([^0-9/][^/]*)"))
|
99
|
+
|
100
|
+
(defn- match-int
|
101
|
+
[s]
|
102
|
+
(let [groups (re-find int-pattern s)]
|
103
|
+
(if (nth groups 2)
|
104
|
+
0
|
105
|
+
(let [negate (if (= "-" (nth groups 1)) -1 1)
|
106
|
+
[n radix] (cond
|
107
|
+
(nth groups 3) [(nth groups 3) 10]
|
108
|
+
(nth groups 4) [(nth groups 4) 16]
|
109
|
+
(nth groups 5) [(nth groups 5) 8]
|
110
|
+
(nth groups 7) [(nth groups 7) (js/parseInt (nth groups 7))]
|
111
|
+
:default [nil nil])]
|
112
|
+
(if (nil? n)
|
113
|
+
nil
|
114
|
+
(* negate (js/parseInt n radix)))))))
|
115
|
+
|
116
|
+
|
117
|
+
(defn- match-ratio
|
118
|
+
[s]
|
119
|
+
(let [groups (re-find ratio-pattern s)
|
120
|
+
numinator (nth groups 1)
|
121
|
+
denominator (nth groups 2)]
|
122
|
+
(/ (js/parseInt numinator) (js/parseInt denominator))))
|
123
|
+
|
124
|
+
(defn- match-float
|
125
|
+
[s]
|
126
|
+
(js/parseFloat s))
|
127
|
+
|
128
|
+
(defn- match-number
|
129
|
+
[s]
|
130
|
+
(cond
|
131
|
+
(re-matches int-pattern s) (match-int s)
|
132
|
+
(re-matches ratio-pattern s) (match-ratio s)
|
133
|
+
(re-matches float-pattern s) (match-float s)))
|
134
|
+
|
135
|
+
(def escape-char-map {\t "\t"
|
136
|
+
\r "\r"
|
137
|
+
\n "\n"
|
138
|
+
\\ \\
|
139
|
+
\" \"
|
140
|
+
\b "\b"
|
141
|
+
\f "\f"})
|
142
|
+
|
143
|
+
(defn read-unicode-char
|
144
|
+
[reader initch]
|
145
|
+
(reader-error reader "Unicode characters not supported by reader (yet)"))
|
146
|
+
|
147
|
+
(defn escape-char
|
148
|
+
[buffer reader]
|
149
|
+
(let [ch (read-char reader)
|
150
|
+
mapresult (get escape-char-map ch)]
|
151
|
+
(if mapresult
|
152
|
+
mapresult
|
153
|
+
(if (or (= \u ch) (numeric? ch))
|
154
|
+
(read-unicode-char reader ch)
|
155
|
+
(reader-error reader "Unsupported escape charater: \\" ch)))))
|
156
|
+
|
157
|
+
(defn read-past
|
158
|
+
"Read until first character that doesn't match pred, returning
|
159
|
+
char."
|
160
|
+
[pred rdr]
|
161
|
+
(loop [ch (read-char rdr)]
|
162
|
+
(if (pred ch)
|
163
|
+
(recur (read-char rdr))
|
164
|
+
ch)))
|
165
|
+
|
166
|
+
(defn read-delimited-list
|
167
|
+
[delim rdr recursive?]
|
168
|
+
(loop [a []]
|
169
|
+
(let [ch (read-past whitespace? rdr)]
|
170
|
+
(when-not ch (reader-error rdr "EOF"))
|
171
|
+
(if (= delim ch)
|
172
|
+
a
|
173
|
+
(if-let [macrofn (get macros ch)]
|
174
|
+
(let [mret (macrofn rdr ch)]
|
175
|
+
(recur (if (= mret rdr) a (conj a mret))))
|
176
|
+
(do
|
177
|
+
(unread rdr ch)
|
178
|
+
(let [o (read rdr true nil recursive?)]
|
179
|
+
(recur (if (= o rdr) a (conj a o))))))))))
|
180
|
+
|
181
|
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
182
|
+
;; data structure readers
|
183
|
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
184
|
+
|
185
|
+
(defn not-implemented
|
186
|
+
[rdr ch]
|
187
|
+
(reader-error rdr "Reader for " ch " not implemented yet"))
|
188
|
+
|
189
|
+
(defn read-dispatch
|
190
|
+
[rdr _]
|
191
|
+
(let [ch (read-char rdr)
|
192
|
+
dm (get dispatch-macros ch)]
|
193
|
+
(if dm
|
194
|
+
(dm rdr _)
|
195
|
+
(reader-error rdr "No dispatch macro for " ch))))
|
196
|
+
|
197
|
+
(defn read-unmatched-delimiter
|
198
|
+
[rdr ch]
|
199
|
+
(reader-error rdr "Unmached delimiter " ch))
|
200
|
+
|
201
|
+
(defn read-list
|
202
|
+
[rdr _]
|
203
|
+
(apply list (read-delimited-list ")" rdr true)))
|
204
|
+
|
205
|
+
(def read-comment skip-line)
|
206
|
+
|
207
|
+
(defn read-vector
|
208
|
+
[rdr _]
|
209
|
+
(read-delimited-list "]" rdr true))
|
210
|
+
|
211
|
+
(defn read-map
|
212
|
+
[rdr _]
|
213
|
+
(let [l (read-delimited-list "}" rdr true)]
|
214
|
+
(when (odd? (count l))
|
215
|
+
(reader-error rdr "Map literal must contain an even number of forms"))
|
216
|
+
(apply hash-map l)))
|
217
|
+
|
218
|
+
(defn read-number
|
219
|
+
[reader initch]
|
220
|
+
(loop [buffer (gstring/StringBuffer. initch)
|
221
|
+
ch (read-char reader)]
|
222
|
+
(if (or (nil? ch) (whitespace? ch) (contains? macros ch))
|
223
|
+
(do
|
224
|
+
(unread reader ch)
|
225
|
+
(let [s (. buffer (toString))]
|
226
|
+
(or (match-number s)
|
227
|
+
(reader-error reader "Invalid number format [" s "]"))))
|
228
|
+
(recur (do (.append buffer ch) buffer) (read-char reader)))))
|
229
|
+
|
230
|
+
(defn read-string
|
231
|
+
[reader _]
|
232
|
+
(loop [buffer (gstring/StringBuffer.)
|
233
|
+
ch (read-char reader)]
|
234
|
+
(cond
|
235
|
+
(nil? ch) (reader-error reader "EOF while reading string")
|
236
|
+
(= "\\" ch) (recur (do (.append buffer (escape-char buffer reader)) buffer)
|
237
|
+
(read-char reader))
|
238
|
+
(= \" ch) (. buffer (toString))
|
239
|
+
:default (recur (do (.append buffer ch) buffer) (read-char reader)))))
|
240
|
+
|
241
|
+
(def special-symbols
|
242
|
+
{"nil" nil
|
243
|
+
"true" true
|
244
|
+
"false" false})
|
245
|
+
|
246
|
+
(defn read-symbol
|
247
|
+
[reader initch]
|
248
|
+
(let [token (read-token reader initch)]
|
249
|
+
(if (gstring/contains token "/")
|
250
|
+
(symbol (subs token 0 (.indexOf token "/"))
|
251
|
+
(subs (inc (.indexOf token "/")) (.length token)))
|
252
|
+
(get special-symbols token (symbol token)))))
|
253
|
+
|
254
|
+
(defn read-keyword
|
255
|
+
[reader initch]
|
256
|
+
(let [token (read-token reader (read-char reader))
|
257
|
+
[token ns name] (re-matches symbol-pattern token)]
|
258
|
+
(if (or (and (not (undefined? ns))
|
259
|
+
(identical? (. ns (substring (- (.length ns) 2) (.length ns))) ":/"))
|
260
|
+
(identical? (aget name (dec (.length name))) ":")
|
261
|
+
(not (== (.indexOf token "::" 1) -1)))
|
262
|
+
(reader-error reader "Invalid token: " token)
|
263
|
+
(if (not (undefined? ns))
|
264
|
+
(keyword (.substring ns 0 (.indexOf ns "/")) name)
|
265
|
+
(keyword token)))))
|
266
|
+
|
267
|
+
(defn desugar-meta
|
268
|
+
[f]
|
269
|
+
(cond
|
270
|
+
(symbol? f) {:tag f}
|
271
|
+
(string? f) {:tag f}
|
272
|
+
(keyword? f) {f true}
|
273
|
+
:else f))
|
274
|
+
|
275
|
+
(defn wrapping-reader
|
276
|
+
[sym]
|
277
|
+
(fn [rdr _]
|
278
|
+
(list sym (read rdr true nil true))))
|
279
|
+
|
280
|
+
(defn throwing-reader
|
281
|
+
[msg]
|
282
|
+
(fn [rdr _]
|
283
|
+
(reader-error rdr msg)))
|
284
|
+
|
285
|
+
(defn read-meta
|
286
|
+
[rdr _]
|
287
|
+
(let [m (desugar-meta (read rdr true nil true))]
|
288
|
+
(when-not (map? m)
|
289
|
+
(reader-error rdr "Metadata must be Symbol,Keyword,String or Map"))
|
290
|
+
(let [o (read rdr true nil true)]
|
291
|
+
(if (satisfies? IWithMeta o)
|
292
|
+
(with-meta o (merge (meta o) m))
|
293
|
+
(reader-error rdr "Metadata can only be applied to IWithMetas")))))
|
294
|
+
|
295
|
+
(defn read-set
|
296
|
+
[rdr _]
|
297
|
+
(set (read-delimited-list "}" rdr true)))
|
298
|
+
|
299
|
+
(defn read-regex
|
300
|
+
[rdr ch]
|
301
|
+
(-> (read-string rdr ch) re-pattern))
|
302
|
+
|
303
|
+
(defn read-discard
|
304
|
+
[rdr _]
|
305
|
+
(read rdr true nil true)
|
306
|
+
rdr)
|
307
|
+
|
308
|
+
(def macros
|
309
|
+
{ \" read-string
|
310
|
+
\: read-keyword
|
311
|
+
\; not-implemented ;; never hit this
|
312
|
+
\' (wrapping-reader 'quote)
|
313
|
+
\@ (wrapping-reader 'deref)
|
314
|
+
\^ read-meta
|
315
|
+
\` not-implemented
|
316
|
+
\~ not-implemented
|
317
|
+
\( read-list
|
318
|
+
\) read-unmatched-delimiter
|
319
|
+
\[ read-vector
|
320
|
+
\] read-unmatched-delimiter
|
321
|
+
\{ read-map
|
322
|
+
\} read-unmatched-delimiter
|
323
|
+
\\ read-char
|
324
|
+
\% not-implemented
|
325
|
+
\# read-dispatch
|
326
|
+
})
|
327
|
+
|
328
|
+
;; omitted by design: var reader, eval reader
|
329
|
+
(def dispatch-macros
|
330
|
+
{"{" read-set
|
331
|
+
"<" (throwing-reader "Unreadable form")
|
332
|
+
"\"" read-regex
|
333
|
+
"!" read-comment
|
334
|
+
"_" read-discard})
|
335
|
+
|
336
|
+
(defn read
|
337
|
+
"Reads the first object from a PushbackReader. Returns the object read.
|
338
|
+
If EOF, throws if eof-is-error is true. Otherwise returns sentinel."
|
339
|
+
[reader eof-is-error sentinel is-recursive]
|
340
|
+
(let [ch (read-char reader)]
|
341
|
+
(cond
|
342
|
+
(nil? ch) (if eof-is-error (reader-error reader "EOF") sentinel)
|
343
|
+
(whitespace? ch) (recur reader eof-is-error sentinel is-recursive)
|
344
|
+
(comment-prefix? ch) (recur (read-comment reader ch) eof-is-error sentinel is-recursive)
|
345
|
+
:else (let [res
|
346
|
+
(cond
|
347
|
+
(macros ch) ((macros ch) reader ch)
|
348
|
+
(number-literal? reader ch) (read-number reader ch)
|
349
|
+
:else (read-symbol reader ch))]
|
350
|
+
(if (= res reader)
|
351
|
+
(recur reader eof-is-error sentinel is-recursive)
|
352
|
+
res)))))
|
353
|
+
|
354
|
+
(defn read-string
|
355
|
+
"Reads one object from the string s"
|
356
|
+
[s]
|
357
|
+
(let [r (push-back-reader s)]
|
358
|
+
(read r true nil false)))
|
359
|
+
|
360
|
+
|
@@ -0,0 +1,106 @@
|
|
1
|
+
;; Copyright (c) Rich Hickey. All rights reserved.
|
2
|
+
;; The use and distribution terms for this software are covered by the
|
3
|
+
;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
|
4
|
+
;; which can be found in the file epl-v10.html at the root of this distribution.
|
5
|
+
;; By using this software in any fashion, you are agreeing to be bound by
|
6
|
+
;; the terms of this license.
|
7
|
+
;; You must not remove this notice, or any other, from this software.
|
8
|
+
|
9
|
+
(ns clojure.browser.dom
|
10
|
+
(:require [goog.dom :as gdom]))
|
11
|
+
|
12
|
+
(defn append [parent & children]
|
13
|
+
(apply gdom/append parent children)
|
14
|
+
parent)
|
15
|
+
|
16
|
+
(defprotocol DOMBuilder
|
17
|
+
(-element [this] [this attrs-or-children] [this attrs children]))
|
18
|
+
|
19
|
+
(defn log [& args]
|
20
|
+
(.log js/console (apply pr-str args)))
|
21
|
+
|
22
|
+
(defn log-obj [obj]
|
23
|
+
(.log js/console obj))
|
24
|
+
|
25
|
+
(extend-protocol DOMBuilder
|
26
|
+
|
27
|
+
string
|
28
|
+
(-element
|
29
|
+
([this]
|
30
|
+
(log "string (-element " this ")")
|
31
|
+
(cond (keyword? this) (gdom/createElement (name this))
|
32
|
+
:else (gdom/createTextNode (name this))))
|
33
|
+
|
34
|
+
([this attrs-or-children]
|
35
|
+
(log "string (-element " this " " attrs-or-children ")")
|
36
|
+
(let [attrs (first attrs-or-children)]
|
37
|
+
(if (map? attrs)
|
38
|
+
(-element this attrs (rest attrs-or-children))
|
39
|
+
(-element this nil attrs-or-children))))
|
40
|
+
|
41
|
+
([this attrs children]
|
42
|
+
(log "string (-element " this " " attrs " " children ")")
|
43
|
+
(let [str-attrs (if (and (map? attrs) (seq attrs))
|
44
|
+
(.strobj (reduce (fn [m [k v]]
|
45
|
+
(log "m = " m)
|
46
|
+
(log "k = " k)
|
47
|
+
(log "v = " v)
|
48
|
+
(when (or (keyword? k)
|
49
|
+
(string? k))
|
50
|
+
(assoc m (name k) v)))
|
51
|
+
{}
|
52
|
+
attrs))
|
53
|
+
nil)]
|
54
|
+
(log-obj str-attrs)
|
55
|
+
(if (seq children)
|
56
|
+
(apply gdom/createDom
|
57
|
+
(name this)
|
58
|
+
str-attrs
|
59
|
+
(map -element children))
|
60
|
+
(gdom/createDom (name this)
|
61
|
+
str-attrs)))))
|
62
|
+
|
63
|
+
Vector
|
64
|
+
(-element
|
65
|
+
[this]
|
66
|
+
(log "Vector (-element " this ")")
|
67
|
+
(let [tag (first this)
|
68
|
+
attrs (second this)
|
69
|
+
children (drop 2 this)]
|
70
|
+
(if (map? attrs)
|
71
|
+
(-element tag attrs children)
|
72
|
+
(-element tag nil (rest this)))))
|
73
|
+
|
74
|
+
js/Element
|
75
|
+
(-element [this]
|
76
|
+
(log "js/Element (-element " this ")")
|
77
|
+
this))
|
78
|
+
|
79
|
+
(defn element
|
80
|
+
([tag-or-text]
|
81
|
+
(log "(element " tag-or-text ")")
|
82
|
+
(-element tag-or-text))
|
83
|
+
([tag & children]
|
84
|
+
(log "(element " tag " " children ")")
|
85
|
+
(let [attrs (first children)]
|
86
|
+
(if (map? attrs)
|
87
|
+
(-element tag attrs (rest children))
|
88
|
+
(-element tag nil children)))))
|
89
|
+
|
90
|
+
(defn remove-children
|
91
|
+
"Remove all children from the element with the passed id."
|
92
|
+
[id]
|
93
|
+
(let [parent (gdom/getElement (name id))]
|
94
|
+
(do (gdom/removeChildren parent))))
|
95
|
+
|
96
|
+
(defn get-element [id]
|
97
|
+
(gdom/getElement (name id)))
|
98
|
+
|
99
|
+
(defn html->dom [s]
|
100
|
+
(gdom/htmlToDocumentFragment s))
|
101
|
+
|
102
|
+
(defn insert-at [parent child index]
|
103
|
+
(gdom/insertChildAt parent child index))
|
104
|
+
|
105
|
+
;; TODO CSS class manipulation
|
106
|
+
;; TODO Query syntax
|