Documentation
¶
Index ¶
- Variables
- func ApplyFilters(value interface{}, fs []Filter, ctx Context) (interface{}, error)
- func Execute(tpl *Template, ctx Context) (string, error)
- func MustExecute(tpl *Template, ctx Context) string
- func RegisterFilter(name string, fn FilterFunc) error
- func Render(source string, ctx Context) (string, error)
- type Context
- type Filter
- type FilterArg
- type FilterFunc
- type Node
- type NumberArg
- type Parser
- type StringArg
- type Template
- type VariableArg
Constants ¶
This section is empty.
Variables ¶
var ( // ErrContextKeyNotFound is returned when a key is not found in the context. ErrContextKeyNotFound = errors.New("key not found in context") // ErrContextInvalidKeyType is returned when an unexpected type is encountered while navigating the context. ErrContextInvalidKeyType = errors.New("invalid key type for navigation") // ErrContextIndexOutOfRange is returned when an index is out of range in the context. ErrContextIndexOutOfRange = errors.New("index out of range in context") )
var ( // ErrFilterInputNotSlice indicates a filter expected a slice but received a different type. ErrFilterInputNotSlice = errors.New("filter input is not a slice") // ErrFilterInputNotNumeric indicates a filter expected a numeric value but received a different type. ErrFilterInputNotNumeric = errors.New("filter input is not numeric") // ErrFilterInputInvalidTimeFormat indicates a filter expected a valid time format but didn't receive it. ErrFilterInputInvalidTimeFormat = errors.New("filter input has an invalid time format") // ErrFilterInputUnsupportedType indicates the filter received a type it does not support. ErrFilterInputUnsupportedType = errors.New("filter input is of an unsupported type") )
var ErrFilterArgsInvalid = errors.New("filter arguments are invalid")
ErrFilterArgsInvalid indicates an issue with the filter arguments, such as wrong type, format, or number of arguments.
var ErrFilterInputEmpty = errors.New("filter input is empty")
ErrFilterInputEmpty indicates that the input value is empty or nil.
var ErrFilterInputInvalid = errors.New("filter input is invalid")
ErrFilterInputInvalid indicates an issue with the filter input value being of an unexpected type or format.
var ErrFilterNotFound = errors.New("filter not found")
ErrFilterNotFound indicates that the requested filter was not found in the global registry.
var ErrInsufficientArgs = errors.New("insufficient arguments provided")
ErrInsufficientArgs indicates that the filter was called with insufficient arguments.
Functions ¶
func ApplyFilters ¶
ApplyFilters executes a series of filters on a value within a context, supporting variable arguments.
func MustExecute ¶
MustExecute renders the template with provided context, ignoring errors.
func RegisterFilter ¶
func RegisterFilter(name string, fn FilterFunc) error
RegisterFilter adds a filter to the global registry with name validation.
Types ¶
type Context ¶
type Context map[string]interface{}
Context stores template variables.
type FilterArg ¶
type FilterArg interface {
Value() interface{}
Type() string
}
FilterArg represents the interface for filter arguments.
type FilterFunc ¶
FilterFunc represents the signature of functions that can be applied as filters.
type Node ¶
Node defines a single element within a template, such as text, variable, or control structure.
type NumberArg ¶
type NumberArg struct {
// contains filtered or unexported fields
}
NumberArg holds a number argument.
type Parser ¶
type Parser struct{}
Parser analyzes template syntax.
type StringArg ¶
type StringArg struct {
// contains filtered or unexported fields
}
StringArg holds a string argument.
type Template ¶
type Template struct {
Nodes []*Node
}
Template represents a structured template that can be executed with a given context.
func NewTemplate ¶
func NewTemplate() *Template
NewTemplate creates an empty template, ready to be populated with nodes.
func (*Template) Execute ¶
Execute combines template data with the provided context to produce a string.
func (*Template) MustExecute ¶
MustExecute combines template data with the provided context to produce a string, ignoring errors.
type VariableArg ¶
type VariableArg struct {
// contains filtered or unexported fields
}
VariableArg holds a variable argument.
func (VariableArg) Type ¶
func (a VariableArg) Type() string
func (VariableArg) Value ¶
func (a VariableArg) Value() interface{}
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
context
command
|
|
|
filter_with_args
command
|
|
|
filters
command
|
|
|
hello_world
command
|
|
|
object
command
|