| Commit message (Collapse) | Author | Age | Lines |
| |
|
| |
|
|
|
| |
It didn't actually work the way it was written.
|
|
|
|
|
|
|
|
|
|
| |
This is a breaking change to move gomponents to my own import namespace.
I will obviously be careful with this, test it out in all kinds of
scenarios, release betas, etc. But otherwise, because the `Node`
interface is so simple and has basically never changed, I don't think
this will break much. 🤞
Fixes #200
|
|
|
|
| |
For getting the slice index using a counter outside the closure.
|
|
|
|
|
|
|
|
|
|
|
|
| |
This changes `Group` to be a type instead of a function, which means it
can support both grouping `[]Node` as well as doing variadic-ish slice things
like `Group{n1, n2}`.
This also means that `Map` can just return a `Group`.
Special thanks to @deitrix for this simple and elegant solution that,
for some reason or another, has had me perplexed for a long time.
Fixes #201.
|
|
|
| |
Fixes #184
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This change makes the result of `Group` renderable directly, instead of
panicking, with the important caveat that root-level attributes are
_ignored_. I don't think this will give problems in practice, as the
main use case for rendering `Group` is basically to return root-level
elements to the client using something like HTMX.
I tried adding a `Fragment`, but it was weird and confusing having two
functions (`Group` and `Fragment`) do essentially the same thing, the
only difference being whether the argument was a slice of `Node`s or
varargs.
Fixes #162
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
I ran into some situation where I want to conditionally render a node if
some variable is not nil and obviously I got a panic
```go
// package viewmodels
type SomePage struct {
s *string
}
// package views
func SomePage (vm viewmodels.SomePage) g,Node {
return Div(
If(vm.s == nil, Text("s is nil"),
If(vm.s !- nil, Text("s is " + vm.s), // this will panic when `s` is nil
)
}
```
In this situation, go will interpret the code of the second `if`
regardless of the condition because the code itself is not in a
condition.
This PR introduces a new `Iff` helper that accepts a callback. The
callback content is only interpreted when it's called, making the code
safe:
```go
// package viewmodels
type SomePage struct {
s *string
}
// package views
func SomePage (vm viewmodels.SomePage) g,Node {
return Div(
Iff(vm.s == nil, func () g.Node { return Text("s is nil") },
Iff(vm.s !- nil, func () g.Node { return Text("s is " + vm.s) },
)
}
```
I'm aware of the `Lazy` effort on the side, but I guess this is no a
breaking change and can still exist in addition to the `Lazy` effort.
Co-authored-by: Markus Wüstenberg <markus@maragu.dk>
|
|
|
| |
Like `Raw`, but interpolates like `Textf`.
|
|
|
|
|
|
|
|
|
|
|
| |
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
|
|
|
|
|
| |
Using `t.Helper()`.
Also move the assert package to be internal.
|
|
|
| |
Makes for fun XSS testing.
|
|
|
| |
These show up in godoc.
|
|
|
|
|
| |
Because this can be a place of injection if untrusted data is passed, escape all attribute values.
Fixes #74.
|
|
|
| |
Used to inline conditional nodes.
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
| |
`Map` makes it easier to build lists of elements without having to iterate.
|
|
|
|
|
|
|
| |
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.)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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
```
|
|
|
| |
This makes it easier to e.g. conditionally skip a component for rendering.
|
| |
|
| |
|
|
|
|
|
| |
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.
|
|
|
| |
Like Text, but calls fmt.Sprintf before rendering.
|
| |
|
| |
|
| |
|
|
|