Fix props->string function

This commit is contained in:
paku 2024-05-28 21:42:28 +09:00
parent e4c0e0f597
commit 1acb065464

View file

@ -72,14 +72,16 @@
(children element-children)) elm (children element-children)) elm
(let ((type-str (string-downcase type))) (let ((type-str (string-downcase type)))
(if children (if children
(format stream (if (rest children) (format stream
(if (rest children)
"~@<<~a~a>~2I~:@_~<~@{~a~^~:@_~}~:>~0I~:@_</~a>~:>" "~@<<~a~a>~2I~:@_~<~@{~a~^~:@_~}~:>~0I~:@_</~a>~:>"
"~@<<~a~a>~2I~:_~<~a~^~:@_~:>~0I~_</~a>~:>") "~@<<~a~a>~2I~:_~<~a~^~:@_~:>~0I~_</~a>~:>")
type-str type-str
(props->string props) (props->string props)
children children
type-str) type-str)
(format stream "<~a~a></~a>" (format stream
"<~a~a></~a>"
type-str type-str
(props->string props) (props->string props)
type-str))))) type-str)))))
@ -88,11 +90,15 @@
(with-output-to-string (stream) (with-output-to-string (stream)
(loop (loop
:for (key value) :on props :by #'cddr :for (key value) :on props :by #'cddr
:do (format stream (if (typep value 'boolean) :do (let ((key-str (string-downcase key)))
(if (typep value 'boolean)
(format stream
"~@[ ~a~]" "~@[ ~a~]"
" ~a=\"~a\"") (and value key-str))
(string-downcase key) (format stream
value)))) " ~a=\"~a\""
key-str
value))))))
(defmethod print-object ((elm html-tag) stream) (defmethod print-object ((elm html-tag) stream)
(format stream "<!DOCTYPE html>~%") (format stream "<!DOCTYPE html>~%")
@ -101,7 +107,8 @@
(defmethod print-object ((elm fragment) stream) (defmethod print-object ((elm fragment) stream)
(with-accessors ((children element-children)) elm (with-accessors ((children element-children)) elm
(if children (if children
(format stream (if (rest children) (format stream
(if (rest children)
"~<~@{~a~^~:@_~}~:>" "~<~@{~a~^~:@_~}~:>"
"~<~a~:>") "~<~a~:>")
children)))) children))))