-
-
Save tboerger/850adbcd7f9a33fd752e03487d1702a5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/vendor/github.com/gin-gonic/gin/gin.go b/vendor/github.com/gin-gonic/gin/gin.go | |
index 6a8e193..c954f7d 100644 | |
--- a/vendor/github.com/gin-gonic/gin/gin.go | |
+++ b/vendor/github.com/gin-gonic/gin/gin.go | |
@@ -46,6 +46,7 @@ type ( | |
Engine struct { | |
RouterGroup | |
HTMLRender render.HTMLRender | |
+ FuncMap template.FuncMap | |
allNoRoute HandlersChain | |
allNoMethod HandlersChain | |
noRoute HandlersChain | |
@@ -111,6 +112,7 @@ func New() *Engine { | |
basePath: "/", | |
root: true, | |
}, | |
+ FuncMap: template.FuncMap{}, | |
RedirectTrailingSlash: true, | |
RedirectFixedPath: false, | |
HandleMethodNotAllowed: false, | |
@@ -140,19 +142,19 @@ func (engine *Engine) allocateContext() *Context { | |
func (engine *Engine) LoadHTMLGlob(pattern string) { | |
if IsDebugging() { | |
- debugPrintLoadTemplate(template.Must(template.ParseGlob(pattern))) | |
- engine.HTMLRender = render.HTMLDebug{Glob: pattern} | |
+ debugPrintLoadTemplate(template.Must(template.New("").Funcs(engine.FuncMap).ParseGlob(pattern))) | |
+ engine.HTMLRender = render.HTMLDebug{Glob: pattern, FuncMap: engine.FuncMap} | |
} else { | |
- templ := template.Must(template.ParseGlob(pattern)) | |
+ templ := template.Must(template.New("").Funcs(engine.FuncMap).ParseGlob(pattern)) | |
engine.SetHTMLTemplate(templ) | |
} | |
} | |
func (engine *Engine) LoadHTMLFiles(files ...string) { | |
if IsDebugging() { | |
- engine.HTMLRender = render.HTMLDebug{Files: files} | |
+ engine.HTMLRender = render.HTMLDebug{Files: files, FuncMap: engine.FuncMap} | |
} else { | |
- templ := template.Must(template.ParseFiles(files...)) | |
+ templ := template.Must(template.New("").Funcs(engine.FuncMap).ParseFiles(files...)) | |
engine.SetHTMLTemplate(templ) | |
} | |
} | |
@@ -161,7 +163,11 @@ func (engine *Engine) SetHTMLTemplate(templ *template.Template) { | |
if len(engine.trees) > 0 { | |
debugPrintWARNINGSetHTMLTemplate() | |
} | |
- engine.HTMLRender = render.HTMLProduction{Template: templ} | |
+ engine.HTMLRender = render.HTMLProduction{Template: templ.Funcs(engine.FuncMap)} | |
+} | |
+ | |
+func (engine *Engine) SetFuncMap(funcMap template.FuncMap) { | |
+ engine.FuncMap = funcMap | |
} | |
// NoRoute adds handlers for NoRoute. It return a 404 code by default. | |
diff --git a/vendor/github.com/gin-gonic/gin/render/html.go b/vendor/github.com/gin-gonic/gin/render/html.go | |
index a3cbda6..1626236 100644 | |
--- a/vendor/github.com/gin-gonic/gin/render/html.go | |
+++ b/vendor/github.com/gin-gonic/gin/render/html.go | |
@@ -19,8 +19,9 @@ type ( | |
} | |
HTMLDebug struct { | |
- Files []string | |
- Glob string | |
+ Files []string | |
+ Glob string | |
+ FuncMap template.FuncMap | |
} | |
HTML struct { | |
@@ -48,11 +49,14 @@ func (r HTMLDebug) Instance(name string, data interface{}) Render { | |
} | |
} | |
func (r HTMLDebug) loadTemplate() *template.Template { | |
+ if r.FuncMap == nil { | |
+ r.FuncMap = template.FuncMap{} | |
+ } | |
if len(r.Files) > 0 { | |
- return template.Must(template.ParseFiles(r.Files...)) | |
+ return template.Must(template.New("").Funcs(r.FuncMap).ParseFiles(r.Files...)) | |
} | |
if len(r.Glob) > 0 { | |
- return template.Must(template.ParseGlob(r.Glob)) | |
+ return template.Must(template.New("").Funcs(r.FuncMap).ParseGlob(r.Glob)) | |
} | |
panic("the HTML debug render was created without files or glob pattern") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment