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, 15 insertions(+), 0 deletions(-)

changed files
M gomponents_test.gogomponents_test.go
@@ -212,6 +212,21 @@ _ = e.Render(os.Stdout)
// Output: <span><button onclick="javascript:alert('Party time!')">Party hats</button> &gt; normal hats.</span> } +func TestRawf(t *testing.T) { + t.Run("renders interpolated and raw text", func(t *testing.T) { + e := g.Rawf("<%v>", "div") + assert.Equal(t, "<div>", e) + }) +} + +func ExampleRawf() { + e := g.El("span", + g.Rawf(`<button onclick="javascript:alert('%v')">Party hats</button> &gt; normal hats.`, "Party time!"), + ) + _ = e.Render(os.Stdout) + // Output: <span><button onclick="javascript:alert('Party time!')">Party hats</button> &gt; normal hats.</span> +} + func TestGroup(t *testing.T) { t.Run("groups multiple nodes into one", func(t *testing.T) { children := []g.Node{g.El("br", g.Attr("id", "hat")), g.El("hr")}