generated from maragudk/template
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Boost, Get, and Post attributes (#1)
- Loading branch information
Showing
7 changed files
with
96 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
# template | ||
# gomponents-htmx | ||
|
||
[![GoDoc](https://pkg.go.dev/badge/github.com/maragudk/gomponents-htmx)](https://pkg.go.dev/github.com/maragudk/gomponents-htmx) | ||
[![CI](https://github.com/maragudk/gomponents-htmx/actions/workflows/ci.yml/badge.svg)](https://github.com/maragudk/gomponents-htmx/actions/workflows/ci.yml) | ||
|
||
[HTMX](https://htmx.org) attributes and helpers for [gomponents](https://www.gomponents.com). | ||
|
||
Made in 🇩🇰 by [maragu](https://www.maragu.dk/), maker of [online Go courses](https://www.golang.dk/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
module template | ||
module github.com/maragudk/gomponents-htmx | ||
|
||
go 1.19 | ||
go 1.20 | ||
|
||
require github.com/maragudk/gomponents v0.20.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
github.com/maragudk/gomponents v0.20.1 h1:TeJY1fXEcfUvzmvjeUgxol42dvkYMggK1c0V67crWWs= | ||
github.com/maragudk/gomponents v0.20.1/go.mod h1:nHkNnZL6ODgMBeJhrZjkMHVvNdoYsfmpKB2/hjdQ0Hg= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Package htmx provides HTMX attributes and helpers for gomponents. | ||
// See https://htmx.org/ | ||
package htmx | ||
|
||
import ( | ||
g "github.com/maragudk/gomponents" | ||
) | ||
|
||
// Boost for links and forms. | ||
// See https://htmx.org/attributes/hx-boost | ||
func Boost(v string) g.Node { | ||
return attr("boost", v) | ||
} | ||
|
||
// Get the url. | ||
// See https://htmx.org/attributes/hx-get | ||
func Get(url string) g.Node { | ||
return attr("get", url) | ||
} | ||
|
||
// Post to the url. | ||
// See https://htmx.org/attributes/hx-post | ||
func Post(url string) g.Node { | ||
return attr("post", url) | ||
} | ||
|
||
func attr(name, value string) g.Node { | ||
return g.Attr("hx-"+name, value) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package htmx_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
g "github.com/maragudk/gomponents" | ||
|
||
. "github.com/maragudk/gomponents-htmx" | ||
"github.com/maragudk/gomponents-htmx/internal/assert" | ||
) | ||
|
||
func TestAttributes(t *testing.T) { | ||
cases := map[string]func(string) g.Node{ | ||
"boost": Boost, | ||
"get": Get, | ||
"post": Post, | ||
} | ||
|
||
for name, fn := range cases { | ||
t.Run(fmt.Sprintf(`should output hx-%v="hat"`, name), func(t *testing.T) { | ||
n := g.El("div", fn("hat")) | ||
assert.Equal(t, fmt.Sprintf(`<div hx-%v="hat"></div>`, name), n) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Package assert provides testing helpers. | ||
package assert | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
g "github.com/maragudk/gomponents" | ||
) | ||
|
||
// Equal checks for equality between the given expected string and the rendered Node string. | ||
func Equal(t *testing.T, expected string, actual g.Node) { | ||
t.Helper() | ||
|
||
var b strings.Builder | ||
_ = actual.Render(&b) | ||
if expected != b.String() { | ||
t.Fatalf(`expected "%v" but got "%v"`, expected, b.String()) | ||
} | ||
} | ||
|
||
// Error checks for a non-nil error. | ||
func Error(t *testing.T, err error) { | ||
t.Helper() | ||
|
||
if err == nil { | ||
t.Fatal("error is nil") | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.