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.
Move to maragu.dev/gomponents-htmx namespace (#16)
Also upgrade to maragu.dev/[email protected]
- Loading branch information
1 parent
15d81a4
commit b85d5b8
Showing
8 changed files
with
68 additions
and
57 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 |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
<img src="logo.png" alt="Logo" width="300" align="right"> | ||
|
||
[![GoDoc](https://pkg.go.dev/badge/github.com/maragudk/gomponents-htmx)](https://pkg.go.dev/github.com/maragudk/gomponents-htmx) | ||
[![GoDoc](https://pkg.go.dev/badge/maragu.dev/gomponents-htmx)](https://pkg.go.dev/maragu.dev/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). | ||
|
@@ -14,7 +14,7 @@ Does your company depend on this project? [Contact me at [email protected]](mailt | |
## Usage | ||
|
||
```shell | ||
go get github.com/maragudk/gomponents-htmx | ||
go get maragu.dev/gomponents-htmx@v1.0.0-beta1 | ||
``` | ||
|
||
```go | ||
|
@@ -26,12 +26,13 @@ import ( | |
"net/http" | ||
"time" | ||
|
||
g "github.com/maragudk/gomponents" | ||
c "github.com/maragudk/gomponents/components" | ||
. "github.com/maragudk/gomponents/html" | ||
ghttp "github.com/maragudk/gomponents/http" | ||
hx "github.com/maragudk/gomponents-htmx" | ||
hxhttp "github.com/maragudk/gomponents-htmx/http" | ||
. "maragu.dev/gomponents" | ||
. "maragu.dev/gomponents/components" | ||
. "maragu.dev/gomponents/html" | ||
. "maragu.dev/gomponents/http" | ||
|
||
hx "maragu.dev/gomponents-htmx" | ||
hxhttp "maragu.dev/gomponents-htmx/http" | ||
) | ||
|
||
func main() { | ||
|
@@ -43,11 +44,11 @@ func main() { | |
func start() error { | ||
now := time.Now() | ||
mux := http.NewServeMux() | ||
mux.HandleFunc("/", ghttp.Adapt(func(w http.ResponseWriter, r *http.Request) (g.Node, error) { | ||
mux.HandleFunc("/", Adapt(func(w http.ResponseWriter, r *http.Request) (Node, error) { | ||
if r.Method == http.MethodPost && hxhttp.IsBoosted(r.Header) { | ||
now = time.Now() | ||
|
||
hxhttp.SetPushURL(w.Header(), "/?time="+now.Format(timeFormat)) | ||
hxhttp.SetPushURL(w.Header(), "/?time="+now.Format(timeOnly)) | ||
|
||
return partial(now), nil | ||
} | ||
|
@@ -61,22 +62,29 @@ func start() error { | |
return nil | ||
} | ||
|
||
const timeFormat = "15:04:05" | ||
const timeOnly = "15:04:05" | ||
|
||
func page(now time.Time) Node { | ||
return HTML5(HTML5Props{ | ||
Title: now.Format(timeOnly), | ||
|
||
func page(now time.Time) g.Node { | ||
return c.HTML5(c.HTML5Props{ | ||
Title: now.Format(timeFormat), | ||
Head: []g.Node{ | ||
Head: []Node{ | ||
Script(Src("https://cdn.tailwindcss.com?plugins=forms,typography")), | ||
Script(Src("https://unpkg.com/htmx.org")), | ||
}, | ||
Body: []g.Node{ | ||
|
||
Body: []Node{ | ||
Div(Class("max-w-7xl mx-auto p-4 prose lg:prose-lg xl:prose-xl"), | ||
H1(g.Text(`gomponents + HTMX`)), | ||
P(g.Textf(`Time at last full page refresh was %v.`, now.Format(timeFormat))), | ||
H1(Text(`gomponents + HTMX`)), | ||
|
||
P(Textf(`Time at last full page refresh was %v.`, now.Format(timeOnly))), | ||
|
||
partial(now), | ||
FormEl(Method("post"), Action("/"), hx.Boost("true"), hx.Target("#partial"), hx.Swap("outerHTML"), | ||
Button(Type("submit"), g.Text(`Update time`), | ||
|
||
Form(Method("post"), Action("/"), | ||
hx.Boost("true"), hx.Target("#partial"), hx.Swap("outerHTML"), | ||
|
||
Button(Type("submit"), Text(`Update time`), | ||
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"), | ||
), | ||
), | ||
|
@@ -85,11 +93,7 @@ func page(now time.Time) g.Node { | |
}) | ||
} | ||
|
||
func partial(now time.Time) g.Node { | ||
return P(ID("partial"), g.Textf(`Time was last updated at %v.`, now.Format(timeFormat))) | ||
func partial(now time.Time) Node { | ||
return P(ID("partial"), Textf(`Time was last updated at %v.`, now.Format(timeOnly))) | ||
} | ||
|
||
``` | ||
|
||
|
||
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
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,7 +1,7 @@ | ||
module github.com/maragudk/gomponents-htmx | ||
module maragu.dev/gomponents-htmx | ||
|
||
go 1.18 | ||
|
||
require github.com/maragudk/gomponents v0.20.1 | ||
require maragu.dev/gomponents v1.0.0-beta1 | ||
|
||
require maragu.dev/is v0.2.0 |
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,4 +1,4 @@ | ||
github.com/maragudk/gomponents v0.20.1 h1:TeJY1fXEcfUvzmvjeUgxol42dvkYMggK1c0V67crWWs= | ||
github.com/maragudk/gomponents v0.20.1/go.mod h1:nHkNnZL6ODgMBeJhrZjkMHVvNdoYsfmpKB2/hjdQ0Hg= | ||
maragu.dev/gomponents v1.0.0-beta1 h1:I51NqKfrtQC4GxuWShqW5CT5BrfToMEueLD76IhdSXs= | ||
maragu.dev/gomponents v1.0.0-beta1/go.mod h1:oEDahza2gZoXDoDHhw8jBNgH+3UR5ni7Ur648HORydM= | ||
maragu.dev/is v0.2.0 h1:poeuVEA5GG3vrDpGmzo2KjWtIMZmqUyvGnOB0/pemig= | ||
maragu.dev/is v0.2.0/go.mod h1:bviaM5S0fBshCw7wuumFGTju/izopZ/Yvq4g7Klc7y8= |
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
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
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
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