From 626fa3fe3eb3714513bb216b33b51892f196d9b0 Mon Sep 17 00:00:00 2001 From: paku Date: Sat, 1 Jun 2024 22:49:15 +0900 Subject: [PATCH] Rename render to render-to-string --- README.md | 7 ++---- src/element.lisp | 6 ++--- src/main.lisp | 2 +- tests/renderer.lisp | 53 ++++++++++++++++++++++++++++----------------- 4 files changed, 39 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 5d829ae..1bd6bf1 100644 --- a/README.md +++ b/README.md @@ -125,12 +125,9 @@ Which generates: ``` -To output HSX as an HTML string, use the `render` method. By default, pretty-printing is enabled, but you can disable it by enabling the `minify` option. - +To output HSX as an HTML string, use the `render-to-string` method. ```lisp -(render (hsx ...)) -; or -(render (hsx ...) :minify t) +(render-to-string (hsx ...)) ``` ## License diff --git a/src/element.lisp b/src/element.lisp index 680b38f..a7291a2 100644 --- a/src/element.lisp +++ b/src/element.lisp @@ -16,7 +16,7 @@ #:element-props #:element-children #:expand-component - #:render)) + #:render-to-string)) (in-package #:hsx/element) ;;;; class definitions @@ -63,9 +63,9 @@ ;;;; methods -(defmethod render ((element element) &key minify) +(defmethod render-to-string ((element element) &key pretty) (with-output-to-string (stream) - (write element :stream stream :pretty (not minify)))) + (write element :stream stream :pretty pretty))) (defmethod print-object ((element tag) stream) (with-accessors ((type element-type) diff --git a/src/main.lisp b/src/main.lisp index d512ff7..9c8472d 100644 --- a/src/main.lisp +++ b/src/main.lisp @@ -6,5 +6,5 @@ #:hsx/hsx) (:export #:hsx #:defcomp - #:render)) + #:render-to-string)) (in-package :hsx) diff --git a/tests/renderer.lisp b/tests/renderer.lisp index 90353c6..9d8fbf0 100644 --- a/tests/renderer.lisp +++ b/tests/renderer.lisp @@ -5,7 +5,7 @@ #:hsx/builtin) (:import-from #:mstrings) (:import-from #:hsx/element - #:render)) + #:render-to-string)) (in-package :hsx-test/renderer) (in-readtable mstrings:mstring-syntax) @@ -14,43 +14,54 @@ (test empty-tag (is (string= "
" - (render (div))))) + (render-to-string (div))))) (test tag-with-props (is (string= "
" - (render (div :prop1 "value1" :prop2 t :prop3 nil))))) + (render-to-string + (div :prop1 "value1" :prop2 t :prop3 nil))))) (test tag-with-children (is (string= "

foo

" - (render (p "foo")))) + (render-to-string (p "foo") :pretty t))) (is (string= #M"

\ foo \

" - (render (p - (span "foo"))))) + (render-to-string + (p + (span "foo")) + :pretty t))) (is (string= #M"

\ foo \ bar \

" - (render (p - "foo" - (span "bar")))))) + (render-to-string + (p + "foo" + (span "bar")) + :pretty t)))) (test tag-with-props-and-children (is (string= "

foo

" - (render (p :prop1 "value1" :prop2 t :prop3 nil - "foo")))) + (render-to-string + (p :prop1 "value1" :prop2 t :prop3 nil + "foo") + :pretty t))) (is (string= #M"

\ foo \ bar \

" - (render (p :prop1 "value1" :prop2 t :prop3 nil - "foo" - (span "bar")))))) + (render-to-string + (p :prop1 "value1" :prop2 t :prop3 nil + "foo" + (span "bar")) + :pretty t)))) (test self-closing-tag (is (string= "" - (render (img :src "/background.png"))))) + (render-to-string + (img :src "/background.png") + :pretty t)))) (test fragment (let ((frg (<> @@ -58,14 +69,16 @@ (li "baz")))) (is (string= #M"
  • bar
  • baz
  • " - (render frg))) + (render-to-string frg :pretty t))) (is (string= #M"" - (render (ul - (li "foo") - frg - (li "brah"))))))) + (render-to-string + (ul + (li "foo") + frg + (li "brah")) + :pretty t)))))