Documentation
¶
Overview ¶
Package render is an internal package that renders a compiled template parse tree.
Index ¶
- type BlockCompiler
- type BlockNode
- type Config
- func (g Config) AddBlock(name string) blockDefBuilder
- func (c *Config) AddTag(name string, td TagCompiler)
- func (g Config) BlockSyntax(name string) (parser.BlockSyntax, bool)
- func (c *Config) Compile(source string, loc parser.SourceLoc) (Node, parser.Error)
- func (c *Config) FindTagDefinition(name string) (TagCompiler, bool)
- type Context
- type Error
- type FileTemplateStore
- type Node
- type ObjectNode
- type RawNode
- type SeqNode
- type TagCompiler
- type TagNode
- type TemplateStore
- type TextNode
- type TrimNode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BlockCompiler ¶
BlockCompiler builds a renderer for the tag instance.
type BlockNode ¶
type BlockNode struct {
parser.Token
Body []Node
Clauses []*BlockNode
// contains filtered or unexported fields
}
BlockNode represents a {% tag %}…{% endtag %}.
type Config ¶
type Config struct {
parser.Config
Cache map[string][]byte
StrictVariables bool
TemplateStore TemplateStore
// contains filtered or unexported fields
}
Config holds configuration information for parsing and rendering.
func NewConfig ¶
func NewConfig() Config
NewConfig creates a new Settings. TemplateStore is initialized to a FileTemplateStore for backwards compatibility
func (Config) AddBlock ¶
func (g Config) AddBlock(name string) blockDefBuilder
AddBlock defines a control tag and its matching end tag.
func (*Config) AddTag ¶
func (c *Config) AddTag(name string, td TagCompiler)
AddTag creates a tag definition.
func (Config) BlockSyntax ¶
func (g Config) BlockSyntax(name string) (parser.BlockSyntax, bool)
BlockSyntax is part of the Grammar interface.
func (*Config) Compile ¶
Compile parses a source template. It returns an AST root, that can be evaluated.
func (*Config) FindTagDefinition ¶
func (c *Config) FindTagDefinition(name string) (TagCompiler, bool)
FindTagDefinition looks up a tag definition.
type Context ¶
type Context interface {
// Bindings returns the current lexical environment.
Bindings() map[string]any
// Get retrieves the value of a variable from the current lexical environment.
Get(name string) any
// Errorf creates a SourceError, that includes the source location.
// Use this to distinguish errors in the template from implementation errors
// in the template engine.
Errorf(format string, a ...any) Error
// Evaluate evaluates a compiled expression within the current lexical context.
Evaluate(expressions.Expression) (any, error)
// EvaluateString compiles and evaluates a string expression such as “x”, “x < 10", or “a.b | split | first | default: 10”, within the current lexical context.
EvaluateString(string) (any, error)
// ExpandTagArg renders the current tag argument string as a Liquid template.
// It enables the implementation of tags such as Jekyll's "{% include {{ page.my_variable }} %}" andjekyll-avatar's "{% avatar {{page.author}} %}".
ExpandTagArg() (string, error)
// InnerString is the rendered content of the current block.
// It's used in the implementation of the Liquid "capture" tag and the Jekyll "highlght" tag.
InnerString() (string, error)
// RenderBlock is used in the implementation of the built-in control flow tags.
// It's not guaranteed stable.
RenderBlock(io.Writer, *BlockNode) error
// RenderChildren is used in the implementation of the built-in control flow tags.
// It's not guaranteed stable.
RenderChildren(io.Writer) Error
// RenderFile parses and renders a template. It's used in the implementation of the {% include %} tag.
// RenderFile does not cache the compiled template.
RenderFile(string, map[string]any) (string, error)
// Set updates the value of a variable in the current lexical environment.
// It's used in the implementation of the {% assign %} and {% capture %} tags.
Set(name string, value any)
// SourceFile retrieves the value set by template.SetSourcePath.
// It's used in the implementation of the {% include %} tag.
SourceFile() string
// TagArgs returns the text of the current tag, not including its name.
// For example, the arguments to {% my_tag a b c %} would be “a b c”.
TagArgs() string
// TagName returns the name of the current tag; for example "my_tag" for {% my_tag a b c %}.
TagName() string
// WrapError creates a new error that records the source location from the current context.
WrapError(err error) Error
}
Context provides the rendering context for a tag renderer.
type FileTemplateStore ¶ added in v1.7.0
type FileTemplateStore struct{}
func (*FileTemplateStore) ReadTemplate ¶ added in v1.7.0
func (tl *FileTemplateStore) ReadTemplate(filename string) ([]byte, error)
type Node ¶
type Node interface {
SourceLocation() parser.SourceLoc // for error reporting
SourceText() string // for error reporting
// contains filtered or unexported methods
}
Node is a node of the render tree.
type ObjectNode ¶
ObjectNode is an {{ object }} object.
type RawNode ¶
type RawNode struct {
// contains filtered or unexported fields
}
RawNode holds the text between the start and end of a raw tag.
func (*RawNode) SourceLocation ¶ added in v0.2.0
func (*RawNode) SourceText ¶ added in v0.2.0
func (n *RawNode) SourceText() string
type SeqNode ¶
type SeqNode struct {
Children []Node
// contains filtered or unexported fields
}
SeqNode is a sequence of nodes.
func (*SeqNode) SourceLocation ¶ added in v0.2.0
func (*SeqNode) SourceText ¶ added in v0.2.0
func (n *SeqNode) SourceText() string
type TagCompiler ¶
TagCompiler is a function that parses the tag arguments, and returns a renderer. TODO instead of using the bare function definition, use a structure that defines how to parse
type TemplateStore ¶ added in v1.7.0
type TrimNode ¶ added in v1.5.0
type TrimNode struct {
parser.TrimDirection
// contains filtered or unexported fields
}
TrimNode is a trim object.
func (*TrimNode) SourceLocation ¶ added in v1.5.0
func (*TrimNode) SourceText ¶ added in v1.5.0
func (n *TrimNode) SourceText() string