mirror of
https://github.com/joerdav/go-htmx-examples.git
synced 2025-11-23 15:52:27 +00:00
feat: bulk update and click to edit
This commit is contained in:
50
shared/layout.templ
Normal file
50
shared/layout.templ
Normal file
@@ -0,0 +1,50 @@
|
||||
package shared
|
||||
|
||||
import "os"
|
||||
|
||||
templ Layout(title string) {
|
||||
<html>
|
||||
<head>
|
||||
<link href="https://unpkg.com/prismjs@1.29.0/themes/prism-twilight.css" rel="stylesheet"/>
|
||||
<style>
|
||||
.token.number,
|
||||
.token.tag {
|
||||
all: inherit;
|
||||
color: hsl(14, 58%, 55%);
|
||||
}
|
||||
</style>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.4/css/bulma.min.css"/>
|
||||
<title>Go htmx examples - { title }</title>
|
||||
<script src="https://unpkg.com/htmx.org@1.8.5"></script>
|
||||
if os.Getenv("DEBUG") == "true" {
|
||||
<style>
|
||||
@keyframes debug {
|
||||
from {outline: 3px solid #FF0000FF;}
|
||||
to {outline: 3px solid #FF000000;}
|
||||
}
|
||||
* {
|
||||
animation-name: debug;
|
||||
animation-duration: 1s;
|
||||
}
|
||||
</style>
|
||||
}
|
||||
</head>
|
||||
<body hx-boost="true">
|
||||
@Nav()
|
||||
<div id="content" class="container p-5 content">
|
||||
{ children... }
|
||||
</div>
|
||||
<script src="https://unpkg.com/prismjs@1.29.0/components/prism-core.min.js"></script>
|
||||
<script src="https://unpkg.com/prismjs@1.29.0/plugins/autoloader/prism-autoloader.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
}
|
||||
|
||||
templ Nav() {
|
||||
<nav class="navbar is-black has-shadow" role="navigation" aria-label="main navigation">
|
||||
<div class="navbar-brand">
|
||||
<div class="navbar-start"><a class="navbar-item has-text-weight-bold is-size-3" href="/">Go HTMX Examples</a></div>
|
||||
</div>
|
||||
</nav>
|
||||
}
|
||||
|
||||
389
shared/layout_templ.go
Normal file
389
shared/layout_templ.go
Normal file
@@ -0,0 +1,389 @@
|
||||
// Code generated by templ@(devel) DO NOT EDIT.
|
||||
|
||||
package shared
|
||||
|
||||
//lint:file-ignore SA4006 This context is only used if a nested component is present.
|
||||
|
||||
import "github.com/a-h/templ"
|
||||
import "context"
|
||||
import "io"
|
||||
import "bytes"
|
||||
|
||||
// GoExpression
|
||||
import "os"
|
||||
|
||||
func Layout(title string) templ.Component {
|
||||
return templ.ComponentFunc(func(ctx context.Context, w io.Writer) (err error) {
|
||||
templBuffer, templIsBuffer := w.(*bytes.Buffer)
|
||||
if !templIsBuffer {
|
||||
templBuffer = templ.GetBuffer()
|
||||
defer templ.ReleaseBuffer(templBuffer)
|
||||
}
|
||||
ctx = templ.InitializeContext(ctx)
|
||||
var_1 := templ.GetChildren(ctx)
|
||||
if var_1 == nil {
|
||||
var_1 = templ.NopComponent
|
||||
}
|
||||
ctx = templ.ClearChildren(ctx)
|
||||
// Element (standard)
|
||||
_, err = templBuffer.WriteString("<html>")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Element (standard)
|
||||
_, err = templBuffer.WriteString("<head>")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Element (void)
|
||||
_, err = templBuffer.WriteString("<link")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Element Attributes
|
||||
_, err = templBuffer.WriteString(" href=\"https://unpkg.com/prismjs@1.29.0/themes/prism-twilight.css\"")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = templBuffer.WriteString(" rel=\"stylesheet\"")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = templBuffer.WriteString(">")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// RawElement
|
||||
_, err = templBuffer.WriteString("<style>")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Text
|
||||
var_2 := `
|
||||
.token.number,
|
||||
.token.tag {
|
||||
all: inherit;
|
||||
color: hsl(14, 58%, 55%);
|
||||
}
|
||||
`
|
||||
_, err = templBuffer.WriteString(var_2)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = templBuffer.WriteString("</style>")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Element (void)
|
||||
_, err = templBuffer.WriteString("<link")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Element Attributes
|
||||
_, err = templBuffer.WriteString(" rel=\"stylesheet\"")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = templBuffer.WriteString(" href=\"https://cdn.jsdelivr.net/npm/bulma@0.9.4/css/bulma.min.css\"")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = templBuffer.WriteString(">")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Element (standard)
|
||||
_, err = templBuffer.WriteString("<title>")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Text
|
||||
var_3 := `Go htmx examples - `
|
||||
_, err = templBuffer.WriteString(var_3)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// StringExpression
|
||||
var var_4 string = title
|
||||
_, err = templBuffer.WriteString(templ.EscapeString(var_4))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = templBuffer.WriteString("</title>")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// RawElement
|
||||
_, err = templBuffer.WriteString("<script")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Element Attributes
|
||||
_, err = templBuffer.WriteString(" src=\"https://unpkg.com/htmx.org@1.8.5\"")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = templBuffer.WriteString(">")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Text
|
||||
var_5 := ``
|
||||
_, err = templBuffer.WriteString(var_5)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = templBuffer.WriteString("</script>")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// If
|
||||
if os.Getenv("DEBUG") == "true" {
|
||||
// RawElement
|
||||
_, err = templBuffer.WriteString("<style>")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Text
|
||||
var_6 := `
|
||||
@keyframes debug {
|
||||
from {outline: 3px solid #FF0000FF;}
|
||||
to {outline: 3px solid #FF000000;}
|
||||
}
|
||||
* {
|
||||
animation-name: debug;
|
||||
animation-duration: 1s;
|
||||
}
|
||||
`
|
||||
_, err = templBuffer.WriteString(var_6)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = templBuffer.WriteString("</style>")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
_, err = templBuffer.WriteString("</head>")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Element (standard)
|
||||
_, err = templBuffer.WriteString("<body")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Element Attributes
|
||||
_, err = templBuffer.WriteString(" hx-boost=\"true\"")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = templBuffer.WriteString(">")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// TemplElement
|
||||
err = Nav().Render(ctx, templBuffer)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Element (standard)
|
||||
_, err = templBuffer.WriteString("<div")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Element Attributes
|
||||
_, err = templBuffer.WriteString(" id=\"content\"")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = templBuffer.WriteString(" class=\"container p-5 content\"")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = templBuffer.WriteString(">")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Children
|
||||
err = var_1.Render(ctx, templBuffer)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = templBuffer.WriteString("</div>")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// RawElement
|
||||
_, err = templBuffer.WriteString("<script")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Element Attributes
|
||||
_, err = templBuffer.WriteString(" src=\"https://unpkg.com/prismjs@1.29.0/components/prism-core.min.js\"")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = templBuffer.WriteString(">")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Text
|
||||
var_7 := ``
|
||||
_, err = templBuffer.WriteString(var_7)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = templBuffer.WriteString("</script>")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// RawElement
|
||||
_, err = templBuffer.WriteString("<script")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Element Attributes
|
||||
_, err = templBuffer.WriteString(" src=\"https://unpkg.com/prismjs@1.29.0/plugins/autoloader/prism-autoloader.min.js\"")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = templBuffer.WriteString(">")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Text
|
||||
var_8 := ``
|
||||
_, err = templBuffer.WriteString(var_8)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = templBuffer.WriteString("</script>")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = templBuffer.WriteString("</body>")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = templBuffer.WriteString("</html>")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !templIsBuffer {
|
||||
_, err = io.Copy(w, templBuffer)
|
||||
}
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
||||
func Nav() templ.Component {
|
||||
return templ.ComponentFunc(func(ctx context.Context, w io.Writer) (err error) {
|
||||
templBuffer, templIsBuffer := w.(*bytes.Buffer)
|
||||
if !templIsBuffer {
|
||||
templBuffer = templ.GetBuffer()
|
||||
defer templ.ReleaseBuffer(templBuffer)
|
||||
}
|
||||
ctx = templ.InitializeContext(ctx)
|
||||
var_9 := templ.GetChildren(ctx)
|
||||
if var_9 == nil {
|
||||
var_9 = templ.NopComponent
|
||||
}
|
||||
ctx = templ.ClearChildren(ctx)
|
||||
// Element (standard)
|
||||
_, err = templBuffer.WriteString("<nav")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Element Attributes
|
||||
_, err = templBuffer.WriteString(" class=\"navbar is-black has-shadow\"")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = templBuffer.WriteString(" role=\"navigation\"")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = templBuffer.WriteString(" aria-label=\"main navigation\"")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = templBuffer.WriteString(">")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Element (standard)
|
||||
_, err = templBuffer.WriteString("<div")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Element Attributes
|
||||
_, err = templBuffer.WriteString(" class=\"navbar-brand\"")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = templBuffer.WriteString(">")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Element (standard)
|
||||
_, err = templBuffer.WriteString("<div")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Element Attributes
|
||||
_, err = templBuffer.WriteString(" class=\"navbar-start\"")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = templBuffer.WriteString(">")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Element (standard)
|
||||
_, err = templBuffer.WriteString("<a")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Element Attributes
|
||||
_, err = templBuffer.WriteString(" class=\"navbar-item has-text-weight-bold is-size-3\"")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = templBuffer.WriteString(" href=\"/\"")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = templBuffer.WriteString(">")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Text
|
||||
var_10 := `Go HTMX Examples`
|
||||
_, err = templBuffer.WriteString(var_10)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = templBuffer.WriteString("</a>")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = templBuffer.WriteString("</div>")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = templBuffer.WriteString("</div>")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = templBuffer.WriteString("</nav>")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !templIsBuffer {
|
||||
_, err = io.Copy(w, templBuffer)
|
||||
}
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
||||
25
shared/shared.go
Normal file
25
shared/shared.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package shared
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"io"
|
||||
|
||||
"github.com/a-h/templ"
|
||||
"github.com/yosssi/gohtml"
|
||||
)
|
||||
|
||||
func Raw() templ.ComponentFunc {
|
||||
return func(ctx context.Context, w io.Writer) error {
|
||||
b := new(bytes.Buffer)
|
||||
if err := templ.GetChildren(ctx).Render(ctx, b); err != nil {
|
||||
return err
|
||||
}
|
||||
gohtml.Condense = true
|
||||
str := templ.EscapeString(gohtml.Format(b.String()))
|
||||
if _, err := w.Write([]byte(str)); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user