From 98d22460172374f6d329b21bdfa9fda1883e6e15 Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Sat, 13 Jul 2024 12:46:23 +0200 Subject: [PATCH] web/dom: improvements (but still work in progress) --- web/dom.lisp | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/web/dom.lisp b/web/dom.lisp index fdc2158..71a5556 100644 --- a/web/dom.lisp +++ b/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 "
" *output*) - (loop for r on plist by #'cddr do - (write-string "
" *output*) - (write-string (string-downcase (car r)) *output*) - (write-string "
" *output*) - (dd (cadr r))) - (write-line "
" *output*)) + (write-nested "
" "
" + (loop for (key val . r) on plist by #'cddr do + (write-simple "
" "
" (string-downcase key)) + (dd val)))) (defun dd (v) (if (atom v) (setf v (list v))) (dolist (el v) - (write-string "
" *output*) - (write-string (string el) *output*) - (write-string "
" *output*))) + (write-simple "
" "
" (string el)))) +