template

package
v0.0.0-...-5c5b187 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2016 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Execute

func Execute(t Template, ctx Context) (buf bytes.Buffer, err error)

Execute - Executes given template with context and returns buffer.

func ExecuteList

func ExecuteList(templates []Template, ctx Context) (res []string, err error)

ExecuteList - Executes a list of templates to strings.

func ExecuteToBytes

func ExecuteToBytes(t Template, ctx Context) (res []byte, err error)

ExecuteToBytes - Executes template with context and returns string result.

func ExecuteToString

func ExecuteToString(t Template, ctx Context) (res string, err error)

ExecuteToString - Executes template with context and returns string result.

Types

type Context

type Context map[string]interface{}

Context - Template context.

func (Context) Clone

func (ctx Context) Clone() (res Context)

Clone - Clones context.

func (Context) Get

func (ctx Context) Get(key string) (_ interface{})

Get - Gets value by key. It might deep traverse if key doesnt exist and contains a dot.

func (Context) WithDefaults

func (ctx Context) WithDefaults(source Context) Context

WithDefaults - Sets values from `source` only if previously didnt exist. It may return a new map if called on nil Context.

type Map

type Map map[string]MapNode

Map - Template map.

func ParseMap

func ParseMap(m Context) (res Map, err error)

ParseMap - Parses map from context map.

func (Map) Execute

func (nodes Map) Execute(ctx Context) (res Context, err error)

Execute - Executes a map of templates and/or values.

func (Map) ParseAndMerge

func (nodes Map) ParseAndMerge(input Context) (Map, error)

ParseAndMerge - Parses a map of templates and merges into current map. If `t == nil` it may return a new map.

type MapNode

type MapNode interface {
	Execute(Context) (interface{}, error)
}

MapNode - Template map node.

type Template

type Template interface {
	Execute(Context, io.Writer) error
}

Template - Template structure.

func FromBytes

func FromBytes(body []byte) (t Template, err error)

FromBytes - Creates a new template structure from byte array.

func FromFile

func FromFile(fname string) (t Template, err error)

FromFile - Creates a new template structure from file.

func FromString

func FromString(body string) (t Template, err error)

FromString - Creates a new template structure from string.

func Text

func Text(text string) Template

Text - Returns template interface that does not actually execute templates.

func TextBytes

func TextBytes(text []byte) Template

TextBytes - Returns template interface that does not actually execute templates.

Jump to

Keyboard shortcuts

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