all repos — gomponents @ a7e24c6cddaafb98091c3989c9da7779eeba30b5

HTML components in pure Go

Minor refactoring and comment changes (#51)

Markus Wüstenberg
commit

a7e24c6cddaafb98091c3989c9da7779eeba30b5

parent

44b18894ac0195767a5882372a011be328000f40

1 file changed, 9 insertions(+), 10 deletions(-)

changed files
M gomponents.gogomponents.go
@@ -57,11 +57,11 @@ return b.String()
} // El creates an element DOM Node with a name and child Nodes. -// Use this if no convenience creator exists. // See https://dev.w3.org/html5/spec-LC/syntax.html#elements-0 for how elements are rendered. // No tags are ever omitted from normal tags, even though it's allowed for elements given at // https://dev.w3.org/html5/spec-LC/syntax.html#optional-tags -// If an element is a void kind, non-attribute nodes are ignored. +// If an element is a void kind, non-attribute children nodes are ignored. +// Use this if no convenience creator exists. func El(name string, children ...Node) NodeFunc { return func(w2 io.Writer) error { w := &statefulWriter{w: w2}
@@ -72,12 +72,11 @@ for _, c := range children {
renderChild(w, c, AttributeType) } + w.Write([]byte(">")) + if isVoidKind(name) { - w.Write([]byte(">")) return w.err } - - w.Write([]byte(">")) for _, c := range children { renderChild(w, c, ElementType)
@@ -135,10 +134,10 @@ }
_, w.err = w.w.Write(p) } -// Attr creates an attr DOM Node. -// If one parameter is passed, it's a name-only attribute (like "required"). -// If two parameters are passed, it's a name-value attribute (like `class="header"`). -// More parameter counts make Attr panic. +// Attr creates an attribute DOM Node with a name and optional value. +// If only a name is passed, it's a name-only (boolean) attribute (like "required"). +// If a name and value are passed, it's a name-value attribute (like `class="header"`). +// More than one value make Attr panic. // Use this if no convenience creator exists. func Attr(name string, value ...string) Node { switch len(value) {
@@ -192,7 +191,7 @@ return err
} } -// Raw creates a raw Node that just Renders the unescaped string t. +// Raw creates a text DOM Node that just Renders the unescaped string t. func Raw(t string) NodeFunc { return func(w io.Writer) error { _, err := w.Write([]byte(t))