-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhlisp2.hl
68 lines (61 loc) · 1.85 KB
/
hlisp2.hl
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
(defn (dep {ref on})
[elem]
(def sym (gensym nil))
(def elem2 (attr elem [ (strcat ^"data-dep::" ref ^":" on) sym ]))
(insert
(fn [x xs]
(cond
[ (eq (first x) ^"ref") xs ]
[ (eq (first x) ^"on") xs ]
[ else (do (def k (strcat ^"data-" sym ^"::" (first x)))
(def v (first (rest x)))
(attr xs [ k v ])) ]))
(attrs callee)
elem2))
(defn dep2
; This is a test.
[elem ref on (args {...})]
(def args (conj list [^"ref" ref] [^"on" on] args))
(eval (attrs '(dep elem) args)))
(defn dep-status
[ref elem]
(dep2 elem
ref
^"-status"
[^"class.success" ^"$$['-status'] == 'success'"]
[^"class.error" ^"$$['-status'] == 'error'"]
[^"class.warning" ^"$$['-status'] == 'warning'"]
[^"class.disabled" ^"$$['-status'] == 'disabled'"]))
(defn dep-state
[ref elem]
(eval
(insert
conj
[ (attrs 'dep
[ [^"ref" ref]
[^"on" ^"-status"]
[^"class.disabled" ^"$$['-status'] == 'disabled'"] ])
(attrs 'dep
[ [^"ref" ref]
[^"on" ^"-value"]
[^"value" ^"$$['-value']"] ]) ]
elem)))
(defn (ctl-group {-label})
[(elems {...})]
(div {class "control-group"}
(text label -label)
(cat (div {class "controls"}) elems)))
(defn ctl-input
[inp]
(def sym (gensym nil))
(def cls (strcat ^"control control-" (attr inp ^"type")))
(conj
(attr div [^"data-name" sym])
(conj
(dep-status sym (attr div [^"class" cls]))
(dep-status sym (dep-state sym inp)))
(dep2 (dep-status sym (p {class "message"}))
sym
^"-message"
[^"text" ^"$$['-message']"])
(dep2 p sym ^"-help" [^"text" ^"$$['-help']"])))