Skip to content

Commit

Permalink
Merge pull request #20 from oetherington/node-array-dom-node
Browse files Browse the repository at this point in the history
Allow `[]Node` as a `DomNode` child
  • Loading branch information
oetherington authored Mar 24, 2023
2 parents d959518 + 5d13d20 commit 886bbca
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions domnode.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ func NewDomNode(tag Tag, args []any) DomNode {
node.Attrs[value.Key] = value.Value
case Node:
node.Children = append(node.Children, value)
case []Node:
node.Children = append(node.Children, value...)
case ClassName, Classes:
node.Attrs["class"] = string(ClassNames(node.Attrs["class"], value))
case string:
Expand Down
6 changes: 6 additions & 0 deletions domnode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ func TestRenderDomNodeWithChildren(t *testing.T) {
assertEqual(t, "<div>bar</div>", result)
}

func TestRenderDomNodeWithChildrenArray(t *testing.T) {
node := NewDomNode("div", []any{[]Node{Text("bar")}})
result := RenderHtmlOpts(node, true, nil)
assertEqual(t, "<div>bar</div>", result)
}

func TestRenderDomNodeWithSingleAttribute(t *testing.T) {
node := NewDomNode("div", []any{Attr{"foo", "bar"}})
result := RenderHtmlOpts(node, true, nil)
Expand Down

0 comments on commit 886bbca

Please sign in to comment.