|
1 | 1 | (defmacro conc-str (&rest body)
|
2 | 2 | `(concatenate 'string ,@body))
|
3 | 3 |
|
| 4 | +(defun apply-conc-str (strings) |
| 5 | + (apply #'concatenate (cons 'string strings))) |
| 6 | + |
4 | 7 | (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 | + "")) |
6 | 16 |
|
7 | 17 | (defmacro element (el)
|
8 | 18 | `(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 | + ">"))) |
10 | 27 |
|
11 | 28 | (defun write-html (html file-name)
|
12 | 29 | (with-open-file (file (conc-str "serve/" file-name ".html") :direction :output :if-exists :supersede)
|
|
17 | 34 | `(apply #'concatenate (let ((,binds (list 'string)))
|
18 | 35 | (dolist (,var ,list (nreverse ,binds))
|
19 | 36 | (push ,@body ,binds))))))
|
20 |
| -(defun apply-conc-str (strings) |
21 |
| - (apply #'concatenate (cons 'string strings))) |
| 37 | + |
22 | 38 | (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 | + |
26 | 52 | (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))))) |
35 | 75 |
|
36 | 76 | (defun value->string (value)
|
37 | 77 | (cond
|
|
0 commit comments