Documentation ¶
Overview ¶
Package gomponents provides declarative view components in Go, that can render to HTML5. The primary interface is a Node, which has a single function Render, which should render the Node to a string. Furthermore, NodeFunc is a function which implements the Node interface by calling itself on Render. All DOM elements and attributes can be created by using the El and Attr functions. The package also provides a lot of convenience functions for creating elements and attributes with the most commonly used parameters. If they don't suffice, a fallback to El and Attr is always possible.
Index ¶
- Constants
- type Node
- func Attr(name string, value ...string) Node
- func El(name string, children ...Node) Node
- func Group(children []Node) Node
- func If(condition bool, n Node) Node
- func Map(length int, cb func(i int) Node) []Node
- func Raw(t string) Node
- func Text(t string) Node
- func Textf(format string, a ...interface{}) Node
- type NodeFunc
- type NodeType
Constants ¶
const ( ElementType = NodeType(iota) AttributeType )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Node ¶
Node is a DOM node that can Render itself to a io.Writer.
func Attr ¶
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 El ¶
El creates an element DOM Node with a name and child Nodes. 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 children nodes are ignored. Use this if no convenience creator exists.
func Group ¶ added in v0.7.0
Group multiple Nodes into one Node. Useful for concatenation of Nodes in variadic functions. The resulting Node cannot Render directly, trying it will panic. Render must happen through a parent element created with El or a helper.
func If ¶ added in v0.13.0
If condition is true, return the given Node. Otherwise, return nil. This helper function is good for inlining elements conditionally. Example:
El("div", If(showMessage, El("span", "You lost your hat.")), )
func Map ¶ added in v0.11.0
Map something enumerable to a list of Nodes. Example:
items := []string{"hat", "partyhat"} lis := Map(len(items), func(i int) Node { return El("li", Text(items[i])) }) list := El("ul", lis...)
Directories ¶
Path | Synopsis |
---|---|
Package assert provides testing helpers.
|
Package assert provides testing helpers. |
Package components provides high-level components and helpers that are composed of low-level elements and attributes.
|
Package components provides high-level components and helpers that are composed of low-level elements and attributes. |
examples
|
|
Package html provides common HTML elements and attributes.
|
Package html provides common HTML elements and attributes. |