all repos — gomponents @ 6c8f0c235287edf7252fe239d4c9beb258c6ff01

HTML components in pure Go

Render to Writer instead of string (#39) The Render function has been changed to take a `Writer` instead of returning a string. This makes it possible to generate documents without having the whole content in memory. This also removes the `gomponents.Write` function, which is now redundant. Furthermore, the `el.Document` function has been changed to only take one child, as multiple children never make sense for it. (It's not even a child, more a sibling.)

Markus Wüstenberg
commit

6c8f0c235287edf7252fe239d4c9beb258c6ff01

parent

92ba5904c1645e6572f5ff1b9d0e0ec629e1afb9

1 file changed, 12 insertions(+), 0 deletions(-)

changed files
M el/elements_test.goel/elements_test.go
@@ -1,6 +1,7 @@
package el_test import ( + "errors" "testing" g "github.com/maragudk/gomponents"
@@ -8,9 +9,20 @@ "github.com/maragudk/gomponents/assert"
"github.com/maragudk/gomponents/el" ) +type erroringWriter struct{} + +func (w *erroringWriter) Write(p []byte) (n int, err error) { + return 0, errors.New("don't want to write") +} + func TestDocument(t *testing.T) { t.Run("returns doctype and children", func(t *testing.T) { assert.Equal(t, `<!doctype html><html />`, el.Document(g.El("html"))) + }) + + t.Run("errors on write error in Render", func(t *testing.T) { + err := el.Document(g.El("html")).Render(&erroringWriter{}) + assert.Error(t, err) }) }