Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions render.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ type Options struct {
PrefixXML []byte
// Allows changing of output to XHTML instead of HTML. Default is "text/html"
HTMLContentType string
// Allows to define a user function to generate templates
CompileHandler func(Options) *template.Template
}

// HTMLOptions is a struct for overriding some rendering Options for specific HTML call
Expand All @@ -149,13 +151,22 @@ type HTMLOptions struct {
func Renderer(options ...Options) martini.Handler {
opt := prepareOptions(options)
cs := prepareCharset(opt.Charset)
t := compile(opt)
var t *template.Template
if opt.CompileHandler != nil {
t = opt.CompileHandler(opt)
} else {
t = compile(opt)
}
bufpool = bpool.NewBufferPool(64)
return func(res http.ResponseWriter, req *http.Request, c martini.Context) {
var tc *template.Template
if martini.Env == martini.Dev {
// recompile for easy development
tc = compile(opt)
if opt.CompileHandler != nil {
tc = opt.CompileHandler(opt)
} else {
tc = compile(opt)
}
} else {
// use a clone of the initial template
tc, _ = t.Clone()
Expand Down