|
77 | 77 | (write element :stream stream :pretty pretty)))
|
78 | 78 |
|
79 | 79 | (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)))) |
94 | 94 |
|
95 | 95 | (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))) |
98 | 97 |
|
99 | 98 | (defmethod print-object ((element html-tag) stream)
|
100 | 99 | (format stream "<!DOCTYPE html>~%")
|
101 | 100 | (call-next-method))
|
102 | 101 |
|
103 | 102 | (defmethod print-object ((element fragment) stream)
|
104 |
| - (with-slots (children) element |
| 103 | + (let ((children (render-children element))) |
105 | 104 | (if children
|
106 | 105 | (format stream
|
107 | 106 | (if (rest children)
|
108 | 107 | "~<~@{~a~^~:@_~}~:>"
|
109 | 108 | "~<~a~:>")
|
110 |
| - (render-children element))))) |
| 109 | + children)))) |
111 | 110 |
|
112 | 111 | (defmethod print-object ((element component) stream)
|
113 | 112 | (print-object (expand-component element) stream))
|
114 | 113 |
|
115 |
| -(defun render-props (props) |
| 114 | +(defmethod render-type ((element tag)) |
| 115 | + (string-downcase (element-type element))) |
| 116 | + |
| 117 | +(defmethod render-props ((element tag)) |
116 | 118 | (with-output-to-string (stream)
|
117 | 119 | (loop
|
118 |
| - :for (key value) :on props :by #'cddr |
| 120 | + :for (key value) :on (element-props element) :by #'cddr |
119 | 121 | :do (let ((key-str (string-downcase key)))
|
120 | 122 | (if (typep value 'boolean)
|
121 | 123 | (format stream
|
|
0 commit comments