Skip to content

Commit

Permalink
simpler streaming ex, that works on vercel
Browse files Browse the repository at this point in the history
  • Loading branch information
will-wow committed May 22, 2024
1 parent f96d352 commit b212414
Show file tree
Hide file tree
Showing 17 changed files with 319 additions and 339 deletions.
9 changes: 5 additions & 4 deletions .vscode/examples.code-snippets
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@
"",
"import (",
" \"embed\"",
" \"time\"",
"",
" \"github.com/lithammer/dedent\"",
"g \"github.com/maragudk/gomponents\"",
". \"github.com/maragudk/gomponents/html\"",
" g \"github.com/maragudk/gomponents\"",
" \"github.com/will-wow/typed-htmx-go/examples/web/$2/shared\"",
" \"github.com/will-wow/typed-htmx-go/examples/web/exprint\"",
Expand All @@ -102,21 +102,22 @@
"",
"var hx = htmx.NewGomponents()",
"",
"//go:embed ${TM_DIRECTORY/.*\\/(.*)$/$1/}.gom.go",
"//go:embed $TM_FILENAME",
"var fs embed.FS",
"var ex = exprint.New(fs, \"//\", \"\")",
"",
"func Page() g.Node {",
" return layout.Wrapper(",
" \"$1\",",
" H1(g.Text(\"$1\")),",
" Class(\"$3\"),",
" P(",
" g.Text(\"Desc\"),",
" ),",
" Pre(",
" Code(",
" Class(\"language-go\"),",
" g.Text(ex.PrintOrErr(\"$TM_FILENAME_BASE.gom.go\", \"demo\")),",
" g.Text(ex.PrintOrErr(\"$TM_FILENAME_BASE\", \"demo\")),",
" ),",
" ),",
" H2(g.Text(\"Demo\")),",
Expand Down
2 changes: 1 addition & 1 deletion examples/cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func main() {
server := &http.Server{
Addr: "localhost:8080",
Handler: handler,
ReadTimeout: time.Second * 30,
ReadTimeout: time.Second * 10,
WriteTimeout: time.Second * 10,
}

Expand Down
2 changes: 1 addition & 1 deletion examples/vercel.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"routes": [{ "src": "/(.*)", "dest": "/api" }],
"functions": {
"api/index.go": {
"maxDuration": 30
"maxDuration": 10
}
}
}
35 changes: 10 additions & 25 deletions examples/web/examples/exgom/examples.gom.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package exgom

import (
"fmt"

g "github.com/maragudk/gomponents"
. "github.com/maragudk/gomponents/html"

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

Expand All @@ -29,31 +32,13 @@ func Page() g.Node {
),
),
TBody(
exampleRow(
"/examples/gomponents/click-to-edit",
"Click To Edit",
"Demonstrates inline editing of a data object",
),
exampleRow(
"/examples/gomponents/bulk-update",
"Bulk Update",
"Demonstrates bulk updating of multiple rows of data",
),
exampleRow(
"/examples/gomponents/active-search/",
"Active Search",
"Demonstrates the active search box pattern",
),
exampleRow(
"/examples/gomponents/progress-bar/",
"Progress Bar",
"Demonstrates a job-runner like progress bar",
),
exampleRow(
"/examples/gomponents/class-tools/",
"Class Tools",
"Demo of class-tools options",
),
g.Group(g.Map(registry.Examples, func(ex registry.Example) g.Node {
return exampleRow(
fmt.Sprintf("/examples/gomponents/%s/", ex.Slug),
ex.Title,
ex.Desc,
)
})),
),
),
)
Expand Down
34 changes: 9 additions & 25 deletions examples/web/examples/extempl/examples.templ
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package extempl

import (
"fmt"
"github.com/will-wow/typed-htmx-go/examples/web/layout/templ/layout"
"github.com/will-wow/typed-htmx-go/examples/web/examples/registry"
)

templ Page() {
Expand Down Expand Up @@ -32,31 +34,13 @@ templ Page() {
</tr>
</thead>
<tbody>
@exampleRow(
"/examples/templ/click-to-edit/",
"Click To Edit",
"Demonstrates inline editing of a data object",
)
@exampleRow(
"/examples/templ/bulk-update/",
"Bulk Update",
"Demonstrates bulk updating of multiple rows of data",
)
@exampleRow(
"/examples/templ/active-search/",
"Active Search",
"Demonstrates the active search box pattern",
)
@exampleRow(
"/examples/templ/progress-bar/",
"Progress Bar",
"Demonstrates a job-runner like progress bar",
)
@exampleRow(
"/examples/templ/class-tools/",
"Class Tools",
"Demo of class-tools options",
)
for _, ex := range registry.Examples {
@exampleRow(
fmt.Sprintf("/examples/templ/%s/", ex.Slug),
ex.Title,
ex.Desc,
)
}
</tbody>
</table>
}
Expand Down
54 changes: 13 additions & 41 deletions examples/web/examples/extempl/examples_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 58 additions & 0 deletions examples/web/examples/registry/registry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package registry

import (
"net/http"

"github.com/will-wow/typed-htmx-go/examples/web/activesearch"
"github.com/will-wow/typed-htmx-go/examples/web/bulkupdate"
"github.com/will-wow/typed-htmx-go/examples/web/classtools_ex"
"github.com/will-wow/typed-htmx-go/examples/web/clicktoedit"
"github.com/will-wow/typed-htmx-go/examples/web/progressbar"
"github.com/will-wow/typed-htmx-go/examples/web/sse_ex"
)

type Example struct {
Title string
Desc string
Slug string
Handler func(bool) http.Handler
}

var Examples = []Example{
{
Title: "Click to Edit",
Desc: "Demonstrates inline editing of a data object",
Slug: "click-to-edit",
Handler: clicktoedit.NewHandler,
},
{
Title: "Bulk Update",
Desc: "Demonstrates bulk updating of multiple rows of data",
Slug: "bulk-update",
Handler: bulkupdate.NewHandler,
},
{
Title: "Active Search",
Desc: "Demonstrates the active search box pattern",
Slug: "active-search",
Handler: activesearch.NewHandler,
},
{
Title: "Progress Bar",
Desc: "Demonstrates a job-runner like progress bar",
Slug: "progress-bar",
Handler: progressbar.NewHandler,
},
{
Title: "Class Tools",
Desc: "Demo of class-tools options",
Slug: "class-tools",
Handler: classtools_ex.NewHandler,
},
{
Title: "Server-Sent Events",
Desc: "Streaming responses with the SSE HTMX Extension",
Slug: "sse",
Handler: sse_ex.NewHandler,
},
}
5 changes: 3 additions & 2 deletions examples/web/layout/gom/layout/layout.gom.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ func Wrapper(title string, children ...g.Node) g.Node {
Meta(Name("htmx-config"), hx.Config(
hxconfig.New().IncludeIndicatorStyles(false),
)),
Script(Src("https://unpkg.com/[email protected]")),
Script(Src("https://unpkg.com/[email protected]/dist/ext/class-tools.js")),
Script(Src("https://unpkg.com/[email protected]")),
Script(Src("https://unpkg.com/[email protected]/dist/ext/class-tools.js")),
Script(Src("https://unpkg.com/[email protected]/dist/ext/sse.js")),
Link(Rel("stylesheet"), Href("https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.classless.min.css")),
Link(Rel("stylesheet"), Href("https://cdn.jsdelivr.net/gh/highlightjs/[email protected]/build/styles/default.min.css")),
Link(Rel("stylesheet"), Href("/static/main.css")),
Expand Down
4 changes: 2 additions & 2 deletions examples/web/layout/templ/layout/layout.templ
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ templ Wrapper(title string, className ...string) {
hxconfig.New().Timeout(time.Second),
)... }
/>
<script src="https://unpkg.com/[email protected].10"></script>
<script src="https://unpkg.com/[email protected].10/dist/ext/class-tools.js"></script>
<script src="https://unpkg.com/[email protected].12"></script>
<script src="https://unpkg.com/[email protected].12/dist/ext/class-tools.js"></script>
<script src="https://unpkg.com/[email protected]/dist/ext/sse.js"></script>
<link
rel="stylesheet"
Expand Down
2 changes: 1 addition & 1 deletion examples/web/layout/templ/layout/layout_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b212414

Please sign in to comment.