Skip to content

Commit 757c9b2

Browse files
committed
some formatting - could be improved
1 parent ca490d8 commit 757c9b2

File tree

2 files changed

+62
-16
lines changed

2 files changed

+62
-16
lines changed

page.lisp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,10 @@
3535
footer))))
3636

3737
(dolist (page pages)
38-
(write-html (template page (eval (with-open-file (file (conc-str page ".lisp")) (read file)))) page))
38+
(write-html
39+
(template page
40+
(eval
41+
(with-open-file
42+
(file (conc-str page ".lisp"))
43+
(read file))))
44+
page))

site.lisp

Lines changed: 55 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,29 @@
11
(defmacro conc-str (&rest body)
22
`(concatenate 'string ,@body))
33

4+
(defun apply-conc-str (strings)
5+
(apply #'concatenate (cons 'string strings)))
6+
47
(defun attrs (attributes)
5-
(if attributes (conc-str " " (string-downcase (symbol-name (car attributes))) "=\"" (cadr attributes) "\"" (attrs (cddr attributes))) ""))
8+
(if attributes
9+
(conc-str " "
10+
(string-downcase (symbol-name (car attributes)))
11+
"=\""
12+
(cadr attributes)
13+
"\""
14+
(attrs (cddr attributes)))
15+
""))
616

717
(defmacro element (el)
818
`(defmacro ,el (attributes &rest children)
9-
`(conc-str "<" ,,(string-downcase (symbol-name el)) (attrs (list ,@attributes)) ">" ,@children "</" ,,(string-downcase (symbol-name el)) ">")))
19+
`(conc-str "<"
20+
,,(string-downcase (symbol-name el))
21+
(attrs (list ,@attributes))
22+
">"
23+
,@children
24+
"</"
25+
,,(string-downcase (symbol-name el))
26+
">")))
1027

1128
(defun write-html (html file-name)
1229
(with-open-file (file (conc-str "serve/" file-name ".html") :direction :output :if-exists :supersede)
@@ -17,21 +34,44 @@
1734
`(apply #'concatenate (let ((,binds (list 'string)))
1835
(dolist (,var ,list (nreverse ,binds))
1936
(push ,@body ,binds))))))
20-
(defun apply-conc-str (strings)
21-
(apply #'concatenate (cons 'string strings)))
37+
2238
(defmacro css (&rest styles)
23-
`(apply-conc-str (mapcar #'decleration ',styles)))
24-
(defun decleration (styles)
25-
(conc-str (apply-conc-str (mapcar (lambda (selector) (string-downcase (symbol-name selector))) (butlast styles))) "{" (properties (car (last styles))) "}"))
39+
`(apply-conc-str (mapcar #'rule ',styles)))
40+
41+
(defun rule (styles)
42+
(conc-str
43+
(apply-conc-str
44+
(mapcar
45+
(lambda (selector)
46+
(string-downcase (symbol-name selector)))
47+
(butlast styles)))
48+
"{"
49+
(properties (car (last styles)))
50+
"}"))
51+
2652
(defun properties (styles)
27-
(apply-conc-str (mapcar (lambda (prop) (conc-str (string-downcase (symbol-name (car prop))) ":" (vals (cdr prop) nil) ";")) styles)))
28-
(defun vals (value list-p)
29-
(apply-conc-str (mapcar (lambda (val next) (cond
30-
((listp val) (conc-str (vals val t) ")"))
31-
((null next) (value->string val))
32-
((listp next) (conc-str (value->string val) "("))
33-
(list-p (conc-str (value->string val) ", "))
34-
(t (conc-str (value->string val) " ")))) value (append (cdr value) (cons nil nil)))))
53+
(apply-conc-str
54+
(mapcar
55+
(lambda (declaration)
56+
(conc-str
57+
(string-downcase (symbol-name (car declaration)))
58+
":"
59+
(property-value (cdr declaration) nil)
60+
";"))
61+
styles)))
62+
63+
(defun property-value (value list-p)
64+
(apply-conc-str
65+
(mapcar
66+
(lambda (val next)
67+
(cond
68+
((listp val) (conc-str (property-value val t) ")"))
69+
((null next) (value->string val))
70+
((listp next) (conc-str (value->string val) "("))
71+
(list-p (conc-str (value->string val) ", "))
72+
(t (conc-str (value->string val) " "))))
73+
value
74+
(append (cdr value) (cons nil nil)))))
3575

3676
(defun value->string (value)
3777
(cond

0 commit comments

Comments
 (0)