generated from maragudk/template
-
Notifications
You must be signed in to change notification settings - Fork 4
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.