Improve render function
This commit is contained in:
parent
5a63bf8154
commit
6a6e3231e7
2 changed files with 21 additions and 15 deletions
|
@ -63,9 +63,10 @@
|
|||
(let ((type-str (string-downcase type)))
|
||||
(if children
|
||||
(format stream
|
||||
(if (rest children)
|
||||
"~@<<~a~a>~2I~:@_~<~@{~a~^~:@_~}~:>~0I~:@_</~a>~:>"
|
||||
"~@<<~a~a>~2I~:_~<~a~^~:@_~:>~0I~_</~a>~:>")
|
||||
(if (and (null (rest children))
|
||||
(typep (first children) 'string))
|
||||
"~@<<~a~a>~2I~:_~<~a~^~:@_~:>~0I~_</~a>~:>"
|
||||
"~@<<~a~a>~2I~:@_~<~@{~a~^~:@_~}~:>~0I~:@_</~a>~:>")
|
||||
type-str
|
||||
(props->string props)
|
||||
children
|
||||
|
|
|
@ -19,29 +19,34 @@
|
|||
(render (hsx (div :prop1 "value1" :prop2 t :prop3 nil))))))
|
||||
|
||||
(test tag-with-children
|
||||
(is (string= "<p>Hello, World!</p>"
|
||||
(render (hsx (p "Hello, World!")))))
|
||||
(is (string= "<p>foo</p>"
|
||||
(render (hsx (p "foo")))))
|
||||
(is (string= #M"<p>
|
||||
\ Hello,
|
||||
\ <span>World!</span>
|
||||
\ <span>foo</span>
|
||||
\</p>"
|
||||
(render (hsx (p
|
||||
"Hello,"
|
||||
(span "World!")))))))
|
||||
(span "foo"))))))
|
||||
(is (string= #M"<p>
|
||||
\ foo
|
||||
\ <span>bar</span>
|
||||
\</p>"
|
||||
(render (hsx (p
|
||||
"foo"
|
||||
(span "bar")))))))
|
||||
|
||||
(test tag-with-props-and-children
|
||||
(is (string= "<p prop1=\"value1\" prop2>Hello, World!</p>"
|
||||
(is (string= "<p prop1=\"value1\" prop2>foo</p>"
|
||||
(render (hsx
|
||||
(p :prop1 "value1" :prop2 t :prop3 nil
|
||||
"Hello, World!")))))
|
||||
"foo")))))
|
||||
(is (string= #M"<p prop1=\"value1\" prop2>
|
||||
\ Hello,
|
||||
\ <span>World!</span>
|
||||
\ foo
|
||||
\ <span>bar</span>
|
||||
\</p>"
|
||||
(render (hsx
|
||||
(p :prop1 "value1" :prop2 t :prop3 nil
|
||||
"Hello,"
|
||||
(span "World!")))))))
|
||||
"foo"
|
||||
(span "bar")))))))
|
||||
|
||||
(test fragment
|
||||
(let ((frg (hsx
|
||||
|
|
Loading…
Reference in a new issue