web/dom: more pre-defined elemnts; simplify dlist accordingly
This commit is contained in:
parent
64dea8453d
commit
464bbfde65
1 changed files with 15 additions and 8 deletions
23
web/dom.lisp
23
web/dom.lisp
|
@ -40,6 +40,8 @@
|
|||
(put c))
|
||||
(end tag))))
|
||||
|
||||
;;;; void element (e.g. <input ...>): no body, no explicit closing of tag
|
||||
|
||||
(defclass void-element (element) ())
|
||||
|
||||
(defun void-element (tag attrs)
|
||||
|
@ -48,27 +50,32 @@
|
|||
(defmethod put ((el void-element))
|
||||
(start (tag el) (attrs el)))
|
||||
|
||||
;;;; automatically define standard HTML elements
|
||||
|
||||
(defmacro make-elements (tags &optional (elem-fn 'elem))
|
||||
`(progn
|
||||
,@(mapcar (lambda (tag) ;`(make-element ,tag)) tags)))
|
||||
`(defun ,tag (attrs &rest body)
|
||||
(funcall #',elem-fn ',tag attrs body)))
|
||||
(funcall (function ,elem-fn) ',tag attrs body)))
|
||||
tags)))
|
||||
|
||||
(eval-when (:compile-toplevel :load-toplevel :execute)
|
||||
(make-elements (div label)))
|
||||
(make-elements (a dd div dl dt label)))
|
||||
|
||||
(eval-when (:compile-toplevel :load-toplevel :execute)
|
||||
(make-elements (br input) :void-element))
|
||||
|
||||
;;;; elements with specific functionality
|
||||
|
||||
(defun dlist (attrs plist)
|
||||
(elem :dl attrs
|
||||
(dl attrs
|
||||
(util:loop-plist plist key val append
|
||||
(cons (element :dt nil (string-downcase key)) (dds nil val)))))
|
||||
(cons (dt nil (string-downcase key)) (dds nil val)))))
|
||||
|
||||
(defun dds (attrs cont)
|
||||
(if (atom cont)
|
||||
(list (element :dd attrs cont))
|
||||
(mapcar #'(lambda (x) (element :dd nil x)) cont)))
|
||||
(list (dd attrs cont))
|
||||
(mapcar #'(lambda (x) (dd nil x)) cont)))
|
||||
|
||||
;;;; rendering
|
||||
|
||||
|
@ -84,8 +91,8 @@
|
|||
(put-string tag)
|
||||
(put-attrs attrs)
|
||||
(if close
|
||||
(put-char #\/))
|
||||
(put-char #\>))
|
||||
(put-string " />")
|
||||
(put-char #\>)))
|
||||
|
||||
(defun end (tag)
|
||||
(put-string "</")
|
||||
|
|
Loading…
Add table
Reference in a new issue