1
0
Commit Graph

20 Commits

Author SHA1 Message Date
Markus Wüstenberg
3bb4e3efea
Add Rawf (#114)
Like `Raw`, but interpolates like `Textf`.
2022-11-03 11:24:26 +01:00
Markus Wüstenberg
f387a71230
Add generic Map implementation (#108)
Instead of waiting for a good time to switch the `Map` implementation,
I've decided to just offer two implementations: one for Go versions
before 1.18, and one for 1.18 and onwards. This is achieved using build
tags in the source files.

This is obviously a breaking change for consumers of this library that
use Go 1.18 and onwards.

See #88
2022-09-22 09:41:06 +02:00
Markus Wüstenberg
4858e5d47d
Mark the assert test helpers as such (#90)
Using `t.Helper()`.

Also move the assert package to be internal.
2021-10-06 20:49:43 +02:00
Markus Wüstenberg
0efc71d6f3
Add javascript alert onclick handler to Raw example (#82)
Makes for fun XSS testing.
2021-06-09 10:56:22 +02:00
Markus Wüstenberg
ba0d83f4fb
Add examples in test files (#80)
These show up in godoc.
2021-06-08 18:12:04 +02:00
Markus Wüstenberg
3e9e00ca0d
Escape Attr values (#77)
Because this can be a place of injection if untrusted data is passed, escape all attribute values.

Fixes #74.
2021-05-18 14:21:53 +02:00
Markus Wüstenberg
f22ce3fb68
Add If helper function (#57)
Used to inline conditional nodes.
2020-12-22 10:53:22 +01:00
Markus Wüstenberg
794c3b26ac
Render correct HTML5 (#44)
Previously, elements of kind void and empty elements generally would be rendered auto-closing (with a final `/` character in the start tag), which is allowed sometimes but arguably wrong. See https://dev.w3.org/html5/spec-LC/syntax.html#end-tags

This created problems with for example `textarea` and `script`, which cannot be auto-closing, or the browser renders it wrong.

Also clarified in the docs that this library outputs HTML5.

Fixes #42.
2020-11-16 12:38:24 +01:00
Markus Wüstenberg
267d40bbea
Add Map function (#40)
`Map` makes it easier to build lists of elements without having to iterate.
2020-11-02 10:59:16 +01:00
Markus Wüstenberg
6c8f0c2352
Render to Writer instead of string (#39)
The Render function has been changed to take a `Writer` instead of returning a string. This makes it possible to generate documents without having the whole content in memory.

This also removes the `gomponents.Write` function, which is now redundant.

Furthermore, the `el.Document` function has been changed to only take one child, as multiple children never make sense for it. (It's not even a child, more a sibling.)
2020-11-02 10:03:05 +01:00
Markus Wüstenberg
92ba5904c1
Remove fmt.Sprintf call in attribute Render (#38)
Just concatenating the strings is much faster.

Before:

```
make benchmark
go test -bench=.
goos: darwin
goarch: amd64
pkg: github.com/maragudk/gomponents
BenchmarkAttr/boolean_attributes-8         	 8194791	       139 ns/op
BenchmarkAttr/name-value_attributes-8      	 5143292	       229 ns/op
PASS
ok  	github.com/maragudk/gomponents	2.841s
```

After:

```
make benchmark
go test -bench=.
goos: darwin
goarch: amd64
pkg: github.com/maragudk/gomponents
BenchmarkAttr/boolean_attributes-8         	16755404	        67.0 ns/op
BenchmarkAttr/name-value_attributes-8      	10208625	       116 ns/op
PASS
ok  	github.com/maragudk/gomponents	2.702s
```
2020-10-29 15:40:14 +01:00
Markus Wüstenberg
3198b25445
Don't render or error on nil children (#32)
This makes it easier to e.g. conditionally skip a component for rendering.
2020-10-23 12:14:23 +02:00
Markus Wüstenberg
6d2fb0eeb1
Add Group function to group Nodes (#29) 2020-10-22 09:07:57 +02:00
Markus Wüstenberg
77b64b1302
Add space before auto-closing element (#20) 2020-09-24 21:55:11 +02:00
Markus Wüstenberg
4c109f9f1d
Introduce Placer interface (#18)
When implemented, the `Place` method of the `Placer` interface tells `Render` in `El` where to put a Node. This is relevant for helpers that want to be rendered like attributes, inside the parent element.

Fixes the bug where `attr.Classes` was rendered outside the element.
2020-09-24 13:19:52 +02:00
Markus Wüstenberg
f27cb0c05f
Add Textf function (#17)
Like Text, but calls fmt.Sprintf before rendering.
2020-09-23 22:10:35 +02:00
Markus Wüstenberg
18b52ffda1
Add a test for attr.String (#12) 2020-09-21 16:07:39 +02:00
Markus Wüstenberg
d78ed7efc7
Add a Write function (#11) 2020-09-21 11:27:37 +02:00
Markus Wüstenberg
f9d584c988
Make NodeFunc and attr implement fmt.Stringer (#6) 2020-09-18 14:38:09 +02:00
Markus Wüstenberg
fc3cc0f0f3 Add first implementation of Node, El, Attr, Text 2020-09-13 22:50:19 +02:00