Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
张磊
/
FileStorageBeego
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
f502f844
authored
2013-09-12 13:44:12 +0800
by
astaxie
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fix #189
1 parent
e788fb72
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
5 deletions
controller.go
template.go
controller.go
View file @
f502f84
...
...
@@ -17,6 +17,7 @@ import (
"net/url"
"os"
"path"
"regexp"
"strconv"
"strings"
"time"
...
...
@@ -133,14 +134,52 @@ func (c *Controller) RenderBytes() ([]byte, error) {
panic
(
"can't find templatefile in the path:"
+
c
.
TplNames
)
return
[]
byte
{},
errors
.
New
(
"can't find templatefile in the path:"
+
c
.
TplNames
)
}
BeeTemplates
[
subdir
]
.
ExecuteTemplate
(
newbytes
,
file
,
c
.
Data
)
err
:=
BeeTemplates
[
subdir
]
.
ExecuteTemplate
(
newbytes
,
file
,
c
.
Data
)
if
err
!=
nil
{
LayoutTplErrDeal
:
if
terr
,
ok
:=
err
.
(
*
template
.
Error
);
ok
{
if
terr
.
ErrorCode
==
template
.
ErrNoSuchTemplate
{
reg
:=
regexp
.
MustCompile
(
"
\"
(.+)
\"
"
)
a
:=
reg
.
FindStringSubmatch
(
terr
.
Description
)
if
len
(
a
)
>
1
{
missfile
:=
path
.
Join
(
ViewsPath
,
subdir
,
a
[
1
])
AllTemplateFiles
.
files
[
subdir
]
=
append
(
AllTemplateFiles
.
files
[
subdir
],
missfile
)
for
k
,
v
:=
range
AllTemplateFiles
.
files
{
BeeTemplates
[
k
]
=
template
.
Must
(
template
.
New
(
"beegoTemplate"
+
k
)
.
Delims
(
TemplateLeft
,
TemplateRight
)
.
Funcs
(
beegoTplFuncMap
)
.
ParseFiles
(
v
...
))
}
err
=
BeeTemplates
[
subdir
]
.
ExecuteTemplate
(
newbytes
,
file
,
c
.
Data
)
if
err
!=
nil
{
goto
LayoutTplErrDeal
}
}
}
}
}
tplcontent
,
_
:=
ioutil
.
ReadAll
(
newbytes
)
c
.
Data
[
"LayoutContent"
]
=
template
.
HTML
(
string
(
tplcontent
))
subdir
=
path
.
Dir
(
c
.
Layout
)
_
,
file
=
path
.
Split
(
c
.
Layout
)
ibytes
:=
bytes
.
NewBufferString
(
""
)
err
:=
BeeTemplates
[
subdir
]
.
ExecuteTemplate
(
ibytes
,
file
,
c
.
Data
)
err
=
BeeTemplates
[
subdir
]
.
ExecuteTemplate
(
ibytes
,
file
,
c
.
Data
)
if
err
!=
nil
{
LayoutErrDeal
:
if
terr
,
ok
:=
err
.
(
*
template
.
Error
);
ok
{
if
terr
.
ErrorCode
==
template
.
ErrNoSuchTemplate
{
reg
:=
regexp
.
MustCompile
(
"
\"
(.+)
\"
"
)
a
:=
reg
.
FindStringSubmatch
(
terr
.
Description
)
if
len
(
a
)
>
1
{
missfile
:=
path
.
Join
(
ViewsPath
,
subdir
,
a
[
1
])
AllTemplateFiles
.
files
[
subdir
]
=
append
(
AllTemplateFiles
.
files
[
subdir
],
missfile
)
for
k
,
v
:=
range
AllTemplateFiles
.
files
{
BeeTemplates
[
k
]
=
template
.
Must
(
template
.
New
(
"beegoTemplate"
+
k
)
.
Delims
(
TemplateLeft
,
TemplateRight
)
.
Funcs
(
beegoTplFuncMap
)
.
ParseFiles
(
v
...
))
}
err
=
BeeTemplates
[
subdir
]
.
ExecuteTemplate
(
ibytes
,
file
,
c
.
Data
)
if
err
!=
nil
{
goto
LayoutErrDeal
}
}
}
}
Trace
(
"template Execute err:"
,
err
)
}
icontent
,
_
:=
ioutil
.
ReadAll
(
ibytes
)
...
...
@@ -161,6 +200,24 @@ func (c *Controller) RenderBytes() ([]byte, error) {
}
err
:=
BeeTemplates
[
subdir
]
.
ExecuteTemplate
(
ibytes
,
file
,
c
.
Data
)
if
err
!=
nil
{
ErrDeal
:
if
terr
,
ok
:=
err
.
(
*
template
.
Error
);
ok
{
if
terr
.
ErrorCode
==
template
.
ErrNoSuchTemplate
{
reg
:=
regexp
.
MustCompile
(
"
\"
(.+)
\"
"
)
a
:=
reg
.
FindStringSubmatch
(
terr
.
Description
)
if
len
(
a
)
>
1
{
missfile
:=
path
.
Join
(
ViewsPath
,
subdir
,
a
[
1
])
AllTemplateFiles
.
files
[
subdir
]
=
append
(
AllTemplateFiles
.
files
[
subdir
],
missfile
)
for
k
,
v
:=
range
AllTemplateFiles
.
files
{
BeeTemplates
[
k
]
=
template
.
Must
(
template
.
New
(
"beegoTemplate"
+
k
)
.
Delims
(
TemplateLeft
,
TemplateRight
)
.
Funcs
(
beegoTplFuncMap
)
.
ParseFiles
(
v
...
))
}
err
=
BeeTemplates
[
subdir
]
.
ExecuteTemplate
(
ibytes
,
file
,
c
.
Data
)
if
err
!=
nil
{
goto
ErrDeal
}
}
}
}
Trace
(
"template Execute err:"
,
err
)
}
icontent
,
_
:=
ioutil
.
ReadAll
(
ibytes
)
...
...
template.go
View file @
f502f84
...
...
@@ -16,6 +16,7 @@ var (
beegoTplFuncMap
template
.
FuncMap
BeeTemplates
map
[
string
]
*
template
.
Template
BeeTemplateExt
[]
string
AllTemplateFiles
*
templatefile
)
func
init
()
{
...
...
@@ -100,18 +101,18 @@ func BuildTemplate(dir string) error {
return
errors
.
New
(
"dir open err"
)
}
}
self
:=
templatefile
{
AllTemplateFiles
=
&
templatefile
{
root
:
dir
,
files
:
make
(
map
[
string
][]
string
),
}
err
:=
filepath
.
Walk
(
dir
,
func
(
path
string
,
f
os
.
FileInfo
,
err
error
)
error
{
return
self
.
visit
(
path
,
f
,
err
)
return
AllTemplateFiles
.
visit
(
path
,
f
,
err
)
})
if
err
!=
nil
{
fmt
.
Printf
(
"filepath.Walk() returned %v
\n
"
,
err
)
return
err
}
for
k
,
v
:=
range
self
.
files
{
for
k
,
v
:=
range
AllTemplateFiles
.
files
{
BeeTemplates
[
k
]
=
template
.
Must
(
template
.
New
(
"beegoTemplate"
+
k
)
.
Delims
(
TemplateLeft
,
TemplateRight
)
.
Funcs
(
beegoTplFuncMap
)
.
ParseFiles
(
v
...
))
}
return
nil
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
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 post a comment