Add br and hr element helpers (#30)
Hans Raaf hara@oderwat.de
Fri, 23 Oct 2020 14:12:47 +0200
3 files changed, 21 insertions(+), 0 deletions(-)
M el/content.go → el/content.go
@@ -23,3 +23,11 @@ func P(children ...g.Node) g.NodeFunc { return g.El("p", children...) } + +func Br(children ...g.Node) g.NodeFunc { + return g.El("br", children...) +} + +func Hr(children ...g.Node) g.NodeFunc { + return g.El("hr", children...) +}
M el/content_test.go → el/content_test.go
@@ -37,3 +37,15 @@ t.Run("returns a p element", func(t *testing.T) { assert.Equal(t, `<p>hat</p>`, el.P(g.Text("hat"))) }) } + +func TestBr(t *testing.T) { + t.Run("returns a br element in context", func(t *testing.T) { + assert.Equal(t, `<p>Test<br />Me</p>`, el.P(g.Text("Test"), el.Br(), g.Text("Me"))) + }) +} + +func TestHr(t *testing.T) { + t.Run("returns a hr element with class", func(t *testing.T) { + assert.Equal(t, `<hr class="test" />`, el.Hr(g.Attr("class", "test"))) + }) +}
M examples/simple/simple.go → examples/simple/simple.go
@@ -44,6 +44,7 @@ ), ), el.Body( navbar(navbarProps{path: props.path}), + el.Hr(), el.H1(props.title), el.P(g.Text(fmt.Sprintf("Welcome to the page at %v.", props.path))), el.P(g.Text(fmt.Sprintf("Rendered at %v", time.Now()))),