Skip to content

Commit

Permalink
print real examples
Browse files Browse the repository at this point in the history
  • Loading branch information
will-wow committed Mar 11, 2024
1 parent 69f8366 commit b585410
Show file tree
Hide file tree
Showing 16 changed files with 254 additions and 496 deletions.
2 changes: 1 addition & 1 deletion .task/checksum/examples-gen
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9a523bcf202b0f54d94c4c32ad6e872c
ac1a28c2343f199a5d8bf54ba8e3c64
5 changes: 3 additions & 2 deletions examples/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ module github.com/will-wow/typed-htmx-go/examples

go 1.22.0

require github.com/a-h/templ v0.2.543
require github.com/a-h/templ v0.2.598

require (
github.com/PuerkitoBio/goquery v1.8.1
github.com/lithammer/dedent v1.1.0
github.com/maragudk/gomponents v0.20.2
github.com/will-wow/typed-htmx-go v0.0.7
)

require (
github.com/andybalholm/cascadia v1.3.1 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/net v0.19.0 // indirect
)
10 changes: 6 additions & 4 deletions examples/go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
github.com/PuerkitoBio/goquery v1.8.1 h1:uQxhNlArOIdbrH1tr0UXwdVFgDcZDrZVdcpygAcwmWM=
github.com/PuerkitoBio/goquery v1.8.1/go.mod h1:Q8ICL1kNUJ2sXGoAhPGUdYDJvgQgHzJsnnd3H7Ho5jQ=
github.com/a-h/templ v0.2.543 h1:8YyLvyUtf0/IE2nIwZ62Z/m2o2NqwhnMynzOL78Lzbk=
github.com/a-h/templ v0.2.543/go.mod h1:jP908DQCwI08IrnTalhzSEH9WJqG/Q94+EODQcJGFUA=
github.com/a-h/templ v0.2.598 h1:6jMIHv6wQZvdPxTuv87erW4RqN/FPU0wk7ZHN5wVuuo=
github.com/a-h/templ v0.2.598/go.mod h1:SA7mtYwVEajbIXFRh3vKdYm/4FYyLQAtPH1+KxzGPA8=
github.com/andybalholm/cascadia v1.3.1 h1:nhxRkql1kdYCc8Snf7D5/D3spOX+dBgjA6u8x004T2c=
github.com/andybalholm/cascadia v1.3.1/go.mod h1:R4bJ1UQfqADjvDa4P6HZHLh/3OxWWEqc0Sk8XGwHqvA=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
Expand All @@ -10,6 +10,8 @@ github.com/lithammer/dedent v1.1.0 h1:VNzHMVCBNG1j0fh3OrsFRkVUwStdDArbgBWoPAffkt
github.com/lithammer/dedent v1.1.0/go.mod h1:jrXYCQtgg0nJiN+StA2KgR7w6CiQNv9Fd/Z9BP0jIOc=
github.com/maragudk/gomponents v0.20.2 h1:39FhnBNNCJzqNcD9Hmvp/5xj0otweFoyvVgFG6kXoy0=
github.com/maragudk/gomponents v0.20.2/go.mod h1:nHkNnZL6ODgMBeJhrZjkMHVvNdoYsfmpKB2/hjdQ0Hg=
github.com/will-wow/typed-htmx-go v0.0.7 h1:nxUaLXq0m4dnN1JqninalwWZSgVqWmrls1KAH8HaGzo=
github.com/will-wow/typed-htmx-go v0.0.7/go.mod h1:8rgV1W5T/jTAw2vXIZ9CAcOkmGbtejyomfLuesH+564=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
Expand All @@ -19,8 +21,8 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v
golang.org/x/net v0.0.0-20210916014120-12bc252f5db8/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c=
golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down
76 changes: 13 additions & 63 deletions examples/web/bulkupdate/exgom/bulkupdate.gom.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package exgom

import (
"embed"
"time"

"github.com/lithammer/dedent"
Expand All @@ -11,12 +12,16 @@ import (
"github.com/will-wow/typed-htmx-go/htmx/swap"

"github.com/will-wow/typed-htmx-go/examples/web/bulkupdate/form"

"github.com/will-wow/typed-htmx-go/examples/web/exprint"
"github.com/will-wow/typed-htmx-go/examples/web/layout/gom/layout"
)

var hx = htmx.NewGomponents()

//go:embed bulkupdate.gom.go
var fs embed.FS
var ex = exprint.New(fs, "//", "")

func Page(users []form.UserModel) g.Node {
return layout.Wrapper(
"Bulk Update",
Expand All @@ -30,57 +35,7 @@ func Page(users []form.UserModel) g.Node {
Pre(
Code(
Class("language-go"),
g.Text(dedent.Dedent(`
func table(users []form.UserModel) g.Node {
return FormEl(
ID("checked-contacts"),
hx.Post("/examples/gomponents/bulk-update/"),
hx.SwapExtended(
swap.New().Strategy(swap.OuterHTML).Settle(3*time.Second),
),
hx.Target(
"#toast",
),
H3(g.Text("Select Rows And Activate Or Deactivate Below")),
Table(
THead(
Tr(
Td(g.Text("Name")),
Td(g.Text("Email")),
Td(g.Text("Activate")),
),
),
TBody(
ID("tbody"),
g.Group(
g.Map(users, func(u form.UserModel) g.Node {
return Tr(
Td(g.Text(u.Name)),
Td(g.Text(u.Email)),
Td(
Input(
Type("checkbox"),
Name(u.Email),
g.If(u.Active,
Checked(),
),
),
),
)
}),
),
),
),
Input(
Type("submit"),
Value("Submit"),
),
UpdateToast(""),
)
}
`)),
g.Text(ex.PrintOrErr("bulkupdate.gom.go", "table")),
),
),
P(
Expand All @@ -105,17 +60,7 @@ func Page(users []form.UserModel) g.Node {
Pre(
Code(
Class("language-go"),
g.Text(dedent.Dedent(`
func UpdateToast(toast string) g.Node {
return Span(
ID("toast"),
g.If(toast != "",
g.Attr("aria-live", "polite"),
),
g.Text(toast),
)
}
`)),
g.Text(ex.PrintOrErr("bulkupdate.gom.go", "UpdateToast")),
),
),
P(
Expand All @@ -138,6 +83,7 @@ func Page(users []form.UserModel) g.Node {
}

func table(users []form.UserModel) g.Node {
//ex:start:table
return FormEl(
ID("checked-contacts"),
hx.Post("/examples/gomponents/bulk-update/"),
Expand Down Expand Up @@ -185,8 +131,10 @@ func table(users []form.UserModel) g.Node {
),
UpdateToast(""),
)
//ex:end:table
}

//ex:start:UpdateToast
func UpdateToast(toast string) g.Node {
return Span(
ID("toast"),
Expand All @@ -196,3 +144,5 @@ func UpdateToast(toast string) g.Node {
g.Text(toast),
)
}

//ex:end:UpdateToast
67 changes: 13 additions & 54 deletions examples/web/bulkupdate/extempl/bulkupdate.templ
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@ package extempl

import (
"time"
"embed"

"github.com/lithammer/dedent"

"github.com/will-wow/typed-htmx-go/examples/web/layout/templ/layout"
"github.com/will-wow/typed-htmx-go/examples/web/bulkupdate/form"
"github.com/will-wow/typed-htmx-go/htmx"
"github.com/will-wow/typed-htmx-go/htmx/swap"
"github.com/will-wow/typed-htmx-go/examples/web/exprint"
)

var hx = htmx.NewTempl()

//go:embed bulkupdate.templ
var fs embed.FS
var ex = exprint.New(fs, "//", "")

templ Page(users []form.UserModel) {
@layout.Wrapper("Bulk Update", "bulk-update") {
<h1>Bulk Update</h1>
Expand All @@ -21,48 +27,7 @@ templ Page(users []form.UserModel) {
</p>
<pre>
<code class="language-go">
{ dedent.Dedent(`
templ table(users []form.UserModel) {
<form
id="checked-contacts"
{ hx.Post("/examples/templ/bulk-update/")... }
{ hx.SwapExtended(
swap.New().Strategy(swap.OuterHTML).Settle(3 * time.Second),
)... }
{ hx.Target("#toast")... }
>
<h3>Select Rows And Activate Or Deactivate Below</h3>
<table>
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Active</th>
</tr>
</thead>
<tbody id="tbody">
for _, user := range users {
<tr>
<td>{ user.Name }</td>
<td>{ user.Email }</td>
<td>
<input
type="checkbox"
name={ user.Email }
if user.Active {
checked
}
/>
</td>
</tr>
}
</tbody>
</table>
<input type="submit" value="Bulk Update"/>
@UpdateToast("")
</form>
}
`) }
{ ex.PrintOrErr("bulkupdate.templ", "table") }
</code>
</pre>
<p>
Expand All @@ -85,18 +50,7 @@ templ Page(users []form.UserModel) {
</pre>
<pre>
<code class="language-go">
{ dedent.Dedent(`
templ UpdateToast(toast string) {
<span
id="toast"
if toast != "" {
aria-live="polite"
}
>
{ toast }
</span>
}
`) }
{ ex.PrintOrErr("bulkupdate.templ", "UpdateToast") }
</code>
</pre>
<p>
Expand All @@ -120,6 +74,7 @@ templ Page(users []form.UserModel) {
}

templ table(users []form.UserModel) {
//ex:start:table
<form
id="checked-contacts"
{ hx.Post("/examples/templ/bulk-update/")... }
Expand Down Expand Up @@ -158,8 +113,10 @@ templ table(users []form.UserModel) {
<input type="submit" value="Bulk Update"/>
@UpdateToast("")
</form>
//ex:end:table
}

//ex:start:UpdateToast
templ UpdateToast(toast string) {
<span
id="toast"
Expand All @@ -170,3 +127,5 @@ templ UpdateToast(toast string) {
{ toast }
</span>
}

//ex:end:UpdateToast
Loading

0 comments on commit b585410

Please sign in to comment.