Example #1
0
// @modified by henry, 2016.1.12
func (r HTMLDebug) loadTemplate() *template.Template {
	if len(r.Files) > 0 {
		return template.Must(template.Must(HTMLTemplate.Clone()).ParseFiles(r.Files...))
	}
	if len(r.Glob) > 0 {
		return template.Must(template.Must(HTMLTemplate.Clone()).ParseGlob(r.Glob))
	}
	panic("the HTML debug render was created without files or glob pattern")
}
Example #2
0
// @modified by henry, 2016.1.12
func (engine *Engine) LoadHTMLFiles(files ...string) {
	render.HTMLTemplate.Clone()
	if IsDebugging() {
		engine.HTMLRender = render.HTMLDebug{Files: files}
	} else {
		templ := template.Must(template.Must(render.HTMLTemplate.Clone()).ParseFiles(files...))
		engine.SetHTMLTemplate(templ)
	}
}
Example #3
0
// @modified by henry, 2016.1.12
func (engine *Engine) LoadHTMLGlob(pattern string) {
	templ := template.Must(template.Must(render.HTMLTemplate.Clone()).ParseGlob(pattern))
	if IsDebugging() {
		debugPrintLoadTemplate(templ)
		engine.HTMLRender = render.HTMLDebug{Glob: pattern}
	} else {
		engine.SetHTMLTemplate(templ)
	}
}
Example #4
0
func (t *Template) Render(w io.Writer, name string, data interface{}) error {
	f := t.pathmap[name]
	if f == "" {
		return fmt.Errorf("索引模板不存在: %s", name)
	}
	if t.debug {
		return template.Must(template.Must(t.Template.Clone()).ParseFiles(f)).ExecuteTemplate(w, f, data)
	}
	return t.Template.ExecuteTemplate(w, f, data)
}