1 // Copyright 2014 Manu Martinez-Almeida. All rights reserved.
2 // Use of this source code is governed by a MIT style
3 // license that can be found in the LICENSE file.
17 type HTMLRender interface {
18 Instance(string, interface{}) Render
21 type HTMLProduction struct {
22 Template *template.Template
26 type HTMLDebug struct {
30 FuncMap template.FuncMap
34 Template *template.Template
39 var htmlContentType = []string{"text/html; charset=utf-8"}
41 func (r HTMLProduction) Instance(name string, data interface{}) Render {
49 func (r HTMLDebug) Instance(name string, data interface{}) Render {
51 Template: r.loadTemplate(),
56 func (r HTMLDebug) loadTemplate() *template.Template {
58 r.FuncMap = template.FuncMap{}
61 return template.Must(template.New("").Delims(r.Delims.Left, r.Delims.Right).Funcs(r.FuncMap).ParseFiles(r.Files...))
64 return template.Must(template.New("").Delims(r.Delims.Left, r.Delims.Right).Funcs(r.FuncMap).ParseGlob(r.Glob))
66 panic("the HTML debug render was created without files or glob pattern")
69 func (r HTML) Render(w http.ResponseWriter) error {
73 return r.Template.Execute(w, r.Data)
75 return r.Template.ExecuteTemplate(w, r.Name, r.Data)
78 func (r HTML) WriteContentType(w http.ResponseWriter) {
79 writeContentType(w, htmlContentType)