Compare commits
10 Commits
8e4b1319d1
...
258100b833
Author | SHA1 | Date | |
---|---|---|---|
258100b833 | |||
|
d81de8319f | ||
|
214138645b | ||
|
a9890f5337 | ||
|
4248e85def | ||
|
4f9709afcc | ||
|
c129ae8da1 | ||
|
b638b8b078 | ||
|
f26f56cc56 | ||
|
b1f7754ccd |
10
.github/workflows/ci.yml
vendored
10
.github/workflows/ci.yml
vendored
@ -20,10 +20,12 @@ jobs:
|
||||
strategy:
|
||||
matrix:
|
||||
go:
|
||||
- 1.16
|
||||
- 1.17
|
||||
- 1.18
|
||||
- 1.19
|
||||
- "1.16"
|
||||
- "1.17"
|
||||
- "1.18"
|
||||
- "1.19"
|
||||
- "1.20"
|
||||
- "1.21"
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
|
@ -25,14 +25,16 @@ Made in 🇩🇰 by [maragu](https://www.maragu.dk), maker of [online Go courses
|
||||
- Auto-completion
|
||||
- Nice formatting with `gofmt`
|
||||
- Simple API that's easy to learn and use (you know most already if you know HTML)
|
||||
- Useful helpers like `Text` and `Textf` that insert HTML-escaped text, `Map` for mapping data to components,
|
||||
and `If` for conditional rendering.
|
||||
- No external dependencies
|
||||
|
||||
## Usage
|
||||
|
||||
Get the library using `go get`:
|
||||
|
||||
```shell script
|
||||
go get -u github.com/maragudk/gomponents
|
||||
```shell
|
||||
go get github.com/maragudk/gomponents
|
||||
```
|
||||
|
||||
The preferred way to use gomponents is with so-called dot-imports (note the dot before the `gomponents/html` import),
|
||||
|
@ -4,8 +4,8 @@
|
||||
// to the given writer as a string.
|
||||
//
|
||||
// All DOM elements and attributes can be created by using the El and Attr functions.
|
||||
// The functions Text, Textf, Raw, and Rawf can be used to create text nodes.
|
||||
// See also helper functions Group, Map, and If.
|
||||
// The functions Text, Textf, Raw, and Rawf can be used to create text nodes, either HTML-escaped or unescaped.
|
||||
// See also helper functions Group, Map, and If for mapping data to Nodes and inserting them conditionally.
|
||||
//
|
||||
// For basic HTML elements and attributes, see the package html.
|
||||
// For higher-level HTML components, see the package components.
|
||||
@ -92,6 +92,30 @@ func El(name string, children ...Node) Node {
|
||||
})
|
||||
}
|
||||
|
||||
// XMLEl behaves identically to El with the exception that checking for void
|
||||
// elements is disabled. This allows use of elements such as "link" which need
|
||||
// to have children in RSS feeds, for example.
|
||||
func XMLEl(name string, children ...Node) Node {
|
||||
return NodeFunc(func(w2 io.Writer) error {
|
||||
w := &statefulWriter{w: w2}
|
||||
|
||||
w.Write([]byte("<" + name))
|
||||
|
||||
for _, c := range children {
|
||||
renderChild(w, c, AttributeType)
|
||||
}
|
||||
|
||||
w.Write([]byte(">"))
|
||||
|
||||
for _, c := range children {
|
||||
renderChild(w, c, ElementType)
|
||||
}
|
||||
|
||||
w.Write([]byte("</" + name + ">"))
|
||||
return w.err
|
||||
})
|
||||
}
|
||||
|
||||
// renderChild c to the given writer w if the node type is t.
|
||||
func renderChild(w *statefulWriter, c Node, t NodeType) {
|
||||
if w.err != nil || c == nil {
|
||||
|
@ -16,6 +16,10 @@ func AutoPlay() g.Node {
|
||||
return g.Attr("autoplay")
|
||||
}
|
||||
|
||||
func Checked() g.Node {
|
||||
return g.Attr("checked")
|
||||
}
|
||||
|
||||
func Controls() g.Node {
|
||||
return g.Attr("controls")
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ func TestBooleanAttributes(t *testing.T) {
|
||||
"async": Async,
|
||||
"autofocus": AutoFocus,
|
||||
"autoplay": AutoPlay,
|
||||
"checked": Checked,
|
||||
"controls": Controls,
|
||||
"defer": Defer,
|
||||
"disabled": Disabled,
|
||||
|
Reference in New Issue
Block a user