-
Notifications
You must be signed in to change notification settings - Fork 0
/
site.lisp
183 lines (172 loc) · 3.73 KB
/
site.lisp
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
(defmacro conc-str (&rest body)
`(concatenate 'string ,@body))
(defun apply-conc-str (strings)
(apply #'concatenate (cons 'string strings)))
(defun attrs (attributes)
(if attributes
(conc-str " "
(string-downcase (symbol-name (car attributes)))
"=\""
(cadr attributes)
"\""
(attrs (cddr attributes)))
""))
(defmacro element (el)
`(defmacro ,el (attributes &rest children)
`(conc-str "<"
,,(string-downcase (symbol-name el))
(attrs (list ,@attributes))
">"
,@children
"</"
,,(string-downcase (symbol-name el))
">")))
(defun write-html (html file-name)
(with-open-file (file (conc-str "serve/" file-name ".html") :direction :output :if-exists :supersede)
(write-string html file)))
(defmacro dohtml ((var list) &body body)
(let ((binds (gensym)))
`(apply #'concatenate (let ((,binds (list 'string)))
(dolist (,var ,list (nreverse ,binds))
(push ,@body ,binds))))))
(defmacro css (&rest styles)
`(apply-conc-str (mapcar #'rule ',styles)))
(defun rule (styles)
(conc-str
(apply-conc-str
(mapcar
(lambda (selector)
(string-downcase (symbol-name selector)))
(butlast styles)))
"{"
(properties (car (last styles)))
"}"))
(defun properties (styles)
(apply-conc-str
(mapcar
(lambda (declaration)
(conc-str
(string-downcase (symbol-name (car declaration)))
":"
(property-value (cdr declaration) nil)
";"))
styles)))
(defun property-value (value list-p)
(apply-conc-str
(mapcar
(lambda (val next)
(cond
((listp val) (conc-str (property-value val t) ")"))
((null next) (value->string val))
((listp next) (conc-str (value->string val) "("))
(list-p (conc-str (value->string val) ", "))
(t (conc-str (value->string val) " "))))
value
(append (cdr value) (cons nil nil)))))
(defun value->string (value)
(cond
((symbolp value) (string-downcase (symbol-name value)))
((stringp value) value)
((numberp value) (write-to-string value))))
(element a)
(element abbr)
(element address)
(element area)
(element article)
(element aside)
(element audio)
(element b)
(element bdi)
(element bdo)
(element blockquote)
(element body)
(element br)
(element button)
(element canvas)
(element caption)
(element cite)
(element code)
(element col)
(element colgroup)
(element command)
(element datalist)
(element dd)
(element del)
(element details)
(element dfn)
(element div)
(element dl)
(element dt)
(element em)
(element embed)
(element fieldset)
(element figcaption)
(element figure)
(element footer)
(element form)
(element h1)
(element h2)
(element h3)
(element h4)
(element h5)
(element h6)
(element head)
(element header)
(element hr)
(element html)
(element i)
(element iframe)
(element img)
(element input)
(element ins)
(element kbd)
(element keygen)
(element label)
(element legend)
(element li)
(element link)
(element main)
(element mark)
(element menu)
(element meta)
(element meter)
(element nav)
(element object)
(element ol)
(element optgroup)
(element option)
(element output)
(element p)
(element param)
(element pre)
(element progress)
(element q)
(element rp)
(element rt)
(element ruby)
(element s)
(element samp)
(element section)
(element select)
(element small)
(element source)
(element span)
(element strong)
(element style)
(element sub)
(element summary)
(element sup)
(element table)
(element tbody)
(element td)
(element textarea)
(element tfoot)
(element th)
(element thead)
(element tr)
(element track)
(element title)
(element u)
(element ul)
(element video)
(element wbr)