mirror of
https://github.com/astaxie/beego.git
synced 2024-11-25 23:41:28 +00:00
add BeeTemplateExt
This commit is contained in:
parent
512d115639
commit
281747ab43
23
template.go
23
template.go
@ -17,13 +17,14 @@ import (
|
|||||||
var (
|
var (
|
||||||
beegoTplFuncMap template.FuncMap
|
beegoTplFuncMap template.FuncMap
|
||||||
BeeTemplates map[string]*template.Template
|
BeeTemplates map[string]*template.Template
|
||||||
BeeTemplateExt string
|
BeeTemplateExt []string
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
BeeTemplates = make(map[string]*template.Template)
|
BeeTemplates = make(map[string]*template.Template)
|
||||||
beegoTplFuncMap = make(template.FuncMap)
|
beegoTplFuncMap = make(template.FuncMap)
|
||||||
BeeTemplateExt = "tpl"
|
BeeTemplateExt = make([]string, 0)
|
||||||
|
BeeTemplateExt = append(BeeTemplateExt, "tpl", "html")
|
||||||
beegoTplFuncMap["markdown"] = MarkDown
|
beegoTplFuncMap["markdown"] = MarkDown
|
||||||
beegoTplFuncMap["dateformat"] = DateFormat
|
beegoTplFuncMap["dateformat"] = DateFormat
|
||||||
beegoTplFuncMap["date"] = Date
|
beegoTplFuncMap["date"] = Date
|
||||||
@ -116,7 +117,14 @@ func (self *templatefile) visit(paths string, f os.FileInfo, err error) error {
|
|||||||
} else if (f.Mode() & os.ModeSymlink) > 0 {
|
} else if (f.Mode() & os.ModeSymlink) > 0 {
|
||||||
return nil
|
return nil
|
||||||
} else {
|
} else {
|
||||||
if strings.HasSuffix(paths, BeeTemplateExt) {
|
hasExt := false
|
||||||
|
for _, v := range BeeTemplateExt {
|
||||||
|
if strings.HasSuffix(paths, v) {
|
||||||
|
hasExt = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if hasExt {
|
||||||
a := []byte(paths)
|
a := []byte(paths)
|
||||||
a = a[len([]byte(self.root)):]
|
a = a[len([]byte(self.root)):]
|
||||||
subdir := path.Dir(strings.TrimLeft(string(a), "/"))
|
subdir := path.Dir(strings.TrimLeft(string(a), "/"))
|
||||||
@ -133,8 +141,13 @@ func (self *templatefile) visit(paths string, f os.FileInfo, err error) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetGlobalTemplateExt(ext string) {
|
func AddTemplateExt(ext string) {
|
||||||
BeeTemplateExt = ext
|
for _, v := range BeeTemplateExt {
|
||||||
|
if v == ext {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
BeeTemplateExt = append(BeeTemplateExt, ext)
|
||||||
}
|
}
|
||||||
|
|
||||||
func BuildTemplate(dir string) error {
|
func BuildTemplate(dir string) error {
|
||||||
|
Loading…
Reference in New Issue
Block a user