diff --git a/test/test-web.lisp b/test/test-web.lisp index efa40c1..56b234c 100644 --- a/test/test-web.lisp +++ b/test/test-web.lisp @@ -42,4 +42,5 @@ (deftest test-message (client) (let ((msg (message:create '(:test :data :field :info) :data '(:info "test data")))) - (== (client:send-message client msg) "test data"))) + (== (str:trim (client:send-message client msg)) + "
info
test data
"))) diff --git a/web/dom.lisp b/web/dom.lisp index 71a5556..2c9e1a1 100644 --- a/web/dom.lisp +++ b/web/dom.lisp @@ -16,28 +16,46 @@ ,@body (get-output-stream-string *output*))) -(defmacro write-nested (start end &body body) - `(progn - (write-string ,start *output*) - ,@body - (write-line ,end *output*))) +(defmacro put-string (s) + `(write-string ,s *output*)) -(defun write-simple (start end val) - (write-string start *output*) - (write-string val *output*) - (write-string end *output*)) +(defmacro put-char (c) + `(write-char ,c *output*)) + +(defmacro nested (tag attrs &body body) + `(progn + (start ,tag ,attrs) + ,@body + (end ,tag t))) + +(defun terminal (tag attrs val) + (start tag attrs) + (put-string val) + (end tag)) + +(defun start (tag &optional attrs) + (put-char #\<) + (put-string tag) + (put-char #\>)) + +(defun end (tag &optional newline) + (put-string ") + (if newline + (put-char #\Newline))) ;;;; tag-specific renderers (defun dl (plist) - (write-nested "
" "
" + (nested "dl" nil (loop for (key val . r) on plist by #'cddr do - (write-simple "
" "
" (string-downcase key)) + (terminal "dt" nil (string-downcase key)) (dd val)))) (defun dd (v) (if (atom v) (setf v (list v))) (dolist (el v) - (write-simple "
" "
" (string el)))) + (terminal "dd" nil (string el))))