Files
pixa/internal/templates/templates.go
sneak aad5e59d23 Add static files and HTML templates for web UI
Embedded Tailwind CSS and login/generator templates.
Self-contained with no external dependencies.
2026-01-08 07:38:09 -08:00

33 lines
667 B
Go

// Package templates provides embedded HTML templates for the web UI.
package templates
import (
"embed"
"html/template"
"io"
"sync"
)
//go:embed *.html
var files embed.FS
//nolint:gochecknoglobals // intentional lazy initialization cache
var (
parsed *template.Template
parseOne sync.Once
)
// Get returns the parsed templates, parsing them on first call.
func Get() *template.Template {
parseOne.Do(func() {
parsed = template.Must(template.ParseFS(files, "*.html"))
})
return parsed
}
// Render renders a template by name to the given writer.
func Render(w io.Writer, name string, data any) error {
return Get().ExecuteTemplate(w, name, data)
}