Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ERROR_CLASS = "hasError"
var ( // The functions available for use in the templates. TemplateFuncs = map[string]interface{}{ "set": func(renderArgs map[string]interface{}, key string, value interface{}) template.JS { renderArgs[key] = value return template.JS("") }, "append": func(renderArgs map[string]interface{}, key string, value interface{}) template.JS { if renderArgs[key] == nil { renderArgs[key] = []interface{}{value} } else { renderArgs[key] = append(renderArgs[key].([]interface{}), value) } return template.JS("") }, "firstof": func(args ...interface{}) interface{} { for _, val := range args { switch val.(type) { case nil: continue case string: if val == "" { continue } return val default: return val } } return nil }, "pad": func(str string, width int) template.HTML { if len(str) >= width { return template.HTML(html.EscapeString(str)) } return template.HTML(html.EscapeString(str) + strings.Repeat(" ", width-len(str))) }, "dump": func(v interface{}) template.HTML { return template.HTML(fmt.Sprintf("%v", v)) }, "goto": func(uri string) template.JS { script := `<script language="javascript">window.location.href="%s";</script>` return template.JS(fmt.Sprintf(script, uri)) }, "nl2br": func(text string) template.HTML { return template.HTML(strings.Replace(template.HTMLEscapeString(text), "\n", "<br>", -1)) }, "raw": func(text string) template.HTML { return template.HTML(text) }, "date": func(date time.Time) string { return fmt.Sprintf("%4d-%02d-%02d", date.Year(), date.Month(), date.Day()) }, "datetime": func(date time.Time) string { return fmt.Sprintf("%4d-%02d-%02d %02d:%02d:%02d", date.Year(), date.Month(), date.Day(), date.Hour(), date.Minute(), date.Second()) }, "even": func(a int) bool { return (a % 2) == 0 }, } )
Functions ¶
func ParseTemplateError ¶
Parse the line, and description from an error message like: html/template:Application/Register.html:36: no such template "footer.html"
Types ¶
type Error ¶
type Error struct { SourceType string // The type of source that failed to build. Title, Path, Description string // Description of the error, as presented to the user. Line, Column int // Where the error was encountered. SourceLines []string // The entire source file, split into lines. Stack string // The raw stack trace string from debug.Stack(). MetaError string // Error that occurred producing the error page. Link string // A configurable link to wrap the error source in }
An error description, used as an argument to the error template.
func (*Error) ContextSource ¶
func (e *Error) ContextSource() []sourceLine
Returns a snippet of the source around where the error occurred.
type GoTemplate ¶
Adapter for Go Templates.
func (GoTemplate) Content ¶
func (gotmpl GoTemplate) Content() []string
type TemplateLoader ¶
This object handles loading and parsing of templates. Everything below the application's views directory is treated as a template.
func NewTemplateLoader ¶
func NewTemplateLoader(delimiters string, paths []string, logger log.Logger) *TemplateLoader
func (*TemplateLoader) Load ¶
func (loader *TemplateLoader) Load() error
func (*TemplateLoader) Refresh ¶
func (loader *TemplateLoader) Refresh() *Error
This scans the views directory and parses all templates as Go Templates. If a template fails to parse, the error is set on the loader. (It's awkward to refresh a single Go Template)
func (*TemplateLoader) Template ¶
func (loader *TemplateLoader) Template(name string) (Template, error)
Return the Template with the given name. The name is the template's path relative to a template loader root.
An Error is returned if there was any problem with any of the templates. (In this case, if a template is returned, it may still be usable.)
func (*TemplateLoader) WatchFile ¶
func (loader *TemplateLoader) WatchFile(basename string) bool