Added Terms type
This commit is contained in:
parent
d104ad05e1
commit
f9176319ce
@ -4,6 +4,7 @@
|
||||
|
||||
### Added
|
||||
- Changelog
|
||||
- `hatmill.Terms` type for representing lists of nodes
|
||||
|
||||
## [0.0.1] - 2019-04-28
|
||||
|
||||
|
27
hatmill.go
27
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,14 +100,12 @@ 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)
|
||||
var nChildren int64
|
||||
nChildren, err = e.Children.WriteTo(w)
|
||||
n += nChildren
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
err = writeStringsTo(w, &n, "</", e.TagName, ">")
|
||||
return
|
||||
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user