Added Terms type

This commit is contained in:
Brandon Dyck 2019-04-28 15:27:46 -06:00
parent d104ad05e1
commit f9176319ce
2 changed files with 24 additions and 8 deletions

View File

@ -4,6 +4,7 @@
### Added ### Added
- Changelog - Changelog
- `hatmill.Terms` type for representing lists of nodes
## [0.0.1] - 2019-04-28 ## [0.0.1] - 2019-04-28

View File

@ -85,7 +85,7 @@ func (e VoidElement) WriteTo(w io.Writer) (n int64, err error) {
// ParentElement represents an HTML element that can have children. // ParentElement represents an HTML element that can have children.
type ParentElement struct { type ParentElement struct {
VoidElement VoidElement
Children []Term Children Terms
} }
func (e ParentElement) isHtml() {} func (e ParentElement) isHtml() {}
@ -100,13 +100,11 @@ func (e ParentElement) WriteTo(w io.Writer) (n int64, err error) {
return return
} }
for _, child := range e.Children { var nChildren int64
var nCurr int64 nChildren, err = e.Children.WriteTo(w)
nCurr, err = child.WriteTo(w) n += nChildren
n += int64(nCurr) if err != nil {
if err != nil { return
return
}
} }
err = writeStringsTo(w, &n, "</", e.TagName, ">") err = writeStringsTo(w, &n, "</", e.TagName, ">")
@ -139,3 +137,20 @@ func WriteDocument(w io.Writer, root ParentElement) (n int64, err error) {
n += nroot n += nroot
return 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
}