Skip to content

Commit b85d5b8

Browse files
Move to maragu.dev/gomponents-htmx namespace (#16)
Also upgrade to maragu.dev/[email protected]
1 parent 15d81a4 commit b85d5b8

File tree

8 files changed

+68
-57
lines changed

8 files changed

+68
-57
lines changed

README.md

+30-26
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<img src="logo.png" alt="Logo" width="300" align="right">
44

5-
[![GoDoc](https://pkg.go.dev/badge/github.com/maragudk/gomponents-htmx)](https://pkg.go.dev/github.com/maragudk/gomponents-htmx)
5+
[![GoDoc](https://pkg.go.dev/badge/maragu.dev/gomponents-htmx)](https://pkg.go.dev/maragu.dev/gomponents-htmx)
66
[![CI](https://github.com/maragudk/gomponents-htmx/actions/workflows/ci.yml/badge.svg)](https://github.com/maragudk/gomponents-htmx/actions/workflows/ci.yml)
77

88
[HTMX](https://htmx.org) attributes and helpers for [gomponents](https://www.gomponents.com).
@@ -14,7 +14,7 @@ Does your company depend on this project? [Contact me at [email protected]](mailt
1414
## Usage
1515

1616
```shell
17-
go get github.com/maragudk/gomponents-htmx
17+
go get maragu.dev/gomponents-htmx@v1.0.0-beta1
1818
```
1919

2020
```go
@@ -26,12 +26,13 @@ import (
2626
"net/http"
2727
"time"
2828

29-
g "github.com/maragudk/gomponents"
30-
c "github.com/maragudk/gomponents/components"
31-
. "github.com/maragudk/gomponents/html"
32-
ghttp "github.com/maragudk/gomponents/http"
33-
hx "github.com/maragudk/gomponents-htmx"
34-
hxhttp "github.com/maragudk/gomponents-htmx/http"
29+
. "maragu.dev/gomponents"
30+
. "maragu.dev/gomponents/components"
31+
. "maragu.dev/gomponents/html"
32+
. "maragu.dev/gomponents/http"
33+
34+
hx "maragu.dev/gomponents-htmx"
35+
hxhttp "maragu.dev/gomponents-htmx/http"
3536
)
3637

3738
func main() {
@@ -43,11 +44,11 @@ func main() {
4344
func start() error {
4445
now := time.Now()
4546
mux := http.NewServeMux()
46-
mux.HandleFunc("/", ghttp.Adapt(func(w http.ResponseWriter, r *http.Request) (g.Node, error) {
47+
mux.HandleFunc("/", Adapt(func(w http.ResponseWriter, r *http.Request) (Node, error) {
4748
if r.Method == http.MethodPost && hxhttp.IsBoosted(r.Header) {
4849
now = time.Now()
4950

50-
hxhttp.SetPushURL(w.Header(), "/?time="+now.Format(timeFormat))
51+
hxhttp.SetPushURL(w.Header(), "/?time="+now.Format(timeOnly))
5152

5253
return partial(now), nil
5354
}
@@ -61,22 +62,29 @@ func start() error {
6162
return nil
6263
}
6364

64-
const timeFormat = "15:04:05"
65+
const timeOnly = "15:04:05"
66+
67+
func page(now time.Time) Node {
68+
return HTML5(HTML5Props{
69+
Title: now.Format(timeOnly),
6570

66-
func page(now time.Time) g.Node {
67-
return c.HTML5(c.HTML5Props{
68-
Title: now.Format(timeFormat),
69-
Head: []g.Node{
71+
Head: []Node{
7072
Script(Src("https://cdn.tailwindcss.com?plugins=forms,typography")),
7173
Script(Src("https://unpkg.com/htmx.org")),
7274
},
73-
Body: []g.Node{
75+
76+
Body: []Node{
7477
Div(Class("max-w-7xl mx-auto p-4 prose lg:prose-lg xl:prose-xl"),
75-
H1(g.Text(`gomponents + HTMX`)),
76-
P(g.Textf(`Time at last full page refresh was %v.`, now.Format(timeFormat))),
78+
H1(Text(`gomponents + HTMX`)),
79+
80+
P(Textf(`Time at last full page refresh was %v.`, now.Format(timeOnly))),
81+
7782
partial(now),
78-
FormEl(Method("post"), Action("/"), hx.Boost("true"), hx.Target("#partial"), hx.Swap("outerHTML"),
79-
Button(Type("submit"), g.Text(`Update time`),
83+
84+
Form(Method("post"), Action("/"),
85+
hx.Boost("true"), hx.Target("#partial"), hx.Swap("outerHTML"),
86+
87+
Button(Type("submit"), Text(`Update time`),
8088
Class("rounded-md border border-transparent bg-orange-600 px-4 py-2 text-sm font-medium text-white shadow-sm hover:bg-orange-700 focus:outline-none focus:ring-2 focus:ring-orange-500 focus:ring-offset-2"),
8189
),
8290
),
@@ -85,11 +93,7 @@ func page(now time.Time) g.Node {
8593
})
8694
}
8795

88-
func partial(now time.Time) g.Node {
89-
return P(ID("partial"), g.Textf(`Time was last updated at %v.`, now.Format(timeFormat)))
96+
func partial(now time.Time) Node {
97+
return P(ID("partial"), Textf(`Time was last updated at %v.`, now.Format(timeOnly)))
9098
}
91-
9299
```
93-
94-
95-
Made in 🇩🇰 by [maragu](https://www.maragu.dk/), maker of [online Go courses](https://www.golang.dk/).

cmd/example/main.go

+27-20
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import (
66
"net/http"
77
"time"
88

9-
g "github.com/maragudk/gomponents"
10-
c "github.com/maragudk/gomponents/components"
11-
. "github.com/maragudk/gomponents/html"
12-
ghttp "github.com/maragudk/gomponents/http"
9+
. "maragu.dev/gomponents"
10+
. "maragu.dev/gomponents/components"
11+
. "maragu.dev/gomponents/html"
12+
. "maragu.dev/gomponents/http"
1313

14-
hx "github.com/maragudk/gomponents-htmx"
15-
hxhttp "github.com/maragudk/gomponents-htmx/http"
14+
hx "maragu.dev/gomponents-htmx"
15+
hxhttp "maragu.dev/gomponents-htmx/http"
1616
)
1717

1818
func main() {
@@ -24,11 +24,11 @@ func main() {
2424
func start() error {
2525
now := time.Now()
2626
mux := http.NewServeMux()
27-
mux.HandleFunc("/", ghttp.Adapt(func(w http.ResponseWriter, r *http.Request) (g.Node, error) {
27+
mux.HandleFunc("/", Adapt(func(w http.ResponseWriter, r *http.Request) (Node, error) {
2828
if r.Method == http.MethodPost && hxhttp.IsBoosted(r.Header) {
2929
now = time.Now()
3030

31-
hxhttp.SetPushURL(w.Header(), "/?time="+now.Format(timeFormat))
31+
hxhttp.SetPushURL(w.Header(), "/?time="+now.Format(timeOnly))
3232

3333
return partial(now), nil
3434
}
@@ -42,22 +42,29 @@ func start() error {
4242
return nil
4343
}
4444

45-
const timeFormat = "15:04:05"
45+
const timeOnly = "15:04:05"
4646

47-
func page(now time.Time) g.Node {
48-
return c.HTML5(c.HTML5Props{
49-
Title: now.Format(timeFormat),
50-
Head: []g.Node{
47+
func page(now time.Time) Node {
48+
return HTML5(HTML5Props{
49+
Title: now.Format(timeOnly),
50+
51+
Head: []Node{
5152
Script(Src("https://cdn.tailwindcss.com?plugins=forms,typography")),
5253
Script(Src("https://unpkg.com/htmx.org")),
5354
},
54-
Body: []g.Node{
55+
56+
Body: []Node{
5557
Div(Class("max-w-7xl mx-auto p-4 prose lg:prose-lg xl:prose-xl"),
56-
H1(g.Text(`gomponents + HTMX`)),
57-
P(g.Textf(`Time at last full page refresh was %v.`, now.Format(timeFormat))),
58+
H1(Text(`gomponents + HTMX`)),
59+
60+
P(Textf(`Time at last full page refresh was %v.`, now.Format(timeOnly))),
61+
5862
partial(now),
59-
FormEl(Method("post"), Action("/"), hx.Boost("true"), hx.Target("#partial"), hx.Swap("outerHTML"),
60-
Button(Type("submit"), g.Text(`Update time`),
63+
64+
Form(Method("post"), Action("/"),
65+
hx.Boost("true"), hx.Target("#partial"), hx.Swap("outerHTML"),
66+
67+
Button(Type("submit"), Text(`Update time`),
6168
Class("rounded-md border border-transparent bg-orange-600 px-4 py-2 text-sm font-medium text-white shadow-sm hover:bg-orange-700 focus:outline-none focus:ring-2 focus:ring-orange-500 focus:ring-offset-2"),
6269
),
6370
),
@@ -66,6 +73,6 @@ func page(now time.Time) g.Node {
6673
})
6774
}
6875

69-
func partial(now time.Time) g.Node {
70-
return P(ID("partial"), g.Textf(`Time was last updated at %v.`, now.Format(timeFormat)))
76+
func partial(now time.Time) Node {
77+
return P(ID("partial"), Textf(`Time was last updated at %v.`, now.Format(timeOnly)))
7178
}

go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
module github.com/maragudk/gomponents-htmx
1+
module maragu.dev/gomponents-htmx
22

33
go 1.18
44

5-
require github.com/maragudk/gomponents v0.20.1
5+
require maragu.dev/gomponents v1.0.0-beta1
66

77
require maragu.dev/is v0.2.0

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
github.com/maragudk/gomponents v0.20.1 h1:TeJY1fXEcfUvzmvjeUgxol42dvkYMggK1c0V67crWWs=
2-
github.com/maragudk/gomponents v0.20.1/go.mod h1:nHkNnZL6ODgMBeJhrZjkMHVvNdoYsfmpKB2/hjdQ0Hg=
1+
maragu.dev/gomponents v1.0.0-beta1 h1:I51NqKfrtQC4GxuWShqW5CT5BrfToMEueLD76IhdSXs=
2+
maragu.dev/gomponents v1.0.0-beta1/go.mod h1:oEDahza2gZoXDoDHhw8jBNgH+3UR5ni7Ur648HORydM=
33
maragu.dev/is v0.2.0 h1:poeuVEA5GG3vrDpGmzo2KjWtIMZmqUyvGnOB0/pemig=
44
maragu.dev/is v0.2.0/go.mod h1:bviaM5S0fBshCw7wuumFGTju/izopZ/Yvq4g7Klc7y8=

htmx.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package htmx
55
import (
66
"io"
77

8-
g "github.com/maragudk/gomponents"
8+
g "maragu.dev/gomponents"
99
)
1010

1111
// Boost to add or remove progressive enhancement for links and forms.

htmx_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import (
55
"os"
66
"testing"
77

8-
g "github.com/maragudk/gomponents"
9-
. "github.com/maragudk/gomponents/html"
8+
g "maragu.dev/gomponents"
9+
. "maragu.dev/gomponents/html"
1010

11-
hx "github.com/maragudk/gomponents-htmx"
12-
"github.com/maragudk/gomponents-htmx/internal/assert"
11+
hx "maragu.dev/gomponents-htmx"
12+
"maragu.dev/gomponents-htmx/internal/assert"
1313
)
1414

1515
func TestAttributes(t *testing.T) {

http/http_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66

77
"maragu.dev/is"
88

9-
hxhttp "github.com/maragudk/gomponents-htmx/http"
9+
hxhttp "maragu.dev/gomponents-htmx/http"
1010
)
1111

1212
func TestBoolGetters(t *testing.T) {

internal/assert/assert.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"strings"
66
"testing"
77

8-
g "github.com/maragudk/gomponents"
8+
g "maragu.dev/gomponents"
99
)
1010

1111
// Equal checks for equality between the given expected string and the rendered Node string.

0 commit comments

Comments
 (0)