mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-29 03:02:07 -05:00
Initialize funcMap in an init function.
This commit is contained in:
parent
6a98d269b5
commit
14e93de8a1
1 changed files with 37 additions and 34 deletions
|
@ -36,6 +36,7 @@ import (
|
||||||
|
|
||||||
var localTemplates *template.Template
|
var localTemplates *template.Template
|
||||||
var tmpl Template
|
var tmpl Template
|
||||||
|
var funcMap template.FuncMap
|
||||||
|
|
||||||
type Template interface {
|
type Template interface {
|
||||||
ExecuteTemplate(wr io.Writer, name string, data interface{}) error
|
ExecuteTemplate(wr io.Writer, name string, data interface{}) error
|
||||||
|
@ -84,40 +85,6 @@ func New() Template {
|
||||||
|
|
||||||
localTemplates = &templates.Template
|
localTemplates = &templates.Template
|
||||||
|
|
||||||
funcMap := template.FuncMap{
|
|
||||||
"urlize": helpers.Urlize,
|
|
||||||
"sanitizeurl": helpers.SanitizeUrl,
|
|
||||||
"eq": Eq,
|
|
||||||
"ne": Ne,
|
|
||||||
"gt": Gt,
|
|
||||||
"ge": Ge,
|
|
||||||
"lt": Lt,
|
|
||||||
"le": Le,
|
|
||||||
"in": In,
|
|
||||||
"intersect": Intersect,
|
|
||||||
"isset": IsSet,
|
|
||||||
"echoParam": ReturnWhenSet,
|
|
||||||
"safeHtml": SafeHtml,
|
|
||||||
"markdownify": Markdownify,
|
|
||||||
"first": First,
|
|
||||||
"where": Where,
|
|
||||||
"delimit": Delimit,
|
|
||||||
"sort": Sort,
|
|
||||||
"highlight": Highlight,
|
|
||||||
"add": func(a, b interface{}) (interface{}, error) { return doArithmetic(a, b, '+') },
|
|
||||||
"sub": func(a, b interface{}) (interface{}, error) { return doArithmetic(a, b, '-') },
|
|
||||||
"div": func(a, b interface{}) (interface{}, error) { return doArithmetic(a, b, '/') },
|
|
||||||
"mod": Mod,
|
|
||||||
"mul": func(a, b interface{}) (interface{}, error) { return doArithmetic(a, b, '*') },
|
|
||||||
"modBool": ModBool,
|
|
||||||
"lower": func(a string) string { return strings.ToLower(a) },
|
|
||||||
"upper": func(a string) string { return strings.ToUpper(a) },
|
|
||||||
"title": func(a string) string { return strings.Title(a) },
|
|
||||||
"partial": Partial,
|
|
||||||
"ref": Ref,
|
|
||||||
"relref": RelRef,
|
|
||||||
}
|
|
||||||
|
|
||||||
templates.Funcs(funcMap)
|
templates.Funcs(funcMap)
|
||||||
templates.LoadEmbedded()
|
templates.LoadEmbedded()
|
||||||
return templates
|
return templates
|
||||||
|
@ -1021,3 +988,39 @@ func (t *GoHtmlTemplate) LoadTemplatesWithPrefix(absPath string, prefix string)
|
||||||
func (t *GoHtmlTemplate) LoadTemplates(absPath string) {
|
func (t *GoHtmlTemplate) LoadTemplates(absPath string) {
|
||||||
t.loadTemplates(absPath, "")
|
t.loadTemplates(absPath, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
funcMap = template.FuncMap{
|
||||||
|
"urlize": helpers.Urlize,
|
||||||
|
"sanitizeurl": helpers.SanitizeUrl,
|
||||||
|
"eq": Eq,
|
||||||
|
"ne": Ne,
|
||||||
|
"gt": Gt,
|
||||||
|
"ge": Ge,
|
||||||
|
"lt": Lt,
|
||||||
|
"le": Le,
|
||||||
|
"in": In,
|
||||||
|
"intersect": Intersect,
|
||||||
|
"isset": IsSet,
|
||||||
|
"echoParam": ReturnWhenSet,
|
||||||
|
"safeHtml": SafeHtml,
|
||||||
|
"markdownify": Markdownify,
|
||||||
|
"first": First,
|
||||||
|
"where": Where,
|
||||||
|
"delimit": Delimit,
|
||||||
|
"sort": Sort,
|
||||||
|
"highlight": Highlight,
|
||||||
|
"add": func(a, b interface{}) (interface{}, error) { return doArithmetic(a, b, '+') },
|
||||||
|
"sub": func(a, b interface{}) (interface{}, error) { return doArithmetic(a, b, '-') },
|
||||||
|
"div": func(a, b interface{}) (interface{}, error) { return doArithmetic(a, b, '/') },
|
||||||
|
"mod": Mod,
|
||||||
|
"mul": func(a, b interface{}) (interface{}, error) { return doArithmetic(a, b, '*') },
|
||||||
|
"modBool": ModBool,
|
||||||
|
"lower": func(a string) string { return strings.ToLower(a) },
|
||||||
|
"upper": func(a string) string { return strings.ToUpper(a) },
|
||||||
|
"title": func(a string) string { return strings.Title(a) },
|
||||||
|
"partial": Partial,
|
||||||
|
"ref": Ref,
|
||||||
|
"relref": RelRef,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue