Switch to dep for dependency management

This commit is contained in:
Dan Sosedoff
2018-08-31 21:49:24 -05:00
parent 847f47c5d3
commit ad81f666a5
537 changed files with 167100 additions and 34410 deletions

View File

@@ -9,26 +9,32 @@ import (
"net/http"
)
type (
HTMLRender interface {
Instance(string, interface{}) Render
}
type Delims struct {
Left string
Right string
}
HTMLProduction struct {
Template *template.Template
}
type HTMLRender interface {
Instance(string, interface{}) Render
}
HTMLDebug struct {
Files []string
Glob string
}
type HTMLProduction struct {
Template *template.Template
Delims Delims
}
HTML struct {
Template *template.Template
Name string
Data interface{}
}
)
type HTMLDebug struct {
Files []string
Glob string
Delims Delims
FuncMap template.FuncMap
}
type HTML struct {
Template *template.Template
Name string
Data interface{}
}
var htmlContentType = []string{"text/html; charset=utf-8"}
@@ -48,11 +54,14 @@ 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...))
if r.FuncMap == nil {
r.FuncMap = template.FuncMap{}
}
if len(r.Glob) > 0 {
return template.Must(template.ParseGlob(r.Glob))
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))
}
panic("the HTML debug render was created without files or glob pattern")
}
@@ -60,7 +69,7 @@ func (r HTMLDebug) loadTemplate() *template.Template {
func (r HTML) Render(w http.ResponseWriter) error {
r.WriteContentType(w)
if len(r.Name) == 0 {
if r.Name == "" {
return r.Template.Execute(w, r.Data)
}
return r.Template.ExecuteTemplate(w, r.Name, r.Data)