mirror of https://github.com/gin-gonic/gin.git
Support multiple HTML globs
This commit is contained in:
parent
9b9f4fab34
commit
78e74dc158
8
gin.go
8
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)
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue