Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
beego
Commits
bc1f0ac6
Commit
bc1f0ac6
authored
Aug 23, 2015
by
astaxie
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1298 from wulove/develop
全局变量AutoRender为false时,run时不再编译模版;针对开发模式下,每个请求渲染模版时支持单独编译当前请求相关模版
parents
db2b1ee5
38ddb611
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
14 deletions
+29
-14
beego.go
beego.go
+7
-5
controller.go
controller.go
+13
-2
template.go
template.go
+8
-6
template_test.go
template_test.go
+1
-1
No files found.
beego.go
View file @
bc1f0ac6
...
...
@@ -306,11 +306,13 @@ func initBeforeHttpRun() {
}
go
GlobalSessions
.
GC
()
}
err
:=
BuildTemplate
(
ViewsPath
)
if
err
!=
nil
{
if
RunMode
==
"dev"
{
Warn
(
err
)
if
AutoRender
{
err
:=
BuildTemplate
(
ViewsPath
)
if
err
!=
nil
{
if
RunMode
==
"dev"
{
Warn
(
err
)
}
}
}
...
...
controller.go
View file @
bc1f0ac6
...
...
@@ -200,8 +200,19 @@ func (c *Controller) RenderBytes() ([]byte, error) {
if
c
.
TplNames
==
""
{
c
.
TplNames
=
strings
.
ToLower
(
c
.
controllerName
)
+
"/"
+
strings
.
ToLower
(
c
.
actionName
)
+
"."
+
c
.
TplExt
}
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
(
""
)
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
}
if
RunMode
==
"dev"
{
BuildTemplate
(
ViewsPath
)
BuildTemplate
(
ViewsPath
,
c
.
TplNames
)
}
ibytes
:=
bytes
.
NewBufferString
(
""
)
if
_
,
ok
:=
BeeTemplates
[
c
.
TplNames
];
!
ok
{
...
...
template.go
View file @
bc1f0ac6
...
...
@@ -128,7 +128,7 @@ func AddTemplateExt(ext string) {
// build all template files in a 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
os
.
IsNotExist
(
err
)
{
return
nil
...
...
@@ -149,11 +149,13 @@ func BuildTemplate(dir string) error {
}
for
_
,
v
:=
range
self
.
files
{
for
_
,
file
:=
range
v
{
t
,
err
:=
getTemplate
(
self
.
root
,
file
,
v
...
)
if
err
!=
nil
{
Trace
(
"parse template err:"
,
file
,
err
)
}
else
{
BeeTemplates
[
file
]
=
t
if
(
len
(
files
)
==
0
||
utils
.
InSlice
(
file
,
files
))
{
t
,
err
:=
getTemplate
(
self
.
root
,
file
,
v
...
)
if
err
!=
nil
{
Trace
(
"parse template err:"
,
file
,
err
)
}
else
{
BeeTemplates
[
file
]
=
t
}
}
}
}
...
...
template_test.go
View file @
bc1f0ac6
...
...
@@ -123,7 +123,7 @@ func TestRelativeTemplate(t *testing.T) {
f
.
Close
()
}
}
if
err
:=
BuildTemplate
(
dir
);
err
!=
nil
{
if
err
:=
BuildTemplate
(
dir
,
files
[
1
]
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
err
:=
BeeTemplates
[
"easyui/rbac/user.tpl"
]
.
ExecuteTemplate
(
os
.
Stdout
,
"easyui/rbac/user.tpl"
,
nil
);
err
!=
nil
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment