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
- Changelog
- `hatmill.Terms` type for representing lists of nodes
## [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.
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, "</", e.TagName, ">")
@ -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
}