From c899a050c06733965dae8ea686daab36e187ba45 Mon Sep 17 00:00:00 2001 From: Markus Wüstenberg Date: Thu, 7 Jan 2021 10:20:03 +0100 Subject: 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`.--- gomponents.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'gomponents.go') diff --git a/gomponents.go b/gomponents.go index 1986a1e..a8b0f95 100644 --- a/gomponents.go +++ b/gomponents.go @@ -62,8 +62,8 @@ func (n NodeFunc) String() string { // 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 @@ func El(name string, children ...Node) NodeFunc { w.Write([]byte("")) return w.err - } + }) } func isVoidKind(name string) bool { @@ -176,27 +176,27 @@ func (a *attr) String() 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 { -- cgit 1.4.1