1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-22 19:00:54 +00:00

Fix formatting with gofmt

Rename BeeTemplateEngines->beeTemplateEngines.  Create templateHandler function type
Fix var name in comment BeeTemplatePreprocessors -> beeTemplatePreprocessors
Rename TemplateI -> TemplateRenderer
This commit is contained in:
saturn4er 2016-03-09 10:40:12 +02:00
parent 9ee9f81861
commit 66423f6935
2 changed files with 16 additions and 15 deletions

View File

@ -7,8 +7,8 @@ import (
"io" "io"
"io/ioutil" "io/ioutil"
"os" "os"
"testing"
"path/filepath" "path/filepath"
"testing"
) )
var currentWorkDir, _ = os.Getwd() var currentWorkDir, _ = os.Getwd()

View File

@ -32,12 +32,12 @@ import (
var ( var (
beegoTplFuncMap = make(template.FuncMap) 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) beeTemplates = make(map[string]TemplateRenderer)
templatesLock sync.RWMutex templatesLock sync.RWMutex
// beeTemplateExt stores the template extension which will build // beeTemplateExt stores the template extension which will build
beeTemplateExt = []string{"tpl", "html"} beeTemplateExt = []string{"tpl", "html"}
// BeeTemplatePreprocessors stores associations of extension -> preprocessor handler // beeTemplatePreprocessors stores associations of extension -> preprocessor handler
BeeTemplateEngines = map[string]func(root, path string, funcs template.FuncMap) (TemplateI, error){} beeTemplateEngines = map[string]templateHandler{}
) )
func executeTemplate(wr io.Writer, name string, data interface{}) error { func executeTemplate(wr io.Writer, name string, data interface{}) error {
@ -90,7 +90,8 @@ func AddFuncMap(key string, fn interface{}) error {
return nil return nil
} }
type TemplateI interface { type templateHandler func(root, path string, funcs template.FuncMap) (TemplateRenderer, error)
type TemplateRenderer interface {
ExecuteTemplate(wr io.Writer, name string, data interface{}) error ExecuteTemplate(wr io.Writer, name string, data interface{}) error
} }
type templateFile struct { type templateFile struct {
@ -167,8 +168,8 @@ func BuildTemplate(dir string, files ...string) error {
if buildAllFiles || utils.InSlice(file, files) { if buildAllFiles || utils.InSlice(file, files) {
templatesLock.Lock() templatesLock.Lock()
fileExt := filepath.Ext(file)[1:] fileExt := filepath.Ext(file)[1:]
var t TemplateI var t TemplateRenderer
if fn, ok := BeeTemplateEngines[fileExt]; ok { if fn, ok := beeTemplateEngines[fileExt]; ok {
t, err = fn(self.root, file, beegoTplFuncMap) t, err = fn(self.root, file, beegoTplFuncMap)
} else { } else {
t, err = getTemplate(self.root, file, v...) t, err = getTemplate(self.root, file, v...)
@ -318,8 +319,8 @@ func DelStaticPath(url string) *App {
return BeeApp return BeeApp
} }
func AddTemplateEngine(extension string, fn func(root, path string, funcs template.FuncMap) (TemplateI, error)) *App { func AddTemplateEngine(extension string, fn templateHandler) *App {
AddTemplateExt(extension) AddTemplateExt(extension)
BeeTemplateEngines[extension] = fn beeTemplateEngines[extension] = fn
return BeeApp return BeeApp
} }