Initialize funcMap in an init function. - hugo - [fork] hugo port for 9front
HTML git clone git@git.drkhsh.at/hugo.git
DIR Log
DIR Files
DIR Refs
DIR Submodules
DIR README
DIR LICENSE
---
DIR commit 14e93de8a1974ffc54e8b3843fcd89a7ae8ca4d5
DIR parent 6a98d269b54a09d53c15965b9ffea802025d3003
HTML Author: Austin Ziegler <austin@zieglers.ca>
Date: Tue, 9 Dec 2014 20:32:58 -0500
Initialize funcMap in an init function.
Diffstat:
M tpl/template.go | 71 ++++++++++++++++---------------
1 file changed, 37 insertions(+), 34 deletions(-)
---
DIR diff --git a/tpl/template.go b/tpl/template.go
@@ -36,6 +36,7 @@ import (
var localTemplates *template.Template
var tmpl Template
+var funcMap template.FuncMap
type Template interface {
ExecuteTemplate(wr io.Writer, name string, data interface{}) error
@@ -84,40 +85,6 @@ func New() 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.LoadEmbedded()
return templates
@@ -1021,3 +988,39 @@ func (t *GoHtmlTemplate) LoadTemplatesWithPrefix(absPath string, prefix string)
func (t *GoHtmlTemplate) LoadTemplates(absPath string) {
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,
+ }
+}