1
0

Add br and hr element helpers (#30)

This commit is contained in:
Hans Raaf 2020-10-23 14:12:47 +02:00 committed by GitHub
parent c99025e6c5
commit c6c5fbd0f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 0 deletions

View File

@ -23,3 +23,11 @@ func Li(children ...g.Node) g.NodeFunc {
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...)
}

View File

@ -37,3 +37,15 @@ func TestP(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")))
})
}

View File

@ -44,6 +44,7 @@ func page(props pageProps) g.Node {
),
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()))),