Documentation
¶
Index ¶
- Variables
- func AppendTrigger(w http.ResponseWriter, name string, payload any) error
- func AppendTriggerAfterSettle(w http.ResponseWriter, name string, payload any) error
- func AppendTriggerAfterSwap(w http.ResponseWriter, name string, payload any) error
- func GeneratedFragment(f func(GeneratedComponentInput) error) ghtmx.Fragment
- func GeneratedTemplate(f func(GeneratedComponentInput) error) ghtmx.Component
- func GetBuilder() (sb strings.Builder)
- func GetDevModeTextFileName(templFileName string) string
- func ReleaseBuffer(w io.Writer) (err error)
- func SanitizeStyleAttributeValues(values ...any) (string, error)
- func ScriptContentInsideStringLiteral[T any](v T, errs ...error) (string, error)
- func ScriptContentOutsideStringLiteral[T any](v T, errs ...error) (string, error)
- func WriteString(w io.Writer, index int, s string) (err error)
- type Buffer
- type GeneratedComponentInput
- type StringLoader
Constants ¶
This section is empty.
Variables ¶
var DefaultBufferSize = 4 * 1024 // 4KB
DefaultBufferSize is the default size of buffers. It is set to 4KB by default, which is the same as the default buffer size of bufio.Writer.
var ErrInvalidStyleAttributeFunctionSignature = errors.New("invalid function signature, should be in the form func() (string, error)")
var TemplUnsupportedStyleAttributeValue = "zTemplUnsupportedStyleAttributeValue:Invalid;"
TemplUnsupportedStyleAttributeValue is the default value returned for unsupported types.
Functions ¶
func AppendTrigger ¶
func AppendTrigger(w http.ResponseWriter, name string, payload any) error
AppendTrigger merges one event into the response's HX-Trigger header, serialized for htmx 2.x: a comma-separated name list while every event is payload-less, upgraded to a JSON object ({"name": payload, ...}) as soon as any payload is involved. Multiple emissions in one response accumulate into a single header; re-emitting an event name replaces its payload in place. Event firing order in htmx follows the JSON key order, so insertion order is preserved.
Call AppendTrigger before writing the response status or body: headers set afterwards are silently discarded by net/http. It reads and rewrites the header map, so it is not safe for concurrent use on the same response. Serialized values are escaped to ASCII (\uXXXX) because HTTP header values cannot carry non-ASCII bytes reliably.
AppendTrigger is plumbing for the generated per-event emitters (FR-037): calling it directly with an ad-hoc name forfeits the declared event contract — the compiler can neither check the name nor type the payload. Do not use it in application code.
func AppendTriggerAfterSettle ¶
func AppendTriggerAfterSettle(w http.ResponseWriter, name string, payload any) error
AppendTriggerAfterSettle merges one event into HX-Trigger-After-Settle: htmx fires it after the settle step. Same contract as AppendTrigger.
func AppendTriggerAfterSwap ¶
func AppendTriggerAfterSwap(w http.ResponseWriter, name string, payload any) error
AppendTriggerAfterSwap merges one event into HX-Trigger-After-Swap: htmx fires it after the swap step. Same contract as AppendTrigger.
func GeneratedFragment ¶
func GeneratedFragment(f func(GeneratedComponentInput) error) ghtmx.Fragment
GeneratedFragment creates a ghtmx.Fragment from a generated standalone fragment wrapper. Render and RenderFragment are the same function: a standalone wrapper executes only the fragment body, so there is no page output to strip (FR-031).
func GeneratedTemplate ¶
func GeneratedTemplate(f func(GeneratedComponentInput) error) ghtmx.Component
GeneratedTemplate is used to avoid generated code needing to import the `context` and `io` packages.
func GetDevModeTextFileName ¶
func ReleaseBuffer ¶
ReleaseBuffer drains the buffer into its underlying writer and returns it to the pool. It deliberately does not invoke the underlying http.Flusher: an implicit end-of-render flush would commit the response headers and force chunked transfer encoding — header effects the handler never requested (FR-034, FR-090). Streaming flushes stay explicit via the ghtmx.Flush() component.
func SanitizeStyleAttributeValues ¶
SanitizeStyleAttributeValues renders a style attribute value. The supported types are: - string - ghtmx.SafeCSS - map[string]string - map[string]ghtmx.SafeCSSProperty - ghtmx.KeyValue[string, string] - A map of key/values where the key is the CSS property name and the value is the CSS property value. - ghtmx.KeyValue[string, ghtmx.SafeCSSProperty] - A map of key/values where the key is the CSS property name and the value is the CSS property value. - ghtmx.KeyValue[string, bool] - The bool determines whether the value should be included. - ghtmx.KeyValue[ghtmx.SafeCSS, bool] - The bool determines whether the value should be included. - func() (anyOfTheAboveTypes) - func() (anyOfTheAboveTypes, error) - []anyOfTheAboveTypes
In the above, ghtmx.SafeCSS and ghtmx.SafeCSSProperty are types that are used to indicate that the value is safe to render as CSS without sanitization. All other types are sanitized before rendering.
If an error is returned by any function, or a non-nil error is included in the input, the error is returned.
Types ¶
type Buffer ¶
Buffer is a wrapper around bufio.Writer that enables flushing and closing of the underlying writer.
func GetBuffer ¶
GetBuffer creates and returns a new buffer if the writer is not already a buffer, or returns the existing buffer if it is.
func (*Buffer) Close ¶
Close closes the buffer and the underlying io.Writer if it implements io.Closer.
func (*Buffer) Flush ¶
Flush writes any buffered data to the underlying io.Writer and calls the Flush method of the underlying http.Flusher if it implements it, committing the HTTP response. Only the explicit ghtmx.Flush() streaming component reaches this; end-of-render release uses ReleaseBuffer, which drains without the http.Flusher cascade.
type GeneratedComponentInput ¶
GeneratedComponentInput is used to avoid generated code needing to import the `context` and `io` packages.
type StringLoader ¶
type StringLoader struct {
// contains filtered or unexported fields
}
func NewStringLoader ¶
func NewStringLoader(devModeWatchRootPath string) (sl *StringLoader)