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, 6 insertions(+), 3 deletions(-)

changed files
M attr/attributes.goattr/attributes.go
@@ -3,6 +3,7 @@ // See https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes for a list of attributes.
package attr import ( + "io" "sort" "strings"
@@ -14,7 +15,7 @@ // The attribute value is a sorted, space-separated string of all the map keys,
// for which the corresponding map value is true. type Classes map[string]bool -func (c Classes) Render() string { +func (c Classes) Render(w io.Writer) error { var included []string for c, include := range c { if include {
@@ -22,7 +23,7 @@ included = append(included, c)
} } sort.Strings(included) - return g.Attr("class", strings.Join(included, " ")).Render() + return g.Attr("class", strings.Join(included, " ")).Render(w) } func (c Classes) Place() g.Placement {
@@ -31,5 +32,7 @@ }
// String satisfies fmt.Stringer. func (c Classes) String() string { - return c.Render() + var b strings.Builder + _ = c.Render(&b) + return b.String() }