Introduce Placer interface (#18) When implemented, the `Place` method of the `Placer` interface tells `Render` in `El` where to put a Node. This is relevant for helpers that want to be rendered like attributes, inside the parent element. Fixes the bug where `attr.Classes` was rendered outside the element.
1 file changed, 11 insertions(+), 0 deletions(-)
changed files
M gomponents_test.go → gomponents_test.go
@@ -52,6 +52,12 @@ } }) } +type outsider struct{} + +func (o outsider) Render() string { + return "outsider" +} + func TestEl(t *testing.T) { t.Run("renders an empty element if no children given", func(t *testing.T) { e := g.El("div")@@ -71,6 +77,11 @@ t.Run("renders attributes at the correct place regardless of placement in parameter list", func(t *testing.T) { e := g.El("div", g.El("span"), g.Attr("class", "hat")) assert.Equal(t, `<div class="hat"><span/></div>`, e) + }) + + t.Run("renders outside if node does not implement placer", func(t *testing.T) { + e := g.El("div", outsider{}) + assert.Equal(t, `<div>outsider</div>`, e) }) }