Documentation
¶
Overview ¶
Package ui provides HTML template rendering and cache version management for the application's user interface. It manages template initialization, cache busting, and page rendering functions.
Index ¶
- func EscapeHash(s string) string
- func GetCacheVersion() string
- func ParseTemplates(templateFS fs.FS) (err error)
- func RenderPage(w io.Writer, name string, data any, partial bool) error
- func RenderTemplate(w io.Writer, name string, data any) error
- func SetCacheVersion(version string)
- func ValidateHTMXResponseStructure(body string, swapType string, targetID string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EscapeHash ¶
EscapeHash replaces all '#' characters with '%23' for use in safe URL query parameters. Exported for use in tests and template funcMap.
func GetCacheVersion ¶
func GetCacheVersion() string
GetCacheVersion returns the current cache version (thread-safe).
func ParseTemplates ¶
ParseTemplates parses all embedded HTML templates and the associated function map. It uses GetCacheVersion() for cache-busting in templates. A mutex serializes concurrent calls to prevent data races on the package-level template variables.
func RenderPage ¶
RenderPage renders a full HTML page by executing a named template within the base "layout" template. If partial is true, it renders only the "body" block for htmx partial updates.
func RenderTemplate ¶
RenderTemplate renders a single, standalone template by name. It is used for partials or components that are not part of a full page layout.
func SetCacheVersion ¶
func SetCacheVersion(version string)
SetCacheVersion updates the application-wide cache version. This should be called when config is loaded or updated.
func ValidateHTMXResponseStructure ¶ added in v0.14.0
ValidateHTMXResponseStructure validates that an HTMX response has the correct structure for the specified swap type. This helps catch structural issues that would cause HTMX swap errors in the browser.
Parameters:
- body: The response body string
- swapType: The HTMX swap type (e.g., "outerHTML", "innerHTML", "beforeend")
- targetID: The target element ID (for validating OOB swaps)
Returns an error if the structure is invalid, nil otherwise.
Types ¶
This section is empty.