From 8b746ee3c0952c6c17f899f2e18e7cac8760ce0b Mon Sep 17 00:00:00 2001 From: Brandon Dyck Date: Sun, 24 Mar 2019 20:54:09 -0600 Subject: [PATCH] Added more doc comments --- hatmill.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/hatmill.go b/hatmill.go index 14698d8..d011212 100644 --- a/hatmill.go +++ b/hatmill.go @@ -26,11 +26,15 @@ func writeStringsTo(w io.Writer, n *int64, ss ...string) error { return nil } +// Attrib represents an HTML attribute. type Attrib struct { Key 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) { err = writeStringsTo(w, &n, a.Key) if err != nil { @@ -42,6 +46,8 @@ func (a Attrib) WriteTo(w io.Writer) (n int64, err error) { return } +// EmptyElement represents an empty HTML element, that is one that cannot have +// children. type EmptyElement struct { TagName string Attribs []Attrib @@ -49,6 +55,8 @@ type EmptyElement struct { 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) { err = writeStringsTo(w, &n, "<", e.TagName) if err != nil { @@ -73,6 +81,7 @@ func (e EmptyElement) WriteTo(w io.Writer) (n int64, err error) { return } +// ParentElement represents an HTML element that can have children. type ParentElement struct { EmptyElement Children []Term @@ -80,6 +89,8 @@ type ParentElement struct { 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) { n, err = e.EmptyElement.WriteTo(w) if err != nil { @@ -99,10 +110,13 @@ func (e ParentElement) WriteTo(w io.Writer) (n int64, err error) { return } +// Text represents an HTML text node. type Text string 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) { err = writeStringsTo(w, &n, string(t)) return