This commit is contained in:
paku 2024-02-05 02:45:48 +09:00
parent 6050602eec
commit 5afef2e895
3 changed files with 72 additions and 60 deletions

View file

@ -19,15 +19,23 @@
:accessor user-element-expander)))
(defun make-builtin-element (&key tag attrs children)
(make-instance 'builtin-element :tag tag :attrs attrs
(make-instance 'builtin-element
:tag tag
:attrs attrs
:children (escape-children children)))
(defun make-builtin-element-with-prefix (&key tag attrs children prefix)
(make-instance 'builtin-element-with-prefix :tag tag :attrs attrs :prefix prefix
(make-instance 'builtin-element-with-prefix
:tag tag
:attrs attrs
:prefix prefix
:children (escape-children children)))
(defun make-user-element (&rest args &key tag attrs children expander)
(make-instance 'user-element :tag tag :attrs attrs :expander expander
(defun make-user-element (&key tag attrs children expander)
(make-instance 'user-element
:tag tag
:attrs attrs
:expander expander
:children (escape-children children)))
(defmethod user-element-expand-to ((element user-element))
@ -78,7 +86,8 @@ When given :ASCII and :ATTR, it's possible to insert html text as a children, e.
(defun %html (&rest attrs-and-children)
(multiple-value-bind (attrs children)
(split-attrs-and-children attrs-and-children)
(make-builtin-element-with-prefix :tag "html" :attrs attrs
(make-builtin-element-with-prefix :tag "html"
:attrs attrs
:children children
:prefix "<!DOCTYPE html>")))
@ -94,7 +103,8 @@ When given :ASCII and :ATTR, it's possible to insert html text as a children, e.
(multiple-value-bind (attrs children)
(split-attrs-and-children attrs-and-children)
(make-builtin-element :tag (string-downcase (mkstr ',element-name))
:attrs attrs :children children)))
:attrs attrs
:children children)))
(defmacro ,element-name (&body attrs-and-children)
`(,',%element-name ,@attrs-and-children)))))
@ -158,7 +168,8 @@ When given :ASCII and :ATTR, it's possible to insert html text as a children, e.
(multiple-value-bind (,g!attrs ,g!children)
(split-attrs-and-children ,g!attrs-and-children)
(let ((,g!element
(make-user-element :tag (string-downcase ',name) :attrs ,g!attrs
(make-user-element :tag (string-downcase ',name)
:attrs ,g!attrs
:children ,g!children)))
(setf (user-element-expander ,g!element)
(lambda (tag attrs children)

View file

@ -365,7 +365,8 @@
'(:id "c"))
"foo")
"some text")))))
(is (string= "<div id=\"duck5\" style=\"color:blue\">
(is (string=
"<div id=\"duck5\" style=\"color:blue\">
ga ga ga
<img href=\"duck.png\">
</div>"