Skip to content

Commit

Permalink
update document.
Browse files Browse the repository at this point in the history
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
  • Loading branch information
appleboy committed Dec 22, 2016
1 parent ce2733d commit 7a0692b
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions multitemplate.go
Expand Up @@ -7,14 +7,17 @@ import (
"github.com/gin-gonic/gin/render"
)

// Render type
type Render map[string]*template.Template

var _ render.HTMLRender = Render{}

// New instance
func New() Render {
return make(Render)
}

// Add new template
func (r Render) Add(name string, tmpl *template.Template) {
if tmpl == nil {
panic("template can not be nil")
Expand All @@ -25,31 +28,36 @@ func (r Render) Add(name string, tmpl *template.Template) {
r[name] = tmpl
}

// AddFromFiles supply add template from files
func (r Render) AddFromFiles(name string, files ...string) *template.Template {
tmpl := template.Must(template.ParseFiles(files...))
r.Add(name, tmpl)
return tmpl
}

// AddFromGlob supply add template from global path
func (r Render) AddFromGlob(name, glob string) *template.Template {
tmpl := template.Must(template.ParseGlob(glob))
r.Add(name, tmpl)
return tmpl
}

// AddFromString supply add template from strings
func (r *Render) AddFromString(name, templateString string) *template.Template {
tmpl := template.Must(template.New(name).Parse(templateString))
r.Add(name, tmpl)
return tmpl
}

// AddFromFilesFuncs supply add template from file callback func
func (r Render) AddFromFilesFuncs(name string, funcMap template.FuncMap, files ...string) *template.Template {
tname := filepath.Base(files[0])
tmpl := template.Must(template.New(tname).Funcs(funcMap).ParseFiles(files...))
r.Add(name, tmpl)
return tmpl
}

// Instance supply render string
func (r Render) Instance(name string, data interface{}) render.Render {
return render.HTML{
Template: r[name],
Expand Down

0 comments on commit 7a0692b

Please sign in to comment.