1
0

Compare commits

..

No commits in common. "258100b83303ba82f3986c7a342b1a7590ea533a" and "8e4b1319d12e11fe62725fc30ea01b1f274f8c50" have entirely different histories.

5 changed files with 8 additions and 41 deletions

View File

@ -20,12 +20,10 @@ jobs:
strategy: strategy:
matrix: matrix:
go: go:
- "1.16" - 1.16
- "1.17" - 1.17
- "1.18" - 1.18
- "1.19" - 1.19
- "1.20"
- "1.21"
steps: steps:
- name: Checkout - name: Checkout

View File

@ -25,16 +25,14 @@ Made in 🇩🇰 by [maragu](https://www.maragu.dk), maker of [online Go courses
- Auto-completion - Auto-completion
- Nice formatting with `gofmt` - Nice formatting with `gofmt`
- Simple API that's easy to learn and use (you know most already if you know HTML) - 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 - No external dependencies
## Usage ## Usage
Get the library using `go get`: Get the library using `go get`:
```shell ```shell script
go get github.com/maragudk/gomponents go get -u github.com/maragudk/gomponents
``` ```
The preferred way to use gomponents is with so-called dot-imports (note the dot before the `gomponents/html` import), The preferred way to use gomponents is with so-called dot-imports (note the dot before the `gomponents/html` import),

View File

@ -4,8 +4,8 @@
// to the given writer as a string. // to the given writer as a string.
// //
// All DOM elements and attributes can be created by using the El and Attr functions. // 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, either HTML-escaped or unescaped. // The functions Text, Textf, Raw, and Rawf can be used to create text nodes.
// See also helper functions Group, Map, and If for mapping data to Nodes and inserting them conditionally. // See also helper functions Group, Map, and If.
// //
// For basic HTML elements and attributes, see the package html. // For basic HTML elements and attributes, see the package html.
// For higher-level HTML components, see the package components. // For higher-level HTML components, see the package components.
@ -92,30 +92,6 @@ 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. // renderChild c to the given writer w if the node type is t.
func renderChild(w *statefulWriter, c Node, t NodeType) { func renderChild(w *statefulWriter, c Node, t NodeType) {
if w.err != nil || c == nil { if w.err != nil || c == nil {

View File

@ -16,10 +16,6 @@ func AutoPlay() g.Node {
return g.Attr("autoplay") return g.Attr("autoplay")
} }
func Checked() g.Node {
return g.Attr("checked")
}
func Controls() g.Node { func Controls() g.Node {
return g.Attr("controls") return g.Attr("controls")
} }

View File

@ -14,7 +14,6 @@ func TestBooleanAttributes(t *testing.T) {
"async": Async, "async": Async,
"autofocus": AutoFocus, "autofocus": AutoFocus,
"autoplay": AutoPlay, "autoplay": AutoPlay,
"checked": Checked,
"controls": Controls, "controls": Controls,
"defer": Defer, "defer": Defer,
"disabled": Disabled, "disabled": Disabled,