Wrap user element functions with macro
This commit is contained in:
parent
169a0c1467
commit
3d8fad8e3f
1 changed files with 18 additions and 14 deletions
|
@ -149,20 +149,24 @@ When given :ASCII and :ATTR, it's possible to insert html text as a children, e.
|
||||||
(call-next-method))
|
(call-next-method))
|
||||||
|
|
||||||
(defmacro! define-element (name (&rest args) &body body)
|
(defmacro! define-element (name (&rest args) &body body)
|
||||||
`(defun ,name (&rest ,g!attrs-and-children)
|
(let ((%name (alexandria:symbolicate '% name)))
|
||||||
(multiple-value-bind (,g!attrs ,g!children)
|
`(progn
|
||||||
(split-attrs-and-children ,g!attrs-and-children)
|
(defun ,%name (&rest ,g!attrs-and-children)
|
||||||
(let ((,g!element
|
(multiple-value-bind (,g!attrs ,g!children)
|
||||||
(make-user-element :tag (string-downcase ',name) :attrs ,g!attrs
|
(split-attrs-and-children ,g!attrs-and-children)
|
||||||
:children ,g!children)))
|
(let ((,g!element
|
||||||
(setf (user-element-expander ,g!element)
|
(make-user-element :tag (string-downcase ',name) :attrs ,g!attrs
|
||||||
(lambda (tag attrs children)
|
:children ,g!children)))
|
||||||
(declare (ignorable tag attrs children))
|
(setf (user-element-expander ,g!element)
|
||||||
(let ,(mapcar (lambda (arg)
|
(lambda (tag attrs children)
|
||||||
(list arg `(attr attrs (make-keyword ',arg))))
|
(declare (ignorable tag attrs children))
|
||||||
args)
|
(let ,(mapcar (lambda (arg)
|
||||||
(progn ,@body))))
|
(list arg `(attr attrs (make-keyword ',arg))))
|
||||||
,g!element))))
|
args)
|
||||||
|
(progn ,@body))))
|
||||||
|
,g!element)))
|
||||||
|
(defmacro ,name (&body attrs-and-children)
|
||||||
|
`(,',%name ,@attrs-and-children)))))
|
||||||
|
|
||||||
(defvar *expand-user-element* t)
|
(defvar *expand-user-element* t)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue