Skip to content

Commit b46aca0

Browse files
committed
Add methods to render each slot
1 parent d203c70 commit b46aca0

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

src/element.lisp

+22-20
Original file line numberDiff line numberDiff line change
@@ -77,45 +77,47 @@
7777
(write element :stream stream :pretty pretty)))
7878

7979
(defmethod print-object ((element tag) stream)
80-
(with-slots (type props children) element
81-
(let ((type-str (string-downcase type))
82-
(props-str (render-props props)))
83-
(if children
84-
(format stream
85-
(if (or (rest children)
86-
(typep (first children) 'element))
87-
"~@<<~a~a>~2I~:@_~<~@{~a~^~:@_~}~:>~0I~:@_</~a>~:>"
88-
"~@<<~a~a>~2I~:_~<~a~^~:@_~:>~0I~_</~a>~:>")
89-
type-str
90-
props-str
91-
(render-children element)
92-
type-str)
93-
(format stream "<~a~a></~a>" type-str props-str type-str)))))
80+
(let ((type (render-type element))
81+
(props (render-props element))
82+
(children (render-children element)))
83+
(if children
84+
(format stream
85+
(if (or (rest children)
86+
(typep (first children) 'element))
87+
"~@<<~a~a>~2I~:@_~<~@{~a~^~:@_~}~:>~0I~:@_</~a>~:>"
88+
"~@<<~a~a>~2I~:_~<~a~^~:@_~:>~0I~_</~a>~:>")
89+
type
90+
props
91+
children
92+
type)
93+
(format stream "<~a~a></~a>" type props type))))
9494

9595
(defmethod print-object ((element self-closing-tag) stream)
96-
(with-slots (type props) element
97-
(format stream "<~a~a>" (string-downcase type) (render-props props))))
96+
(format stream "<~a~a>" (render-type element) (render-props element)))
9897

9998
(defmethod print-object ((element html-tag) stream)
10099
(format stream "<!DOCTYPE html>~%")
101100
(call-next-method))
102101

103102
(defmethod print-object ((element fragment) stream)
104-
(with-slots (children) element
103+
(let ((children (render-children element)))
105104
(if children
106105
(format stream
107106
(if (rest children)
108107
"~<~@{~a~^~:@_~}~:>"
109108
"~<~a~:>")
110-
(render-children element)))))
109+
children))))
111110

112111
(defmethod print-object ((element component) stream)
113112
(print-object (expand-component element) stream))
114113

115-
(defun render-props (props)
114+
(defmethod render-type ((element tag))
115+
(string-downcase (element-type element)))
116+
117+
(defmethod render-props ((element tag))
116118
(with-output-to-string (stream)
117119
(loop
118-
:for (key value) :on props :by #'cddr
120+
:for (key value) :on (element-props element) :by #'cddr
119121
:do (let ((key-str (string-downcase key)))
120122
(if (typep value 'boolean)
121123
(format stream

0 commit comments

Comments
 (0)