Documentation
¶
Index ¶
- func IncludeZeroTruthy(v any) (bool, error)
- func IsNumericZero(v any) (bool, error)
- func IsTruthy(value any) (bool, error)
- func LookupPath(root any, path string) any
- func MergePartialContext(base, additions map[string]any) map[string]any
- func MissingPartial(name string) error
- func MissingPartialOutput(w io.Writer, name string)
- func SetReflectUsageLevel(level ReflectUsageLevel)
- func Stringify(v any) string
- func WriteEscaped(w io.Writer, v any) error
- func WriteRaw(w io.Writer, v any) error
- type Blocks
- type Hash
- type Helper
- type HelperArgs
- func (a HelperArgs) GetArg(idx int) any
- func (a HelperArgs) GetHash(key string) any
- func (a HelperArgs) GetHashNumber(key string) (float64, error)
- func (a HelperArgs) GetHashString(key string) string
- func (a HelperArgs) GetNumber(idx int) (float64, error)
- func (a HelperArgs) GetString(idx int) string
- type LazyBlockWriter
- type LazyWriter
- type ReflectUsageLevel
- type SafeString
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IncludeZeroTruthy ¶
IncludeZeroTruthy reports whether v should be treated as truthy when the includeZero option is set: it returns true if v is numeric zero or if IsTruthy(v) is true. Used by {{#if}} / {{#unless}} with includeZero=true.
func IsNumericZero ¶
IsNumericZero reports whether v is a numeric type with value zero. It handles json.Number (from decoding JSON with UseNumber()), Go numeric types, and numeric kinds via reflection when ReflectUsageLevel allows.
func LookupPath ¶
LookupPath returns the value at the dot-separated path from root (e.g. "title", "user.name"). Root can be map[string]any or implement Raw() any returning a map. Used for @root.xxx in partials.
func MergePartialContext ¶
MergePartialContext returns a new map with base keys/values plus additions (additions override). Used for partial context: current/explicit context merged with hash (e.g. note="thanks"). If base is nil, returns a copy of additions.
func MissingPartial ¶
MissingPartial formats a missing partial error.
func MissingPartialOutput ¶
MissingPartialOutput is used for dynamic partials only: when the partial name is not found, it writes the error message (HTML comment) and logs with log.Error; the render continues without failing. If w implements LazyBlockWriter, the output is registered as a lazy block and written on Flush.
func SetReflectUsageLevel ¶ added in v0.1.2
func SetReflectUsageLevel(level ReflectUsageLevel)
SetReflectUsageLevel sets the reflect usage level (USE, WARN, ERROR). Default is WARN.
func WriteEscaped ¶
WriteEscaped writes an escaped value into the writer.
Types ¶
type Blocks ¶
type Blocks struct {
// contains filtered or unexported fields
}
Blocks holds content for layout block/partial: child templates register content with {{#partial "name"}}...{{/partial}}, layout outputs it with {{#block "name"}}default{{/block}}. When Blocks is nil, {{#block}} renders only its default body and {{#partial}} renders its body to the writer.
func NewBlocks ¶
func NewBlocks() *Blocks
NewBlocks returns a new Blocks store for use with layout templates.
type Helper ¶
type Helper func(args HelperArgs) (any, error)
Helper is a user-defined function invoked from a template. It receives HelperArgs; values are resolved by the compiler. For block helpers, call args.BlockFn() or args.InverseFn() with no arguments; the writer is already captured in the closure.
type HelperArgs ¶ added in v0.1.3
type HelperArgs struct {
HashArgs map[string]any // named (hash) arguments
Args []any // positional arguments
BlockFn func() error // when IsBlock: closure that renders the main block (writer captured by compiler); nil otherwise
InverseFn func() error // when IsBlock and else exists: closure that renders the else block; may be nil
IsBlock bool // true for block helper invocations
}
HelperArgs is the argument bundle passed to every helper. Values are resolved by the compiler; the helper receives typed args and hash.
func (HelperArgs) GetArg ¶ added in v0.1.3
func (a HelperArgs) GetArg(idx int) any
GetArg returns the positional argument at index, or nil if out of bounds.
func (HelperArgs) GetHash ¶ added in v0.1.3
func (a HelperArgs) GetHash(key string) any
GetHash returns the hash argument for key, or nil if missing or HashArgs is nil.
func (HelperArgs) GetHashNumber ¶ added in v0.1.3
func (a HelperArgs) GetHashNumber(key string) (float64, error)
GetHashNumber converts the hash value for key to float64. Returns (0, nil) if missing or nil.
func (HelperArgs) GetHashString ¶ added in v0.1.3
func (a HelperArgs) GetHashString(key string) string
GetHashString returns the stringified hash value for key, or empty string.
func (HelperArgs) GetNumber ¶ added in v0.1.3
func (a HelperArgs) GetNumber(idx int) (float64, error)
GetNumber converts the argument at index to float64. Returns (0, nil) for nil or out of bounds.
func (HelperArgs) GetString ¶ added in v0.1.3
func (a HelperArgs) GetString(idx int) string
GetString returns the stringified argument at index, or empty string.
type LazyBlockWriter ¶
type LazyBlockWriter interface {
io.Writer
// WriteLazyBlock registers a block to be written at Flush. The block receives
// the underlying writer and may write the "partial \"\" is not defined" message etc.
WriteLazyBlock(block func(io.Writer))
// Flush writes any buffered data and evaluates lazy blocks in order.
Flush() error
}
LazyBlockWriter is an io.Writer that can register lazy output blocks. A lazy block is written when Flush is called, preserving order with prior Write calls.
type LazyWriter ¶
type LazyWriter struct {
// contains filtered or unexported fields
}
LazyWriter wraps w and implements LazyBlockWriter: Write and WriteLazyBlock are queued in order; Flush drains the queue to w.
func NewLazyWriter ¶
func NewLazyWriter(w io.Writer) *LazyWriter
NewLazyWriter returns a LazyBlockWriter that flushes to w.
func (*LazyWriter) Flush ¶
func (l *LazyWriter) Flush() error
Flush writes all queued direct bytes and runs lazy blocks in order.
func (*LazyWriter) Write ¶
func (l *LazyWriter) Write(p []byte) (n int, err error)
Write implements io.Writer by queuing the bytes; they are written on Flush.
func (*LazyWriter) WriteLazyBlock ¶
func (l *LazyWriter) WriteLazyBlock(block func(io.Writer))
WriteLazyBlock registers a block to run at Flush (writes to l.w).
type ReflectUsageLevel ¶ added in v0.1.2
type ReflectUsageLevel int
ReflectUsageLevel is the level for reflect fallback branches.
const ( ReflectUse ReflectUsageLevel = iota ReflectWarn ReflectError )
ReflectUsageLevel controls how reflection is used when type switches don't cover a value.
func GetReflectUsageLevel ¶ added in v0.1.2
func GetReflectUsageLevel() ReflectUsageLevel
GetReflectUsageLevel returns the current reflect usage level.