Add functions passing to template engine callback

This commit is contained in:
saturn4er 2016-03-07 09:37:47 +02:00
parent 10ddb06782
commit 9ee9f81861
1 changed files with 6 additions and 6 deletions

View File

@ -31,13 +31,13 @@ import (
var (
beegoTplFuncMap = make(template.FuncMap)
// beeTemplates caching map and supported template file extensions.
// beeTemplates caching map and supported template file extensions.
beeTemplates = make(map[string]TemplateI)
templatesLock sync.RWMutex
// beeTemplateExt stores the template extension which will build
// beeTemplateExt stores the template extension which will build
beeTemplateExt = []string{"tpl", "html"}
// BeeTemplatePreprocessors stores associations of extension -> preprocessor handler
BeeTemplateEngines = map[string]func(root, path string) (TemplateI, error){}
// BeeTemplatePreprocessors stores associations of extension -> preprocessor handler
BeeTemplateEngines = map[string]func(root, path string, funcs template.FuncMap) (TemplateI, error){}
)
func executeTemplate(wr io.Writer, name string, data interface{}) error {
@ -169,7 +169,7 @@ func BuildTemplate(dir string, files ...string) error {
fileExt := filepath.Ext(file)[1:]
var t TemplateI
if fn, ok := BeeTemplateEngines[fileExt]; ok {
t, err = fn(self.root, file)
t, err = fn(self.root, file, beegoTplFuncMap)
}else {
t, err = getTemplate(self.root, file, v...)
}
@ -318,7 +318,7 @@ func DelStaticPath(url string) *App {
return BeeApp
}
func AddTemplateEngine(extension string, fn func(root, path string) (TemplateI, error)) *App {
func AddTemplateEngine(extension string, fn func(root, path string, funcs template.FuncMap) (TemplateI, error)) *App {
AddTemplateExt(extension)
BeeTemplateEngines[extension] = fn
return BeeApp