all repos — gomponents @ c899a050c06733965dae8ea686daab36e187ba45

HTML components in pure Go

Return Node from all helpers instead of NodeFunc (#62) This makes it clearer that the helpers return a `Node` of any kind, and that the type is not important. This also streamlines the API, as attribute helpers already return just `Node`.

Markus Wüstenberg
commit

c899a050c06733965dae8ea686daab36e187ba45

parent

d41c4e5a85362dec7844a9093b43720eb0e70e72

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

changed files
M gomponents.gogomponents.go
@@ -62,8 +62,8 @@ // No tags are ever omitted from normal tags, even though it's allowed for elements given at
// https://dev.w3.org/html5/spec-LC/syntax.html#optional-tags // If an element is a void kind, non-attribute children nodes are ignored. // Use this if no convenience creator exists. -func El(name string, children ...Node) NodeFunc { - return func(w2 io.Writer) error { +func El(name string, children ...Node) Node { + return NodeFunc(func(w2 io.Writer) error { w := &statefulWriter{w: w2} w.Write([]byte("<" + name))
@@ -84,7 +84,7 @@ }
w.Write([]byte("</" + name + ">")) return w.err - } + }) } func isVoidKind(name string) bool {
@@ -176,27 +176,27 @@ return b.String()
} // Text creates a text DOM Node that Renders the escaped string t. -func Text(t string) NodeFunc { - return func(w io.Writer) error { +func Text(t string) Node { + return NodeFunc(func(w io.Writer) error { _, err := w.Write([]byte(template.HTMLEscapeString(t))) return err - } + }) } // Textf creates a text DOM Node that Renders the interpolated and escaped string t. -func Textf(format string, a ...interface{}) NodeFunc { - return func(w io.Writer) error { +func Textf(format string, a ...interface{}) Node { + return NodeFunc(func(w io.Writer) error { _, err := w.Write([]byte(template.HTMLEscapeString(fmt.Sprintf(format, a...)))) return err - } + }) } // Raw creates a text DOM Node that just Renders the unescaped string t. -func Raw(t string) NodeFunc { - return func(w io.Writer) error { +func Raw(t string) Node { + return NodeFunc(func(w io.Writer) error { _, err := w.Write([]byte(t)) return err - } + }) } type group struct {