Wrap builtin element functions with macro

This commit is contained in:
paku 2024-02-03 22:04:19 +09:00
parent 979489c15b
commit 169a0c1467

View file

@ -84,22 +84,21 @@ When given :ASCII and :ATTR, it's possible to insert html text as a children, e.
(setf (gethash :html *builtin-elements*) t) (setf (gethash :html *builtin-elements*) t)
(defmacro define-builtin-element (element-name) (defmacro define-builtin-element (element-name)
`(progn (let ((%element-name (alexandria:symbolicate '% element-name)))
(defun ,element-name (&rest attrs-and-children) `(progn
(multiple-value-bind (attrs children) (defun ,%element-name (&rest attrs-and-children)
(split-attrs-and-children attrs-and-children) (multiple-value-bind (attrs children)
(make-builtin-element :tag (string-downcase (mkstr ',element-name)) (split-attrs-and-children attrs-and-children)
:attrs attrs :children children))) (make-builtin-element :tag (string-downcase (mkstr ',element-name))
(defun ,(alexandria:symbolicate element-name '*) (attrs children) :attrs attrs :children children)))
(make-builtin-element :tag (string-downcase (mkstr ',element-name)) (defmacro ,element-name (&body attrs-and-children)
:attrs attrs :children children)))) `(,',%element-name ,@attrs-and-children)))))
(defmacro define-and-export-builtin-elements (&rest element-names) (defmacro define-and-export-builtin-elements (&rest element-names)
`(progn `(progn
,@(mapcan (lambda (e) ,@(mapcan (lambda (e)
(list `(define-builtin-element ,e) (list `(define-builtin-element ,e)
`(setf (gethash (make-keyword ',e) *builtin-elements*) t) `(setf (gethash (make-keyword ',e) *builtin-elements*) t)
`(setf (gethash (make-keyword ,(format nil "~a*" e)) *builtin-elements*) t)
`(export ',e))) `(export ',e)))
element-names))) element-names)))