Documentation
¶
Index ¶
- Constants
- Variables
- func AddFunc(fn *Func)
- func AddFuncs(fn []*Func)
- func DefaultVFS() vfs.VFS
- func NamespacedName(ns []string, name string) string
- func RegisterConverter(ext string, c Converter)
- func RegisterFunc(name string, fn interface{}, opts ...FuncOption)
- type CSS
- type Converter
- type Func
- type FuncMap
- type FuncOption
- type FuncTrait
- type HTML
- type HTMLAttr
- type JS
- type JSStr
- type Plugin
- type State
- type Template
- func (t *Template) AddAssets(groups []*assets.Group) error
- func (t *Template) AddNamespace(ns string)
- func (t *Template) AddParseTree(name string, tree *parse.Tree) error
- func (t *Template) AddPlugin(plugin *Plugin) error
- func (t *Template) Asset(arg string) (string, error)
- func (t *Template) Assets() []*assets.Group
- func (t *Template) Compile() error
- func (t *Template) ContentType() string
- func (t *Template) Execute(w io.Writer, data interface{}) error
- func (t *Template) ExecuteContext(w io.Writer, data interface{}, context interface{}, vars VarMap) error
- func (t *Template) Funcs(funcs []*Func) *Template
- func (t *Template) Include(name string) error
- func (t *Template) InsertTemplate(tmpl *Template, name string) error
- func (t *Template) IsFinal() bool
- func (t *Template) Name() string
- func (t *Template) Namespace() string
- func (t *Template) Parse(name string) error
- func (t *Template) ParseVars(name string, vars VarMap) error
- func (t *Template) RawFuncs(funcs map[string]interface{}) *Template
- func (t *Template) Root() string
- func (t *Template) Trees() map[string]*parse.Tree
- type URL
- type VarMap
Constants ¶
const (
AssetFuncName = "asset"
)
Variables ¶
var ( ErrNoAssetsManager = errors.New("template does not have an assets manager") ErrAssetsAlreadyPrepared = errors.New("assets have been already prepared") )
Functions ¶
func AddFuncs ¶
func AddFuncs(fn []*Func)
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 ¶
DefaultVFS returns a VFS which loads templates from the tmpl directory, relative to the application binary.
func NamespacedName ¶
func RegisterConverter ¶
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.
func RegisterFunc ¶
func RegisterFunc(name string, fn interface{}, opts ...FuncOption)
RegisterFunc registers a template func and makes it available to all templates.
Types ¶
type CSS ¶
These types are aliases for the ones defined in html/template. They will be escaped by the template engine exactly the same as their html/template counterparts.
func (CSS) ContentType ¶
func (v CSS) ContentType() htmltemplate.ContentType
type Converter ¶
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 Func ¶
type Func struct { Name string Fn interface{} Traits FuncTrait // contains filtered or unexported fields }
Func represents a function which is available to be called from a template.
type FuncOption ¶
type FuncTrait ¶
type FuncTrait int
FuncTrait indicates the traits of a template function, which allow the template engine to pass additional arguments to them.
const ( // FuncTraitPure declares the function as pure (depends only on its arguments) and allows // evaluating at compile time if its arguments are constant. FuncTraitPure FuncTrait = 1 << iota // FuncTraitContext declares as a Context function. Context functions receive an additional // Context argument as passed to Template.ExecuteContext. // The Context argument type must be assignable from the type of the // Context used during execution. The Context argument is passed before the arguments // in the template function call. e.g. // // func MyFunction(ctx *MyTemplateContext, someArg someType, someotherArg...) someThing // FuncTraitContext // FuncTraitState declares a State function. Note that a function might be both a Context // and a State function, with the State argument coming before the Context argument. The // State argument is a pointer to the execution state of the template, as represented by // the State type. State functions might use any method exported by State. e.g. // // func MyStateFunction(s *State, someArg someType, someotherArg...) someThing // FuncTraitState )
type HTML ¶
These types are aliases for the ones defined in html/template. They will be escaped by the template engine exactly the same as their html/template counterparts.
func (HTML) ContentType ¶
func (v HTML) ContentType() htmltemplate.ContentType
type HTMLAttr ¶
These types are aliases for the ones defined in html/template. They will be escaped by the template engine exactly the same as their html/template counterparts.
func (HTMLAttr) ContentType ¶
func (v HTMLAttr) ContentType() htmltemplate.ContentType
type JS ¶
These types are aliases for the ones defined in html/template. They will be escaped by the template engine exactly the same as their html/template counterparts.
func (JS) ContentType ¶
func (v JS) ContentType() htmltemplate.ContentType
type JSStr ¶
These types are aliases for the ones defined in html/template. They will be escaped by the template engine exactly the same as their html/template counterparts.
func (JSStr) ContentType ¶
func (v JSStr) ContentType() htmltemplate.ContentType
type Plugin ¶
A Plugin represents a template which can be automatically attached to another template without the parent template invoking the plugged-in template. Depending on the Position field, the plugin might be inserted at the following locations.
assets.Position.Top: Inside the <head> assets.Position.Bottom: Just before the <body> is closed. assets.Position.None: The plugin is added to the template, but it must invoke it explicitely.
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 state functions.
type Template ¶
type Template struct { AssetsManager *assets.Manager Minify bool Debug bool // contains filtered or unexported fields }
func New ¶
New returns a new template with the given VFS and assets manager. Please, refer to the documention in github.com/rainycape/vfs and gnd.la/template/assets for further information in those types. If the fs is nil, DefaultVFS() will be used.
func Parse ¶
Parse creates a new template using the given VFS and manager and then parses the template with the given name.
func ParseFromDir ¶
ParseFromDir is a conveniency function which creates a vfs.VFS rooted at dir and creates a new template from the file with the given name. It's equivalent to Parse(vfs.FS(dir), manager, name) (minus error handling).
func (*Template) AddNamespace ¶
func (*Template) AddParseTree ¶
func (*Template) AddPlugin ¶
AddPlugin plugs another template into this one. See the Plugin type for more information.
func (*Template) ContentType ¶
ContentType returns the template content type, usually found by its extension.
func (*Template) ExecuteContext ¶
func (*Template) InsertTemplate ¶
type URL ¶
These types are aliases for the ones defined in html/template. They will be escaped by the template engine exactly the same as their html/template counterparts.
func (URL) ContentType ¶
func (v URL) ContentType() htmltemplate.ContentType
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
sass
Package sass implements a sass compiler for assets.
|
Package sass implements a sass compiler for assets. |
internal
|
|
htmltemplate
Package template (html/template) implements data-driven templates for generating HTML output safe against code injection.
|
Package template (html/template) implements data-driven templates for generating HTML output safe against code injection. |
Package markdown implements a Markdown template converter.
|
Package markdown implements a Markdown template converter. |