all repos — gomponents @ 3bb4e3efeac645acc02781af59a1399f6f8e0795

HTML components in pure Go

Add Rawf (#114) Like `Raw`, but interpolates like `Textf`.

Markus Wüstenberg
commit

3bb4e3efeac645acc02781af59a1399f6f8e0795

parent

34df17d356afbb6293fc856007f18cc62d112dcb

1 file changed, 10 insertions(+), 2 deletions(-)

changed files
M gomponents.gogomponents.go
@@ -4,7 +4,7 @@ // The primary interface is a Node. It describes a function Render, which should render the Node
// to the given writer as a string. // // All DOM elements and attributes can be created by using the El and Attr functions. -// The functions Text, Textf, and Raw can be used to create text nodes. +// The functions Text, Textf, Raw, and Rawf can be used to create text nodes. // See also helper functions Group, Map, and If. // // For basic HTML elements and attributes, see the package html.
@@ -207,7 +207,7 @@ return err
}) } -// Textf creates a text DOM Node that Renders the interpolated and escaped string t. +// Textf creates a text DOM Node that Renders the interpolated and escaped string format. func Textf(format string, a ...interface{}) Node { return NodeFunc(func(w io.Writer) error { _, err := w.Write([]byte(template.HTMLEscapeString(fmt.Sprintf(format, a...))))
@@ -219,6 +219,14 @@ // Raw creates a text DOM Node that just Renders the unescaped string t.
func Raw(t string) Node { return NodeFunc(func(w io.Writer) error { _, err := w.Write([]byte(t)) + return err + }) +} + +// Rawf creates a text DOM Node that just Renders the interpolated and unescaped string format. +func Rawf(format string, a ...interface{}) Node { + return NodeFunc(func(w io.Writer) error { + _, err := w.Write([]byte(fmt.Sprintf(format, a...))) return err }) }