mirror of
https://github.com/astaxie/beego.git
synced 2024-11-25 21:11:29 +00:00
Merge pull request #1298 from wulove/develop
全局变量AutoRender为false时,run时不再编译模版;针对开发模式下,每个请求渲染模版时支持单独编译当前请求相关模版
This commit is contained in:
commit
bc1f0ac6fd
2
beego.go
2
beego.go
@ -307,12 +307,14 @@ func initBeforeHttpRun() {
|
|||||||
go GlobalSessions.GC()
|
go GlobalSessions.GC()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if AutoRender {
|
||||||
err := BuildTemplate(ViewsPath)
|
err := BuildTemplate(ViewsPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if RunMode == "dev" {
|
if RunMode == "dev" {
|
||||||
Warn(err)
|
Warn(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
registerDefaultErrorHandler()
|
registerDefaultErrorHandler()
|
||||||
|
|
||||||
|
@ -200,8 +200,19 @@ func (c *Controller) RenderBytes() ([]byte, error) {
|
|||||||
if c.TplNames == "" {
|
if c.TplNames == "" {
|
||||||
c.TplNames = strings.ToLower(c.controllerName) + "/" + strings.ToLower(c.actionName) + "." + c.TplExt
|
c.TplNames = strings.ToLower(c.controllerName) + "/" + strings.ToLower(c.actionName) + "." + c.TplExt
|
||||||
}
|
}
|
||||||
|
|
||||||
if RunMode == "dev" {
|
if RunMode == "dev" {
|
||||||
BuildTemplate(ViewsPath)
|
buildFiles := make([]string, 1)
|
||||||
|
buildFiles = append(buildFiles, c.TplNames)
|
||||||
|
if c.LayoutSections != nil {
|
||||||
|
for _, sectionTpl := range c.LayoutSections {
|
||||||
|
if sectionTpl == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
buildFiles = append(buildFiles, sectionTpl)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
BuildTemplate(ViewsPath, buildFiles...)
|
||||||
}
|
}
|
||||||
newbytes := bytes.NewBufferString("")
|
newbytes := bytes.NewBufferString("")
|
||||||
if _, ok := BeeTemplates[c.TplNames]; !ok {
|
if _, ok := BeeTemplates[c.TplNames]; !ok {
|
||||||
@ -246,7 +257,7 @@ func (c *Controller) RenderBytes() ([]byte, error) {
|
|||||||
c.TplNames = strings.ToLower(c.controllerName) + "/" + strings.ToLower(c.actionName) + "." + c.TplExt
|
c.TplNames = strings.ToLower(c.controllerName) + "/" + strings.ToLower(c.actionName) + "." + c.TplExt
|
||||||
}
|
}
|
||||||
if RunMode == "dev" {
|
if RunMode == "dev" {
|
||||||
BuildTemplate(ViewsPath)
|
BuildTemplate(ViewsPath, c.TplNames)
|
||||||
}
|
}
|
||||||
ibytes := bytes.NewBufferString("")
|
ibytes := bytes.NewBufferString("")
|
||||||
if _, ok := BeeTemplates[c.TplNames]; !ok {
|
if _, ok := BeeTemplates[c.TplNames]; !ok {
|
||||||
|
@ -128,7 +128,7 @@ func AddTemplateExt(ext string) {
|
|||||||
|
|
||||||
// build all template files in a directory.
|
// build all template files in a directory.
|
||||||
// it makes beego can render any template file in view directory.
|
// it makes beego can render any template file in view directory.
|
||||||
func BuildTemplate(dir string) error {
|
func BuildTemplate(dir string, files... string) error {
|
||||||
if _, err := os.Stat(dir); err != nil {
|
if _, err := os.Stat(dir); err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
return nil
|
return nil
|
||||||
@ -149,6 +149,7 @@ func BuildTemplate(dir string) error {
|
|||||||
}
|
}
|
||||||
for _, v := range self.files {
|
for _, v := range self.files {
|
||||||
for _, file := range v {
|
for _, file := range v {
|
||||||
|
if (len(files) == 0 || utils.InSlice(file, files)) {
|
||||||
t, err := getTemplate(self.root, file, v...)
|
t, err := getTemplate(self.root, file, v...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Trace("parse template err:", file, err)
|
Trace("parse template err:", file, err)
|
||||||
@ -157,6 +158,7 @@ func BuildTemplate(dir string) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ func TestRelativeTemplate(t *testing.T) {
|
|||||||
f.Close()
|
f.Close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := BuildTemplate(dir); err != nil {
|
if err := BuildTemplate(dir, files[1]); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if err := BeeTemplates["easyui/rbac/user.tpl"].ExecuteTemplate(os.Stdout, "easyui/rbac/user.tpl", nil); err != nil {
|
if err := BeeTemplates["easyui/rbac/user.tpl"].ExecuteTemplate(os.Stdout, "easyui/rbac/user.tpl", nil); err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user