From 78e74dc158323fe33b95b3a506b1acf670bfc180 Mon Sep 17 00:00:00 2001 From: David Zbarsky Date: Tue, 24 Sep 2019 11:23:17 -0500 Subject: [PATCH] Support multiple HTML globs --- gin.go | 8 ++++++-- render/html.go | 9 ++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/gin.go b/gin.go index cbdd080e..1459f755 100644 --- a/gin.go +++ b/gin.go @@ -173,10 +173,14 @@ func (engine *Engine) SecureJsonPrefix(prefix string) *Engine { // LoadHTMLGlob loads HTML files identified by glob pattern // and associates the result with HTML renderer. -func (engine *Engine) LoadHTMLGlob(pattern string) { +func (engine *Engine) LoadHTMLGlob(pattern ...string) { left := engine.delims.Left right := engine.delims.Right - templ := template.Must(template.New("").Delims(left, right).Funcs(engine.FuncMap).ParseGlob(pattern)) + + templ := template.New("").Delims(left, right).Funcs(engine.FuncMap) + for _, p := range pattern { + templ = template.Must(templ.ParseGlob(p)) + } if IsDebugging() { debugPrintLoadTemplate(templ) diff --git a/render/html.go b/render/html.go index 6696ece9..93cfa22f 100644 --- a/render/html.go +++ b/render/html.go @@ -32,7 +32,7 @@ type HTMLProduction struct { // HTMLDebug contains template delims and pattern and function with file list. type HTMLDebug struct { Files []string - Glob string + Glob []string Delims Delims FuncMap template.FuncMap } @@ -70,8 +70,11 @@ func (r HTMLDebug) loadTemplate() *template.Template { if len(r.Files) > 0 { return template.Must(template.New("").Delims(r.Delims.Left, r.Delims.Right).Funcs(r.FuncMap).ParseFiles(r.Files...)) } - if r.Glob != "" { - return template.Must(template.New("").Delims(r.Delims.Left, r.Delims.Right).Funcs(r.FuncMap).ParseGlob(r.Glob)) + if len(r.Glob) > 0 { + tmpl := template.New("").Delims(r.Delims.Left, r.Delims.Right).Funcs(r.FuncMap) + for _, g := range r.Glob { + tmpl = template.Must(tmpl.ParseGlob(g)) + } } panic("the HTML debug render was created without files or glob pattern") }