-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhlisp.hl
81 lines (65 loc) · 1.9 KB
/
hlisp.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
68
69
70
71
72
73
74
75
76
77
78
79
;; skipping a few lines...
(defn mapattr
[elem (pairs {...})]
(ins
(fn [x xs]
(attr xs (first x) (first (rest x))))
pairs
elem))
(defn (dep {ref on})
[elem]
(do
(def sym (gensym nil))
(def elem (attr elem (strcat ^"data-dep::" ref ^":" on) sym))
(ins
(fn [x xs]
(cond
[ (eq (first x) ^"ref") xs ]
[ (eq (first x) ^"on") xs ]
[ else (attr xs
(strcat ^"data-" sym ^"::" (first x))
(first (rest x))) ]))
(attrs arguments)
elem)))
(defn dep2
[elem ref on (args {...})]
(do
(def args (conj args [^"ref" ref] [^"on" on]))
(conj (apply (quote (mapattr dep)) args) elem)))
(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]
(ins
conj
[ (mapattr dep
[^"ref" ref]
[^"on" ^"_status"]
[^"class.disabled" ^"$$['_status'] == 'disabled'"])
(mapattr dep
[^"ref" ref]
[^"on" ^"_value"]
[^"value" ^"$$['_value']"]) ]
elem))
(defn (input-text {_name _label _message _help})
[]
(do
(def sym (gensym nil))
(def inp (attr input ^"type" ^"text" ^"name" _name))
(conj
(attr div ^"data-name" sym)
(conj
(dep-status sym (div {class "control control-text"}))
(dep-status sym (dep-state sym inp)))
(dep2 (dep-status sym (p {class "message"}))
sym
^"_message"
[^"text" ^"$$['_message']"])
(dep2 p sym ^"_help" [^"text" ^"$$['_help']"]))))