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
0f982c4a
Commit
0f982c4a
authored
Apr 02, 2013
by
astaxie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add Config.Int64 and Template add Runmode==dev everytime parsefile
parent
f78ceb82
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
5 deletions
+28
-5
config.go
config.go
+4
-0
controller.go
controller.go
+24
-5
No files found.
config.go
View file @
0f982c4a
...
...
@@ -97,6 +97,10 @@ func (c *Config) Int(key string) (int, error) {
return
strconv
.
Atoi
(
c
.
data
[
key
])
}
func
(
c
*
Config
)
Int64
(
key
string
)
(
int64
,
error
)
{
return
strconv
.
ParseInt
(
c
.
data
[
key
],
10
,
64
)
}
// Float returns the float value for a given key.
func
(
c
*
Config
)
Float
(
key
string
)
(
float64
,
error
)
{
return
strconv
.
ParseFloat
(
c
.
data
[
key
],
64
)
...
...
controller.go
View file @
0f982c4a
...
...
@@ -98,19 +98,30 @@ func (c *Controller) Render() error {
func
(
c
*
Controller
)
RenderBytes
()
([]
byte
,
error
)
{
//if the controller has set layout, then first get the tplname's content set the content to the layout
var
t
*
template
.
Template
var
err
error
if
c
.
Layout
!=
""
{
if
c
.
TplNames
==
""
{
c
.
TplNames
=
c
.
ChildName
+
"/"
+
c
.
Ctx
.
Request
.
Method
+
"."
+
c
.
TplExt
}
if
RunMode
==
"dev"
{
t
,
err
=
template
.
New
(
"beegoTemplate"
)
.
Funcs
(
beegoTplFuncMap
)
.
ParseFiles
(
path
.
Join
(
ViewsPath
,
c
.
TplNames
),
path
.
Join
(
ViewsPath
,
c
.
Layout
))
if
err
!=
nil
{
Trace
(
"template ParseFiles err:"
,
err
)
}
}
else
{
subdir
:=
path
.
Dir
(
c
.
TplNames
)
t
=
BeeTemplates
[
subdir
]
}
_
,
file
:=
path
.
Split
(
c
.
TplNames
)
subdir
:=
path
.
Dir
(
c
.
TplNames
)
newbytes
:=
bytes
.
NewBufferString
(
""
)
BeeTemplates
[
subdir
]
.
ExecuteTemplate
(
newbytes
,
file
,
c
.
Data
)
t
.
ExecuteTemplate
(
newbytes
,
file
,
c
.
Data
)
tplcontent
,
_
:=
ioutil
.
ReadAll
(
newbytes
)
c
.
Data
[
"LayoutContent"
]
=
template
.
HTML
(
string
(
tplcontent
))
_
,
file
=
path
.
Split
(
c
.
Layout
)
ibytes
:=
bytes
.
NewBufferString
(
""
)
err
:=
BeeTemplates
[
subdir
]
.
ExecuteTemplate
(
ibytes
,
file
,
c
.
Data
)
err
:=
t
.
ExecuteTemplate
(
ibytes
,
file
,
c
.
Data
)
if
err
!=
nil
{
Trace
(
"template Execute err:"
,
err
)
}
...
...
@@ -120,10 +131,18 @@ func (c *Controller) RenderBytes() ([]byte, error) {
if
c
.
TplNames
==
""
{
c
.
TplNames
=
c
.
ChildName
+
"/"
+
c
.
Ctx
.
Request
.
Method
+
"."
+
c
.
TplExt
}
if
RunMode
==
"dev"
{
t
,
err
=
template
.
New
(
"beegoTemplate"
)
.
Funcs
(
beegoTplFuncMap
)
.
ParseFiles
(
path
.
Join
(
ViewsPath
,
c
.
TplNames
))
if
err
!=
nil
{
Trace
(
"template ParseFiles err:"
,
err
)
}
}
else
{
subdir
:=
path
.
Dir
(
c
.
TplNames
)
t
=
BeeTemplates
[
subdir
]
}
_
,
file
:=
path
.
Split
(
c
.
TplNames
)
subdir
:=
path
.
Dir
(
c
.
TplNames
)
ibytes
:=
bytes
.
NewBufferString
(
""
)
err
:=
BeeTemplates
[
subdir
]
.
ExecuteTemplate
(
ibytes
,
file
,
c
.
Data
)
err
:=
t
.
ExecuteTemplate
(
ibytes
,
file
,
c
.
Data
)
if
err
!=
nil
{
Trace
(
"template Execute err:"
,
err
)
}
...
...
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