Documentation ¶
Index ¶
- Constants
- Variables
- func DisableSessionContextStore(s *sessions.Session)
- func EnableSessionContextStore(s *sessions.Session)
- func ExecuteContext(c *Context, wr io.Writer, data interface{}) error
- func RegisterPackage(name string, i interface{})
- func RegisterPlugin(p Plugin, opts *PluginOpts) error
- func ResetEnvironment(s *sessions.Session)
- func TriggerGlobalEvent(s *sessions.Session, eventName string, params ...interface{})
- type Action
- type Args
- type Context
- func (c *Context) Delete(key interface{})
- func (c *Context) DomID() string
- func (c *Context) GenDomID(id string) string
- func (c *Context) Get(key interface{}, vars ...func() interface{}) (value interface{}, ok bool)
- func (c *Context) ID() string
- func (c *Context) New(t *Template, id string, vars ...[]string) *Context
- func (c *Context) Pull(key interface{}, vars ...func() interface{}) (interface{}, bool)
- func (c *Context) Release()
- func (c *Context) RootID() string
- func (c *Context) Session() *sessions.Session
- func (c *Context) Set(key interface{}, value interface{})
- func (c *Context) StoreDelete(key interface{})
- func (c *Context) StoreGet(key interface{}, vars ...func() interface{}) (value interface{}, ok bool)
- func (c *Context) StorePull(key interface{}, vars ...func() interface{}) (interface{}, bool)
- func (c *Context) StoreSet(key interface{}, value interface{})
- func (c *Context) Styles() []string
- func (c *Context) StylesString() (str string)
- func (c *Context) Template() *Template
- func (c *Context) TriggerEvent(eventName string, params ...interface{})
- func (c *Context) Update(vars ...interface{}) error
- type ContextStore
- type ExecOpts
- type FuncMap
- type GetDataFunc
- type Plugin
- type PluginData
- type PluginOpts
- type Template
- func Must(t *Template, err error) *Template
- func New(uid string, name string) *Template
- func ParseFiles(uid string, filenames ...string) (*Template, error)
- func ParseGlob(uid string, pattern string) (*Template, error)
- func ParseRec(uid string, dir string, excludeDirs ...string) (*Template, error)
- func ParseRecToNamespace(uid string, namespace string, dir string, excludeDirs ...string) (*Template, error)
- func (t *Template) AddStyleClass(styleClass string) *Template
- func (t *Template) Delims(left, right string) *Template
- func (t *Template) Execute(s *sessions.Session, wr io.Writer, optArgs ...ExecOpts) (c *Context, err error)
- func (t *Template) ExecuteTemplate(s *sessions.Session, wr io.Writer, name string, optArgs ...ExecOpts) (c *Context, found bool, err error)
- func (t *Template) ExecuteTemplateToString(s *sessions.Session, name string, optArgs ...ExecOpts) (string, *Context, bool, error)
- func (t *Template) ExecuteToString(s *sessions.Session, optArgs ...ExecOpts) (string, *Context, error)
- func (t *Template) Funcs(funcMap FuncMap) *Template
- func (t *Template) Lookup(name string) *Template
- func (t *Template) LookupFatal(name string) (tt *Template)
- func (t *Template) LookupMust(name string) (tt *Template)
- func (t *Template) Name() string
- func (t *Template) New(name string) *Template
- func (t *Template) OffTemplateExecution(f func(c *Context, data interface{}))
- func (t *Template) OffTemplateExecutionFinished(f func(c *Context, data interface{}))
- func (t *Template) OnGetData(f GetDataFunc) *Template
- func (t *Template) OnTemplateExecution(f func(c *Context, data interface{}))
- func (t *Template) OnTemplateExecutionFinished(f func(c *Context, data interface{}))
- func (t *Template) OnceTemplateExecution(f func(c *Context, data interface{}))
- func (t *Template) OnceTemplateExecutionFinished(f func(c *Context, data interface{}))
- func (t *Template) Parse(src string) (tt *Template, err error)
- func (t *Template) ParseFiles(filenames ...string) (*Template, error)
- func (t *Template) ParseGlob(pattern string) (*Template, error)
- func (t *Template) ParseRec(dir string, excludeDirs ...string) (*Template, error)
- func (t *Template) ParseRecToNamespace(namespace string, dir string, excludeDirs ...string) (*Template, error)
- func (t *Template) RegisterEvents(i interface{}, vars ...string) *Template
- func (t *Template) RegisterFuncs(i interface{}, vars ...string) *Template
- func (t *Template) SetStaticDomID(id string) *Template
- func (t *Template) Templates() []*Template
- func (t *Template) UID() string
Constants ¶
const (
EventMethodPrefix = "Event"
)
const (
FuncMethodPrefix = "Func"
)
const (
GlobalID = "global"
)
const (
MustMethodPrefix = "Must"
)
Variables ¶
var ( // Custom error types. ErrNoFilesFound = errors.New("bulldozer/template: no files named in call to ParseFiles") ErrPatternMatchesNoFiles = errors.New("bulldozer/template: pattern matches no files!") )
var (
ExecTemplateAbort = errors.New("Template execution aborted")
)
Functions ¶
func DisableSessionContextStore ¶
DisableSessionContextStore disables the context store for the session.
func EnableSessionContextStore ¶
EnableSessionContextStore enables the context store for the session. All current active contexts of the session will be saved to the sessions instance values. This adds some overhead during each render request. Only activate this if you need access to the sessions contexts.
func ExecuteContext ¶
ExecuteContext executes the template context.
func RegisterPackage ¶
func RegisterPackage(name string, i interface{})
RegisterPackage registeres a new template package. This call is not thread-safe! Register packages during program initialization. A template package function has the following syntax: func (p *Package) MustIsAuth(a *template.Action, c *template.Context) {}
func RegisterPlugin ¶
func RegisterPlugin(p Plugin, opts *PluginOpts) error
RegisterPlugin adds and registers a template plugin with the given type. This method call is not thread-safe!
func ResetEnvironment ¶
ResetEnvironment releases all registered session events. All previously registered client event calls will be invalid. If a context store is present, then this is also resetted.
func TriggerGlobalEvent ¶
TriggerGlobalEvent triggers the global event on the client side defined with the template event syntax.
Types ¶
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
func (*Context) Delete ¶
func (c *Context) Delete(key interface{})
Delete removes the execution value with the given key. This operation is thread-safe.
func (*Context) GenDomID ¶
GenDomID generates the real DOM ID of id. This is equivalent to the following template call: {{id "YOUR_ID"}}
func (*Context) Get ¶
Get obtains the execution value. Execution values exist for one complete execution cycle. A single variadic argument is accepted, and it is optional: if a function is set, this function will be called if no value exists for the given key. This operation is thread-safe.
func (*Context) ID ¶
ID returns the unique ID of this execution context. Use this for example as database access keys...
func (*Context) New ¶
New creates a new sub context. One optional slice can be passed, which defines additional style classes.
func (*Context) Pull ¶
Pull does the same as Get(), but additionally removes the value from the map if present. Use this for Flash values...
func (*Context) Release ¶
func (c *Context) Release()
Release removes all session template events and releases the current context.
func (*Context) Set ¶
func (c *Context) Set(key interface{}, value interface{})
Set sets the execution value with the given key. This operation is thread-safe.
func (*Context) StoreDelete ¶
func (c *Context) StoreDelete(key interface{})
StoreDelete removes the store value with the given key. This operation is thread-safe.
func (*Context) StoreGet ¶
func (c *Context) StoreGet(key interface{}, vars ...func() interface{}) (value interface{}, ok bool)
StoreGet obtains the store value, which are stored in the session store. They survive application restarts. Values have to be encodable by gob. Don't store pointers! A single variadic argument is accepted, and it is optional: if a function is set, this function will be called if no value exists for the given key. This operation is thread-safe.
func (*Context) StorePull ¶
StorePull does the same as Get(), but additionally removes the value from the store if present. Use this for Flash values...
func (*Context) StoreSet ¶
func (c *Context) StoreSet(key interface{}, value interface{})
StoreSet sets the store value with the given key. This operation is thread-safe.
func (*Context) StylesString ¶
StylesString returns a string of all template styles.
func (*Context) TriggerEvent ¶
TriggerEvent triggers the event on the client side defined with the template event syntax.
type ContextStore ¶
type ContextStore struct {
// contains filtered or unexported fields
}
func GetSessionContextStore ¶
func GetSessionContextStore(s *sessions.Session) *ContextStore
GetSessionContextStore returns the session context store if present or nil.
type FuncMap ¶
type FuncMap map[string]interface{}
FuncMap is the type of the map defining the mapping from names to functions. Each function must have either a single return value, or two return values of which the second has type error. In that case, if the second (error) argument evaluates to non-nil during execution, execution terminates and Execute returns that error. FuncMap has the same base type as FuncMap in "text/template", copied here so clients need not import "text/template".
type GetDataFunc ¶
type GetDataFunc func(c *Context) interface{}
GetDataFunc is called during template execution if no data is specified with the optional execute option. Return the template render data.
type Plugin ¶
type Plugin interface { Prepare(d *PluginData) error // Prepare is called for each plugin context. Settings should be parsed... Render(c *Context, d *PluginData) (interface{}, error) }
type PluginData ¶
type PluginOpts ¶
type Template ¶
type Template struct {
// contains filtered or unexported fields
}
func Must ¶
Must is a helper that wraps a call to a function returning (*Template, error) and panics if the error is non-nil. It is intended for use in variable initializations such as
var t = template.Must(template.New("name").Parse("html"))
func New ¶
New allocates a new bulldozer template with the given name. The uid has to be a unique ID for this new template set. This uid is used to access templates over events even during a bulldozer application restart...
func ParseFiles ¶
ParseFiles creates a new Template and parses the template definitions from the named files. The returned template's name will have the (base) name and (parsed) contents of the first file. There must be at least one file. If an error occurs, parsing stops and the returned *Template is nil.
func ParseGlob ¶
ParseGlob creates a new Template and parses the template definitions from the files identified by the pattern, which must match at least one file. The returned template will have the (base) name and (parsed) contents of the first file matched by the pattern. ParseGlob is equivalent to calling ParseFiles with the list of files matched by the pattern.
func ParseRecToNamespace ¶
func ParseRecToNamespace(uid string, namespace string, dir string, excludeDirs ...string) (*Template, error)
ParseRec parses all template files recursivly in the given directory path. The namespace is prepended to the template name. namespace: bulldozer template name: bulldozer/templatename
func (*Template) AddStyleClass ¶
AddStyleClass adds a style class to the template div. The return value is the template, so calls can be chained.
func (*Template) Delims ¶
Delims sets the action delimiters to the specified strings, to be used in subsequent calls to Parse, ParseFiles, or ParseGlob. Nested template definitions will inherit the settings. An empty delimiter stands for the corresponding default: {{ or }}. The return value is the template, so calls can be chained.
func (*Template) Execute ¶
func (t *Template) Execute(s *sessions.Session, wr io.Writer, optArgs ...ExecOpts) (c *Context, err error)
Execute applies a parsed template to the specified data object, writing the output to wr. If an error occurs executing the template or writing its output, execution stops, but partial results may already have been written to the output writer. A template may be executed safely in parallel. Optional options can be passed.
func (*Template) ExecuteTemplate ¶
func (t *Template) ExecuteTemplate(s *sessions.Session, wr io.Writer, name string, optArgs ...ExecOpts) (c *Context, found bool, err error)
ExecuteTemplate applies the template associated with t that has the given name to the specified data object and writes the output to wr. If an error occurs executing the template or writing its output, execution stops, but partial results may already have been written to the output writer. A template may be executed safely in parallel. A boolean is returned, defining if the template exists... Optional options can be passed.
func (*Template) ExecuteTemplateToString ¶
func (t *Template) ExecuteTemplateToString(s *sessions.Session, name string, optArgs ...ExecOpts) (string, *Context, bool, error)
ExecuteTemplateToString does the same as ExecuteTemplate, but instead writes the output to a string.
func (*Template) ExecuteToString ¶
func (t *Template) ExecuteToString(s *sessions.Session, optArgs ...ExecOpts) (string, *Context, error)
ExecuteToString does the same as Execute, but instead writes the output to a string.
func (*Template) Funcs ¶
Funcs adds the elements of the argument map to the template's function map. It panics if a value in the map is not a function with appropriate return type. However, it is legal to overwrite elements of the map. The return value is the template, so calls can be chained. Functions have to be registered before any template which use these functions are parsed. This method is equivalent of calling the html/template Funcs method.
func (*Template) Lookup ¶
Lookup returns the template with the given name that is associated with t, or nil if there is no such template.
func (*Template) LookupFatal ¶
LookupFatal fatals if the template does not exists with the given name.
func (*Template) LookupMust ¶
LookupMust panics if the template does not exists with the given name.
func (*Template) New ¶
New allocates a new bulldozer template associated with the given one and with the same delimiters. The association, which is transitive, allows one template to invoke another with a {{template}} action.
func (*Template) OffTemplateExecution ¶
OffTemplateExecution removes the listener again
func (*Template) OffTemplateExecutionFinished ¶
OffTemplateExecutionFinished removes the listener again
func (*Template) OnGetData ¶
func (t *Template) OnGetData(f GetDataFunc) *Template
OnGetData set the function which is called during template execution if no data is specified with the optional execute option. Return the template render data.
func (*Template) OnTemplateExecution ¶
OnTemplateExecution is triggered during each template execution
func (*Template) OnTemplateExecutionFinished ¶
OnTemplateExecutionFinished is triggered after each template execution
func (*Template) OnceTemplateExecution ¶
OnceTemplateExecution is the same event as OnTemplateExecution, but the listener is triggered only once
func (*Template) OnceTemplateExecutionFinished ¶
OnceTemplateExecutionFinished is the same event as OnTemplateExecutionFinished, but the listener is triggered only once
func (*Template) Parse ¶
Parse parses a string into a template. Nested template definitions will be associated with the top-level template t. Parse may be called multiple times to parse definitions of templates to associate with t. It is an error if a resulting template is non-empty (contains content other than template definitions) and would replace a non-empty template with the same name. (In multiple calls to Parse with the same receiver template, only one call can contain text other than space, comments, and template definitions.)
func (*Template) ParseFiles ¶
ParseFiles parses the named files and associates the resulting templates with t. If an error occurs, parsing stops and the returned template is nil; otherwise it is t. There must be at least one file.
func (*Template) ParseGlob ¶
ParseGlob parses the template definitions in the files identified by the pattern and associates the resulting templates with t. The pattern is processed by filepath.Glob and must match at least one file. ParseGlob is equivalent to calling t.ParseFiles with the list of files matched by the pattern.
func (*Template) ParseRec ¶
ParseRec parses all template files recursivly in the given directory path.
func (*Template) ParseRecToNamespace ¶
func (t *Template) ParseRecToNamespace(namespace string, dir string, excludeDirs ...string) (*Template, error)
ParseRec parses all template files recursivly in the given directory path. The namespace is prepended to the template name. namespace: bulldozer template name: bulldozer/templatename
func (*Template) RegisterEvents ¶
RegisterEvents registeres the event methods of the interface. Event method names have to start with the 'Event' prefix. They are called from the client-side without this prefix. One optional parameter can be set, to define the events namespace. If no namespace is defined, then the events are registered in the global namespace.
func (*Template) RegisterFuncs ¶
RegisterFuncs registeres the template function methods of the interface. Template function method names have to start with the 'Func' prefix. They are called from the template without this prefix. One optional parameter can be set, to define the functions namespace. If no namespace is defined, then the functions are registered in the global namespace. Only call this method before any template execution. This is not thread-safe.
The first parameter of a template function has to be a template Context pointer. Valid return values are following:
- no return values
- error
- (interface{}, error)
func (*Template) SetStaticDomID ¶
SetStaticDomID sets a static DOM ID instead of using an automatic generated one. The return value is the template, so calls can be chained.