render

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 10, 2017 License: MIT Imports: 9 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockCompiler

type BlockCompiler func(BlockNode) (func(io.Writer, Context) error, error)

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

type CompilationError interface {
	error
	Cause() error
	Filename() string
	LineNumber() int
}

A CompilationError is an error in the template source, encountered during template compilation.

type Config

type Config struct {
	parser.Config
	// contains filtered or unexported fields
}

Config holds configuration information for parsing and rendering.

func NewConfig

func NewConfig() Config

NewConfig creates a new Settings.

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 Error

type Error interface {
	Filename() string
	LineNumber() int
	Cause() error
	Error() string
}

An Error is a rendering error during template rendering.

func Render

func Render(node Node, w io.Writer, vars map[string]interface{}, c Config) Error

Render renders the render tree.

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

type ObjectNode struct {
	parser.Token
	// contains filtered or unexported fields
}

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 (n *RawNode) SourceLocation() parser.SourceLoc

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 (n *SeqNode) SourceLocation() parser.SourceLoc

func (*SeqNode) SourceText added in v0.2.0

func (n *SeqNode) SourceText() string

type TagCompiler

type TagCompiler func(expr string) (func(io.Writer, Context) error, error)

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 TagNode

type TagNode struct {
	parser.Token
	// contains filtered or unexported fields
}

TagNode renders itself via a render function that is created during parsing.

type TextNode

type TextNode struct {
	parser.Token
}

TextNode is a text chunk, that is rendered verbatim.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL