render

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Package render parses and evaluates template strings.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Render

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

Render renders the render tree.

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 string

A CompilationError is a parse error during template compilation.

func (CompilationError) Error

func (e CompilationError) Error() string

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 (c 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 (c 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, error)

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(name string) interface{}
	Evaluate(expr expression.Expression) (interface{}, error)
	EvaluateString(source string) (interface{}, error)
	EvaluateStatement(tag, source string) (interface{}, error)
	ExpandTagArg() (string, error)
	InnerString() (string, error)
	RenderChild(io.Writer, *BlockNode) error
	RenderChildren(io.Writer) error
	RenderFile(string, map[string]interface{}) (string, error)
	Set(name string, value interface{})
	SourceFile() string
	TagArgs() string
	TagName() string
}

Context provides the rendering context for a tag renderer.

type Error

type Error string

An Error is an evaluation error during template rendering.

func Errorf

func Errorf(format string, a ...interface{}) Error

Errorf creates a render error.

func (Error) Error

func (e Error) Error() string

type Node

type Node interface {
}

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.

type SeqNode

type SeqNode struct {
	Children []Node
}

SeqNode is a sequence of nodes.

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