Added more doc comments

This commit is contained in:
Brandon Dyck 2019-03-24 20:54:09 -06:00
parent 4ecd5ccaf7
commit 8b746ee3c0

View File

@ -26,11 +26,15 @@ func writeStringsTo(w io.Writer, n *int64, ss ...string) error {
return nil return nil
} }
// Attrib represents an HTML attribute.
type Attrib struct { type Attrib struct {
Key string Key string
Value string Value string
} }
// WriteTo writes a to w as an HTML attribute in the form key="value", or
// simply key if value is empty. It returns the number of bytes written and any
// error encountered.
func (a Attrib) WriteTo(w io.Writer) (n int64, err error) { func (a Attrib) WriteTo(w io.Writer) (n int64, err error) {
err = writeStringsTo(w, &n, a.Key) err = writeStringsTo(w, &n, a.Key)
if err != nil { if err != nil {
@ -42,6 +46,8 @@ func (a Attrib) WriteTo(w io.Writer) (n int64, err error) {
return return
} }
// EmptyElement represents an empty HTML element, that is one that cannot have
// children.
type EmptyElement struct { type EmptyElement struct {
TagName string TagName string
Attribs []Attrib Attribs []Attrib
@ -49,6 +55,8 @@ type EmptyElement struct {
func (EmptyElement) isHtml() {} func (EmptyElement) isHtml() {}
// WriteTo writes the HTML markup represented by e to w, returning the number
// of bytes written and any error encountered.
func (e EmptyElement) WriteTo(w io.Writer) (n int64, err error) { func (e EmptyElement) WriteTo(w io.Writer) (n int64, err error) {
err = writeStringsTo(w, &n, "<", e.TagName) err = writeStringsTo(w, &n, "<", e.TagName)
if err != nil { if err != nil {
@ -73,6 +81,7 @@ func (e EmptyElement) WriteTo(w io.Writer) (n int64, err error) {
return return
} }
// ParentElement represents an HTML element that can have children.
type ParentElement struct { type ParentElement struct {
EmptyElement EmptyElement
Children []Term Children []Term
@ -80,6 +89,8 @@ type ParentElement struct {
func (e ParentElement) isHtml() {} func (e ParentElement) isHtml() {}
// WriteTo writes the HTML markup represented by e to w, returning the number
// of bytes written and any error encountered.
func (e ParentElement) WriteTo(w io.Writer) (n int64, err error) { func (e ParentElement) WriteTo(w io.Writer) (n int64, err error) {
n, err = e.EmptyElement.WriteTo(w) n, err = e.EmptyElement.WriteTo(w)
if err != nil { if err != nil {
@ -99,10 +110,13 @@ func (e ParentElement) WriteTo(w io.Writer) (n int64, err error) {
return return
} }
// Text represents an HTML text node.
type Text string type Text string
func (Text) isHtml() {} func (Text) isHtml() {}
// WriteTo writes the contents of t to w, returning the number of bytes written
// and any error encountered.
func (t Text) WriteTo(w io.Writer) (n int64, err error) { func (t Text) WriteTo(w io.Writer) (n int64, err error) {
err = writeStringsTo(w, &n, string(t)) err = writeStringsTo(w, &n, string(t))
return return