-
Notifications
You must be signed in to change notification settings - Fork 1
/
template.moonxml
161 lines (146 loc) · 3.75 KB
/
template.moonxml
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
tbl, inspect = ...
ROOT = ->
-- dump = (iskey) =>
-- switch type @
-- when "table"
-- if iskey
-- div class: "kv", ->
-- span "["
-- span class: "code-#{type @}", inspect @
-- span "]:"
-- else
-- details class: "kv", ->
-- summary ->
-- len = 0
-- for k, v in pairs @ do len += 1
-- span class: "summary", "Table (#{len})"
-- span class: "object", tostring @
-- for k, v in pairs @
-- div class: "pair", ->
-- dump k, true
-- dump v, false
-- else
-- if iskey
-- div class: "kv", ->
-- span "["
-- span class: "code-#{type @}", inspect @
-- span "]:"
-- else
-- div class: "kv code-#{type @}", inspect @
stack = {
push: table.insert
pop: table.remove
find: (target) => for index, item in ipairs @
return index if item == target
}
dump = (k=ROOT, v) ->
-- handle the key first
div class: "pair", ->
div class: "kv value", ->
switch type v
when "table"
details ->
summary ->
if k != ROOT
div class: "kv key", ->
span "["
span class: "code-#{type k}", inspect k
span "] = "
len = 0
for kk, vv in pairs v do len += 1
span class: "summary", "Table (#{len})"
span class: "object", tostring v
if stack\find v
b "(Recursion)"
else
stack\push v
tpairs = {}
for kk, vv in pairs v
table.insert tpairs, { kk, vv }
table.sort tpairs, (a, b) ->
a,b = a[1], b[1]
if (type a) < (type b) then
return true
elseif (type a) > (type b) then
return false
else
if (type a) == "number"
return a < b
else
return (tostring a) < (tostring b)
for idx, pair in ipairs tpairs
dump pair[1], pair[2]
stack\pop!
else
if k != ROOT
div class: "kv key", ->
span "["
span class: "code-#{type k}", inspect k
span "] = "
div class: "kv code-#{type v}", inspect v
print "<!doctype html>"
html ->
head ->
style -> print [[
details > *:not(summary) {
padding-left: 2em;
}
#main {
font-family: Fira Code, 'Courier New', Courier, monospace;
}
span.object {
color: #aaa;
font-size: 0.7em;
}
div.pair {
margin: 0.5em;
display: flex;
}
div.kv {
display: inline;
width: max-content;
}
details,
details[open],
details:focus {
outline: 0;
outline-color: #fff;
}
.code-string {
color: green;
}
.code-number {
color: purple;
}
.code-boolean {
color: gold;
}
.code-function {
color: blue;
}
.code-table {
color: brown;
}
details > summary {
list-style: none;
}
details > summary::-webkit-details-marker {
display: none;
}
details > summary::after {
content: "\25BC";
display: inline-block;
transform: rotate(-90deg);
margin-left: .6em;
}
details[open] > summary::after {
transform: none;
}
:focus {
outline: none;
}
]]
body ->
div id: "main", ->
-- dump tbl
dump ROOT, tbl