Documentation
¶
Index ¶
- Variables
- func RegisterExprFunc(name string, fn any)
- func RegisterNAttr(name string, h NAttrHandler)
- type Delims
- type DumbEval
- type Evaluator
- type ExprEval
- type Loader
- type NAttrHandler
- type NContext
- type OSLoader
- type Parser
- func (p *Parser) Delims(left, right string) *Parser
- func (p *Parser) Parse(name, src string) (*Template, error)
- func (p *Parser) ParseFS(fsys fs.FS, patterns ...string) ([]*Template, error)
- func (p *Parser) ParseFile(path string) (*Template, error)
- func (p *Parser) ParseGlob(pattern string) ([]*Template, error)
- type Template
Constants ¶
This section is empty.
Variables ¶
var DefaultDelims = Delims{L: "{{", R: "}}"}
var GlobalExprFunctions = map[string]any{}
GlobalExprFunctions Global registry for expr functions
var GlobalNAttrHandlers = map[string]NAttrHandler{}
Functions ¶
func RegisterExprFunc ¶
func RegisterNAttr ¶
func RegisterNAttr(name string, h NAttrHandler)
Types ¶
type ExprEval ¶
ExprEval uses github.com/cantonment/expr to evaluate expressions against data. Supports pipe filters like `User.Role|upper|default("N/A")` by transforming them into nested function calls: default(upper(User.Role), "N/A").
type Loader ¶
Loader abstracts how files are read (for layouts/includes). Provide OSLoader in production and a fake in tests.
type NAttrHandler ¶
type Parser ¶
type Parser struct {
Loader Loader
// contains filtered or unexported fields
}
func NewParserWithDelims ¶
func (*Parser) Delims ¶
Delims sets the parser delimiters (same semantics as html/template.Delims). Call this BEFORE Parse/ParseFile/ParseGlob. Chainable.
type Template ¶
type Template struct {
Name string
Source string
Layout string
Blocks map[string]string
Snippets map[string]string
SnippetClasses map[string]string
Delims Delims
// contains filtered or unexported fields
}
func NewTemplate ¶
func (*Template) Execute ¶
Execute renders the template (layout + blocks) and then processes n:* attrs.
func (*Template) ExecuteWith ¶
func (t *Template) ExecuteWith(loader Loader, eval Evaluator, data any, handlers map[string]NAttrHandler) (string, error)
ExecuteWith allows injecting custom n:-attribute handlers from outside. Order of precedence: defaults < global < provided