diff --git a/src/flute.lisp b/src/flute.lisp index 5cb2fe7..989e375 100644 --- a/src/flute.lisp +++ b/src/flute.lisp @@ -158,3 +158,11 @@ When given :ASCII and :ATTR, it's possible to insert html text as a children, e. body (and (symbolp x) (not (keywordp x)) (gethash (make-keyword x) *builtin-elements*)) (find-symbol (string x) :flute)))) + +(defmethod element-string ((element element)) + (with-output-to-string (s) + (write element :stream s))) + +(defmethod elem-str ((element element)) + (with-output-to-string (s) + (write element :stream s :pretty nil))) diff --git a/src/package.lisp b/src/package.lisp index d400e6f..0c151de 100644 --- a/src/package.lisp +++ b/src/package.lisp @@ -49,4 +49,8 @@ :escape-string :utf8-html-escape-char-p :ascii-html-escape-char-p - :attr-value-escape-char-p)) + :attr-value-escape-char-p + + ;;; helper for generate html string + :element-string + :elem-str)) diff --git a/t/flute.lisp b/t/flute.lisp index 88d5f17..17ce834 100644 --- a/t/flute.lisp +++ b/t/flute.lisp @@ -7,6 +7,7 @@ (def-suite escape) (def-suite attr-access) (def-suite user-element) +(def-suite h-macro) (in-suite builtin-element) @@ -111,6 +112,42 @@ (is (equal '((:id . "dog") (:class . "happy")) (attrs-alist (element-attrs div4)))) (is (equal (list div1 div2 div3) (element-children div4))))) +(test builtin-element-html-generation + (let* ((html (html)) + (div0 (div)) + (div1 (div "some text")) + (div2 (div :id "2")) + (div3 (div :id "3" div1 div2 "some other text")) + (div4 (div :id "4" div3 (div :id "5" (a :href "a.html" "a"))))) + (is (string= " +" (element-string html))) + (is (string= "