all repos — gomponents @ 69b0da41dff1813f3939cf4ea09fbbb2d06b7719

HTML components in pure Go

Drop support for Go 1.16 and Go 1.17 (#203) Fixes #184

Markus Wüstenberg
commit

69b0da41dff1813f3939cf4ea09fbbb2d06b7719

parent

c97605aca761985ac45adfe19365801ec2682657

1 file changed, 22 insertions(+), 0 deletions(-)

changed files
M gomponents_test.gogomponents_test.go
@@ -227,6 +227,28 @@ _ = e.Render(os.Stdout)
// Output: <span><button onclick="javascript:alert('Party time!')">Party hats</button> &gt; normal hats.</span> } +func TestMap(t *testing.T) { + t.Run("maps slices to nodes", func(t *testing.T) { + items := []string{"hat", "partyhat", "turtlehat"} + lis := g.Map(items, func(i string) g.Node { + return g.El("li", g.Text(i)) + }) + + list := g.El("ul", lis...) + + assert.Equal(t, `<ul><li>hat</li><li>partyhat</li><li>turtlehat</li></ul>`, list) + }) +} + +func ExampleMap() { + items := []string{"party hat", "super hat"} + e := g.El("ul", g.Group(g.Map(items, func(i string) g.Node { + return g.El("li", g.Text(i)) + }))) + _ = e.Render(os.Stdout) + // Output: <ul><li>party hat</li><li>super hat</li></ul> +} + 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")}