Documentation
¶
Index ¶
- type BlockNode
- type Context
- func (c *Context) Flatten() map[string]any
- func (c *Context) Get(key string) (any, bool)
- func (c *Context) GetEngine() *Engine
- func (c *Context) GetRenderState(key string) any
- func (c *Context) Pop() map[string]any
- func (c *Context) Push(data map[string]any)
- func (c *Context) Resolve(path string) any
- func (c *Context) Set(key string, value any)
- func (c *Context) SetRenderState(key string, val any)
- type Engine
- type FilterFunc
- type Lexer
- type Library
- type Node
- type NodeList
- type Parser
- type SafeString
- type TagParser
- type Template
- type TextNode
- type Token
- type TokenType
- type VariableNode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BlockNode ¶
type BlockNode struct {
TagName string
TagArgs string
Children NodeList
// Used for blocks that have alternative branches like {% else %}
ElseChildren NodeList
}
BlockNode represents a built-in block like {% if %} or custom blocks.
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context represents a stack of dictionaries for template rendering.
func NewContext ¶
NewContext creates a new context with an initial dictionary.
func (*Context) Flatten ¶
Flatten combines all dictionaries in the stack into a single map. Values higher in the stack take precedence.
func (*Context) GetRenderState ¶
GetRenderState fetches internal engine state data.
func (*Context) Resolve ¶
Resolve allows external packages (like tags) to resolve variables using the private resolver.
func (*Context) SetRenderState ¶
SetRenderState saves internal engine state data.
type Engine ¶
type Engine struct {
DIRS []string
APP_DIRS bool
Autoescape bool
Libraries map[string]*Library
Builtins []*Library
Loaders []loaders.Loader
// contains filtered or unexported fields
}
Engine is responsible for loading and rendering templates.
func (*Engine) AddBuiltin ¶
AddBuiltin adds a library that is always loaded
func (*Engine) FromString ¶
FromString compiles a template directly from a string.
func (*Engine) GetTemplate ¶
GetTemplate loads a template by name, optionally from cache.
func (*Engine) RegisterLibrary ¶
RegisterLibrary makes a library available for `{% load %}`
type FilterFunc ¶
FilterFunc is a function that filters a template variable.
type Lexer ¶
type Lexer struct {
Tokens []Token
// contains filtered or unexported fields
}
Lexer breaks a template string into tokens.
type Library ¶
type Library struct {
Tags map[string]TagParser
Filters map[string]FilterFunc
}
Library represents a collection of tags and filters.
func (*Library) RegisterFilter ¶
func (l *Library) RegisterFilter(name string, filter FilterFunc)
RegisterFilter registers a filter function.
func (*Library) RegisterTag ¶
RegisterTag registers a tag parser.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser builds an AST from tokens.
func (*Parser) PrependToken ¶
PrependToken puts a token back into the stream.
func (*Parser) RegisterTag ¶
RegisterTag allows a tag to register tags to the parser dynamically (e.g. {% load %})
type SafeString ¶
type SafeString string
SafeString represents a string that has already been safely HTML-escaped and should bypass autoescaping during rendering.
type Template ¶
type Template struct {
// contains filtered or unexported fields
}
Template represents a parsed template.
func (*Template) RenderToResponse ¶
func (t *Template) RenderToResponse(req *godjangohttp.Request, ctx *Context) godjangohttp.Response
RenderToResponse renders the template and returns an HttpResponse.
type VariableNode ¶
type VariableNode struct {
Expression string
}
VariableNode renders a context variable, applying filters.