1
0
Commit Graph

23 Commits

Author SHA1 Message Date
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
c899a050c0
Return Node from all helpers instead of NodeFunc (#62)
This makes it clearer that the helpers return a `Node` of any kind, and that the type is not important.

This also streamlines the API, as attribute helpers already return just `Node`.
2021-01-07 10:20:03 +01: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
a7e24c6cdd
Minor refactoring and comment changes (#51) 2020-12-08 21:59:47 +01:00
Markus Wüstenberg
108f8d9ba5
Add NodeType which replaces the Placer interface (#45)
The `Placer` interface was a weird interface that tried to abstract away nodes being elements or attributes, but it doesn't really make sense. Now `Nodes` just have a `NodeType`.
2020-11-16 12:58:42 +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
f277d1942e
Pass attributes as pointers (#37) 2020-10-29 13:07:22 +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
f2a2b94970
Update package doc for gomponents (#28) 2020-10-21 22:17:27 +02:00
Markus Wüstenberg
42433a4a09
Use HTMLEscapeString in Textf (#27) 2020-10-21 21:59:52 +02:00
Markus Wüstenberg
83faa4caa3
Use HTMLEscapeString (#24)
HTMLEscaper is not needed with strings.
2020-09-25 13:39:55 +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
d78ed7efc7
Add a Write function (#11) 2020-09-21 11:27:37 +02:00
Markus Wüstenberg
02d963de10
Don't render twice with children (#9) 2020-09-21 11:14: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
ca80dce018
Add package documentation (#1) 2020-09-14 10:47:14 +02:00
Markus Wüstenberg
fc3cc0f0f3 Add first implementation of Node, El, Attr, Text 2020-09-13 22:50:19 +02:00