Documentation
¶
Overview ¶
Package render renders a template parse tree.
Except where noted in the documentation for the liquid package, even public symbols in this package are intended to be public only to other subpackages within this repo, and are not guaranteed stable even across subminor version number increments.
Index ¶
- type BlockCompiler
- type BlockNode
- type CompilationError
- 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) (parser.ASTNode, CompilationError)
- func (c *Config) FindTagDefinition(name string) (TagCompiler, bool)
- type Context
- type Error
- type Node
- type ObjectNode
- type RawNode
- type SeqNode
- type TagCompiler
- type TagNode
- type TextNode
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 Branches []*BlockNode // contains filtered or unexported fields }
BlockNode represents a {% tag %}…{% endtag %}.
type CompilationError ¶
A CompilationError is an error in the template source, encountered during template compilation.
type Config ¶
Config holds configuration information for parsing and rendering.
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 ¶
func (c Config) Compile(source string) (parser.ASTNode, CompilationError)
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 { // Get retrieves the value of a variable from the lexical environment. Get(name string) interface{} // Errorf creates a render Error, that includes the source location. // Use this to distinguish template errors from implementation errors. Errorf(format string, a ...interface{}) Error // Evaluate evaluates an expression within the template context. Evaluate(expr expression.Expression) (interface{}, error) // Evaluate compiles and interprets an expression, such as “x”, “x < 10", or “a.b | split | first | default: 10”, within the current lexical context. EvaluateString(source string) (interface{}, error) // EvaluateStatement evaluates a statement of the expression syntax. // Tag must be a special string known to the compiler. // For example, {% for %} uses this to parse the loop syntax. EvaluateStatement(tag, source string) (interface{}, error) // ExpandTagArg renders the current tag argument string as a Liquid template. // It enables the implementation of tags such as {% avatar {{page.author}} %}, from the jekyll-avatar plugin; or Jekyll's {% include %} parameters. ExpandTagArg() (string, error) // InnerString is the rendered children of the current block. InnerString() (string, error) RenderChild(io.Writer, *BlockNode) error RenderChildren(io.Writer) Error RenderFile(string, map[string]interface{}) (string, error) // Set updates the value of a variable in the lexical environment. // For example, {% assign %} and {% capture %} use this. Set(name string, value interface{}) // SourceFile retrieves the value set by template.SetSourcePath. // {% include %} uses this. 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. TagName() string // WrapError creates a new error that records the source location. WrapError(err error) Error }
Context provides the rendering context for a tag renderer.
This interface shares the compatibility committments of the top-level liquid package.
type Node ¶
type Node interface { SourceLocation() parser.SourceLoc // for error reporting SourceText() string // for error reporting }
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