Improve hsx macro
This commit is contained in:
parent
e394addcd3
commit
3a6475df6a
1 changed files with 16 additions and 17 deletions
33
src/hsx.lisp
33
src/hsx.lisp
|
@ -19,6 +19,17 @@
|
||||||
(parse-body body)
|
(parse-body body)
|
||||||
`(create-element ,',element-type (list ,@props) ,@children))))
|
`(create-element ,',element-type (list ,@props) ,@children))))
|
||||||
|
|
||||||
|
(defun parse-body (body)
|
||||||
|
(if (keywordp (first body))
|
||||||
|
(loop :for thing :on body :by #'cddr
|
||||||
|
:for (k v) := thing
|
||||||
|
:when (and (keywordp k) v)
|
||||||
|
:append (list k v) :into props
|
||||||
|
:when (not (keywordp k))
|
||||||
|
:return (values props thing)
|
||||||
|
:finally (return (values props nil)))
|
||||||
|
(values nil body)))
|
||||||
|
|
||||||
(defparameter *builtin-elements* (make-hash-table))
|
(defparameter *builtin-elements* (make-hash-table))
|
||||||
|
|
||||||
(defmacro define-and-export-builtin-elements (&body names)
|
(defmacro define-and-export-builtin-elements (&body names)
|
||||||
|
@ -52,26 +63,14 @@
|
||||||
,@body)
|
,@body)
|
||||||
(defhsx ,name (fdefinition ',%name)))))
|
(defhsx ,name (fdefinition ',%name)))))
|
||||||
|
|
||||||
(defun parse-body (body)
|
|
||||||
(if (keywordp (first body))
|
|
||||||
(loop :for thing :on body :by #'cddr
|
|
||||||
:for (k v) := thing
|
|
||||||
:when (and (keywordp k) v)
|
|
||||||
:append (list k v) :into props
|
|
||||||
:when (not (keywordp k))
|
|
||||||
:return (values props thing)
|
|
||||||
:finally (return (values props nil)))
|
|
||||||
(values nil body)))
|
|
||||||
|
|
||||||
|
|
||||||
;;;; hsx macro to find hsx symbols
|
;;;; hsx macro to find hsx symbols
|
||||||
|
|
||||||
(defmacro hsx (&body body)
|
(defmacro hsx (form)
|
||||||
`(progn
|
(modify-first-leaves form
|
||||||
,@(modify-first-leaves body
|
#'builtin-element-p
|
||||||
#'builtin-element-p
|
(lambda (node)
|
||||||
(lambda (node)
|
(find-symbol (string node) :hsx/hsx))))
|
||||||
(find-symbol (string node) :hsx/hsx)))))
|
|
||||||
|
|
||||||
(defun modify-first-leaves (tree test result)
|
(defun modify-first-leaves (tree test result)
|
||||||
(if tree
|
(if tree
|
||||||
|
|
Loading…
Reference in a new issue