soyhtml

package
v0.0.0-...-4dafff4 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2017 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package soyhtml renders a compiled set of Soy to HTML.

Index

Constants

This section is empty.

Variables

View Source
var ErrTemplateNotFound = errors.New("template not found")
View Source
var Funcs = map[string]Func{
	"isNonnull":   {funcIsNonnull, []int{1}},
	"length":      {funcLength, []int{1}},
	"keys":        {funcKeys, []int{1}},
	"augmentMap":  {funcAugmentMap, []int{2}},
	"round":       {funcRound, []int{1, 2}},
	"floor":       {funcFloor, []int{1}},
	"ceiling":     {funcCeiling, []int{1}},
	"min":         {funcMin, []int{2}},
	"max":         {funcMax, []int{2}},
	"randomInt":   {funcRandomInt, []int{1}},
	"strContains": {funcStrContains, []int{2}},
	"range":       {funcRange, []int{1, 2, 3}},
	"hasData":     {funcHasData, []int{0}},
}

Funcs contains the builtin soy functions. Callers may add their own functions to this map as well.

View Source
var Logger *log.Logger

Logger collects output from {log} commands.

View Source
var PrintDirectives = map[string]PrintDirective{
	"insertWordBreaks":  {directiveInsertWordBreaks, []int{1}, true},
	"changeNewlineToBr": {directiveChangeNewlineToBr, []int{0}, true},
	"truncate":          {directiveTruncate, []int{1, 2}, false},
	"id":                {directiveNoAutoescape, []int{0}, true},
	"noAutoescape":      {directiveNoAutoescape, []int{0}, true},
	"escapeHtml":        {directiveEscapeHtml, []int{0}, true},
	"escapeUri":         {directiveEscapeUri, []int{0}, true},
	"escapeJsString":    {directiveEscapeJsString, []int{0}, true},
	"bidiSpanWrap":      {nil, []int{0}, false},
	"bidiUnicodeWrap":   {nil, []int{0}, false},
	"json":              {directiveJson, []int{0}, true},
}

PrintDirectives are the builtin print directives. Callers may add their own print directives to this map.

Functions

func EvalExpr

func EvalExpr(node ast.Node) (val data.Value, err error)

EvalExpr evaluates the given expression node and returns the result. The given node must be a simple Soy expression, such as what may appear inside a print tag.

This is useful for evaluating Globals, or anything returned from parse.Expr.

Types

type Func

type Func struct {
	Apply           func([]data.Value) data.Value
	ValidArgLengths []int
}

Func represents a soy function that may be invoked within a soy template.

type PrintDirective

type PrintDirective struct {
	Apply            func(value data.Value, args []data.Value) data.Value
	ValidArgLengths  []int
	CancelAutoescape bool
}

PrintDirective represents a transformation applied when printing a value.

type Renderer

type Renderer struct {
	// contains filtered or unexported fields
}

Renderer provides parameters to template execution. At minimum, Registry and Template are required to render a template..

func (Renderer) Execute

func (t Renderer) Execute(wr io.Writer, obj data.Map) (err error)

Execute applies a parsed template to the specified data object, and writes the output to wr.

func (*Renderer) Inject

func (r *Renderer) Inject(ij data.Map) *Renderer

Inject sets the given data map as the $ij injected data.

func (*Renderer) WithMessages

func (r *Renderer) WithMessages(bundle soymsg.Bundle) *Renderer

WithMessages provides a message bundle to use during execution.

type Tofu

type Tofu struct {
	// contains filtered or unexported fields
}

Tofu is a bundle of compiled soy, ready to render to HTML.

func NewTofu

func NewTofu(registry *template.Registry) *Tofu

NewTofu returns a new instance that is ready to provide HTML rendering services for the given templates, with the default functions and print directives.

func (*Tofu) NewRenderer

func (tofu *Tofu) NewRenderer(name string) *Renderer

NewRenderer returns a new instance of a soy html renderer, given the fully-qualified name of the template to render.

func (Tofu) Render

func (tofu Tofu) Render(wr io.Writer, name string, obj interface{}) error

Render is a convenience function that executes the soy template of the given name, using the given object (converted to data.Map) as context, and writes the results to the given Writer.

When converting structs to soy's data format, the DefaultStructOptions are used. In particular, note that struct properties are converted to lowerCamel by default, since that is the Soy naming convention. The caller may update those options to change the behavior of this function.

Jump to

Keyboard shortcuts

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