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)
|
||||
|
||||
;;;; basic / common stuff
|
||||
|
||||
(defvar *output* nil)
|
||||
|
||||
(defmacro render (&body body)
|
||||
|
@ -14,19 +16,28 @@
|
|||
,@body
|
||||
(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)
|
||||
(write-string "<dl>" *output*)
|
||||
(loop for r on plist by #'cddr do
|
||||
(write-string "<dt>" *output*)
|
||||
(write-string (string-downcase (car r)) *output*)
|
||||
(write-string "</dt>" *output*)
|
||||
(dd (cadr r)))
|
||||
(write-line "</dl>" *output*))
|
||||
(write-nested "<dl>" "</dl>"
|
||||
(loop for (key val . r) on plist by #'cddr do
|
||||
(write-simple "<dt>" "</dt>" (string-downcase key))
|
||||
(dd val))))
|
||||
|
||||
(defun dd (v)
|
||||
(if (atom v)
|
||||
(setf v (list v)))
|
||||
(dolist (el v)
|
||||
(write-string "<dd>" *output*)
|
||||
(write-string (string el) *output*)
|
||||
(write-string "</dd>" *output*)))
|
||||
(write-simple "<dd>" "</dd>" (string el))))
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue