Skip to content

Commit

Permalink
feat(gin): add Texts for TemplateHTML, to support embed files
Browse files Browse the repository at this point in the history
  • Loading branch information
searKing committed Sep 10, 2024
1 parent 3a8aab5 commit f0a173b
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions third_party/github.com/gin-gonic/gin/render/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ import (
// TemplateHTML contains template reference and its name with given interface object.
type TemplateHTML struct {
Template *template.Template
Files []string
Glob string

Texts []string
Files []string
Glob string

FuncMap template.FuncMap
Name string // Data's Name in tmpl
Expand All @@ -37,13 +39,16 @@ func (r *TemplateHTML) Render(w http.ResponseWriter) error {
}

if r.Delims != nil {
r.Template.Delims(r.Delims.Left, r.Delims.Right)
r.Template = r.Template.Delims(r.Delims.Left, r.Delims.Right)
}

if r.FuncMap != nil {
r.Template.Funcs(r.FuncMap)
r.Template = r.Template.Funcs(r.FuncMap)
}

for _, text := range r.Texts {
r.Template = template.Must(r.Template.Parse(text))
}
if len(r.Files) > 0 {
r.Template = template.Must(r.Template.ParseFiles(r.Files...))
}
Expand Down

0 comments on commit f0a173b

Please sign in to comment.