add custom Delims support (#860)

* Revert "Merge pull request #753 from gin-gonic/bug"

This reverts commit 556287ff08, reversing
changes made to 32cab500ec.

* Revert "Merge pull request #744 from aviddiviner/logger-fix"

This reverts commit c3bfd69303, reversing
changes made to 9177f01c28.

* add custom Delims support

* add some test for Delims

* remove the empty line for import native package

* remove unuseful comments
This commit is contained in:
sope
2017-05-29 16:03:49 +08:00
committed by Bo-Yi Wu
parent 8295db44ed
commit 35f5df63e6
4 changed files with 84 additions and 10 deletions

View File

@ -10,17 +10,24 @@ import (
)
type (
Delims struct {
Left string
Right string
}
HTMLRender interface {
Instance(string, interface{}) Render
}
HTMLProduction struct {
Template *template.Template
Delims Delims
}
HTMLDebug struct {
Files []string
Glob string
Files []string
Glob string
Delims Delims
}
HTML struct {
@ -49,10 +56,10 @@ func (r HTMLDebug) Instance(name string, data interface{}) Render {
}
func (r HTMLDebug) loadTemplate() *template.Template {
if len(r.Files) > 0 {
return template.Must(template.ParseFiles(r.Files...))
return template.Must(template.New("").Delims(r.Delims.Left, r.Delims.Right).ParseFiles(r.Files...))
}
if len(r.Glob) > 0 {
return template.Must(template.ParseGlob(r.Glob))
return template.Must(template.New("").Delims(r.Delims.Left, r.Delims.Right).ParseGlob(r.Glob))
}
panic("the HTML debug render was created without files or glob pattern")
}