web/dom: improvements (but still work in progress)
This commit is contained in:
parent
00366e8b13
commit
98d2246017
1 changed files with 21 additions and 10 deletions
31
web/dom.lisp
31
web/dom.lisp
|
@ -7,6 +7,8 @@
|
||||||
|
|
||||||
(in-package :scopes/web/dom)
|
(in-package :scopes/web/dom)
|
||||||
|
|
||||||
|
;;;; basic / common stuff
|
||||||
|
|
||||||
(defvar *output* nil)
|
(defvar *output* nil)
|
||||||
|
|
||||||
(defmacro render (&body body)
|
(defmacro render (&body body)
|
||||||
|
@ -14,19 +16,28 @@
|
||||||
,@body
|
,@body
|
||||||
(get-output-stream-string *output*)))
|
(get-output-stream-string *output*)))
|
||||||
|
|
||||||
|
(defmacro write-nested (start end &body body)
|
||||||
|
`(progn
|
||||||
|
(write-string ,start *output*)
|
||||||
|
,@body
|
||||||
|
(write-line ,end *output*)))
|
||||||
|
|
||||||
|
(defun write-simple (start end val)
|
||||||
|
(write-string start *output*)
|
||||||
|
(write-string val *output*)
|
||||||
|
(write-string end *output*))
|
||||||
|
|
||||||
|
;;;; tag-specific renderers
|
||||||
|
|
||||||
(defun dl (plist)
|
(defun dl (plist)
|
||||||
(write-string "<dl>" *output*)
|
(write-nested "<dl>" "</dl>"
|
||||||
(loop for r on plist by #'cddr do
|
(loop for (key val . r) on plist by #'cddr do
|
||||||
(write-string "<dt>" *output*)
|
(write-simple "<dt>" "</dt>" (string-downcase key))
|
||||||
(write-string (string-downcase (car r)) *output*)
|
(dd val))))
|
||||||
(write-string "</dt>" *output*)
|
|
||||||
(dd (cadr r)))
|
|
||||||
(write-line "</dl>" *output*))
|
|
||||||
|
|
||||||
(defun dd (v)
|
(defun dd (v)
|
||||||
(if (atom v)
|
(if (atom v)
|
||||||
(setf v (list v)))
|
(setf v (list v)))
|
||||||
(dolist (el v)
|
(dolist (el v)
|
||||||
(write-string "<dd>" *output*)
|
(write-simple "<dd>" "</dd>" (string el))))
|
||||||
(write-string (string el) *output*)
|
|
||||||
(write-string "</dd>" *output*)))
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue