template

package
v0.0.0-...-ba7cdbd Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2014 License: MPL-2.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AssetFuncName = "asset"
)

Variables

View Source
var (
	ErrNoAssetsManager       = errors.New("template does not have an assets manager")
	ErrAssetsAlreadyPrepared = errors.New("assets have been already prepared")
)

Functions

func AddFuncs

func AddFuncs(f FuncMap)

AddFuncs registers new functions which will be available to the templates. Please, note that you must register the functions before compiling a template that uses them, otherwise the template parser will return an error.

func DefaultVFS

func DefaultVFS() vfs.VFS

DefaultVFS returns a VFS which loads templates from the tmpl directory, relative to the application binary.

func NamespacedName

func NamespacedName(ns []string, name string) string

func RegisterConverter

func RegisterConverter(ext string, c Converter)

RegisterConverter registers a template converter for the given extension. If there's already a converter for the given extension, it's overwritten by the new one.

Types

type CSS

type CSS template.CSS

type Converter

type Converter func([]byte) ([]byte, error)

Converter represents a function which converts a template source with a given extension into the source of an HTML template. Use RegisterConverter to register your own converters.

type FuncMap

type FuncMap map[string]interface{}

type HTML

type HTML template.HTML

type HTMLAttr

type HTMLAttr template.HTMLAttr

type Hook

type Hook struct {
	Template *Template
	Position assets.Position
}

type JS

type JS template.JS

type JSStr

type JSStr template.JSStr

type State

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

State represents the execution state of a template. Users should never create a State manually, but can access its methods via template stat functions.

func (*State) Dot

func (s *State) Dot() reflect.Value

func (*State) Set

func (s *State) Set(name string, value interface{})

func (*State) Unset

func (s *State) Unset(name string) bool

func (*State) Var

func (s *State) Var(name string) (reflect.Value, bool)

type Template

type Template struct {
	AssetsManager *assets.Manager
	Minify        bool

	Debug bool
	// contains filtered or unexported fields
}

func MustParse

func MustParse(fs vfs.VFS, manager *assets.Manager, name string) *Template

MustParse works like parse, but panics if there's an error

func New

func New(fs vfs.VFS, manager *assets.Manager) *Template

New returns a new template with the given VFS and assets manager. Please, refer to the documention in gopkgs.com/vfs.v1 and gnd.la/template/assets for further information in those types. If the fs is nil, DefaultVFS() will be used.

func Parse

func Parse(fs vfs.VFS, manager *assets.Manager, name string) (*Template, error)

Parse creates a new template using the given VFS and manager and then parses the template with the given name.

func (*Template) AddAssets

func (t *Template) AddAssets(groups []*assets.Group) error

func (*Template) AddNamespace

func (t *Template) AddNamespace(ns string)

func (*Template) AddParseTree

func (t *Template) AddParseTree(name string, tree *parse.Tree) error

func (*Template) Asset

func (t *Template) Asset(arg string) (string, error)

func (*Template) Assets

func (t *Template) Assets() []*assets.Group

func (*Template) Compile

func (t *Template) Compile() error

func (*Template) ContentType

func (t *Template) ContentType() string

ContentType returns the template content type, usually found by its extension.

func (*Template) Execute

func (t *Template) Execute(w io.Writer, data interface{}) error

Execute is a shorthand for ExecuteContext(w, data, nil, nil).

func (*Template) ExecuteContext

func (t *Template) ExecuteContext(w io.Writer, data interface{}, context interface{}, vars VarMap) error

func (*Template) Funcs

func (t *Template) Funcs(funcs FuncMap) *Template

func (*Template) Hook

func (t *Template) Hook(hook *Hook) error

func (*Template) Include

func (t *Template) Include(name string) error

func (*Template) InsertTemplate

func (t *Template) InsertTemplate(tmpl *Template, name string) error

func (*Template) IsFinal

func (t *Template) IsFinal() bool

func (*Template) Name

func (t *Template) Name() string

func (*Template) Namespace

func (t *Template) Namespace() string

func (*Template) Parse

func (t *Template) Parse(name string) error

Parse parses the template starting with the given template name (and following any extends/includes directives declared in it).

func (*Template) ParseVars

func (t *Template) ParseVars(name string, vars VarMap) error

func (*Template) Root

func (t *Template) Root() string

func (*Template) SetDropComments

func (t *Template) SetDropComments(drop bool) error

func (*Template) Trees

func (t *Template) Trees() map[string]*parse.Tree

type URL

type URL template.URL

type VarMap

type VarMap map[string]interface{}

Directories

Path Synopsis
Package markdown implements a Markdown template converter.
Package markdown implements a Markdown template converter.

Jump to

Keyboard shortcuts

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