about summary refs log tree commit diff stats
path: root/gomponents.go
diff options
context:
space:
mode:
authorMarkus Wüstenberg2021-01-07 10:20:03 +0100
committerGitHub2021-01-07 10:20:03 +0100
commitc899a050c06733965dae8ea686daab36e187ba45 (patch)
treec1fb78147e22eacd98fef576f39b3009ca6f3899 /gomponents.go
parentd41c4e5a85362dec7844a9093b43720eb0e70e72 (diff)
downloadgomponents-c899a050c06733965dae8ea686daab36e187ba45.tar.lz
gomponents-c899a050c06733965dae8ea686daab36e187ba45.tar.zst
gomponents-c899a050c06733965dae8ea686daab36e187ba45.zip
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`.
Diffstat (limited to 'gomponents.go')
-rw-r--r--gomponents.go24
1 files changed, 12 insertions, 12 deletions
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("</" + name + ">"))
 		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 {