diff --git a/CHANGELOG.md b/CHANGELOG.md index a808ab9..cbc6289 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Added - Changelog +- `hatmill.Terms` type for representing lists of nodes ## [0.0.1] - 2019-04-28 diff --git a/hatmill.go b/hatmill.go index e1afa08..b1a9744 100644 --- a/hatmill.go +++ b/hatmill.go @@ -85,7 +85,7 @@ func (e VoidElement) WriteTo(w io.Writer) (n int64, err error) { // ParentElement represents an HTML element that can have children. type ParentElement struct { VoidElement - Children []Term + Children Terms } func (e ParentElement) isHtml() {} @@ -100,13 +100,11 @@ func (e ParentElement) WriteTo(w io.Writer) (n int64, err error) { return } - for _, child := range e.Children { - var nCurr int64 - nCurr, err = child.WriteTo(w) - n += int64(nCurr) - if err != nil { - return - } + var nChildren int64 + nChildren, err = e.Children.WriteTo(w) + n += nChildren + if err != nil { + return } err = writeStringsTo(w, &n, "") @@ -139,3 +137,20 @@ func WriteDocument(w io.Writer, root ParentElement) (n int64, err error) { n += nroot return } + +// Terms is a list of HTML nodes. +type Terms []Term + +func (Terms) isHtml() {} + +func (ts Terms) WriteTo(w io.Writer) (n int64, err error) { + for _, t := range ts { + var nCurr int64 + nCurr, err = t.WriteTo(w) + n += int64(nCurr) + if err != nil { + return + } + } + return +}