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
de2dd6e0
authored
2013-09-12 17:32:11 +0800
by
astaxie
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
update template's testcase
1 parent
ffb347a2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
20 deletions
template.go
template_test.go
template.go
View file @
de2dd6e
...
...
@@ -65,7 +65,7 @@ func (self *templatefile) visit(paths string, f os.FileInfo, err error) error {
a
=
a
[
len
([]
byte
(
self
.
root
))
:
]
file
:=
strings
.
TrimLeft
(
replace
.
Replace
(
string
(
a
)),
"/"
)
subdir
:=
filepath
.
Dir
(
file
)
t
,
err
:=
getTemplate
(
file
)
t
,
err
:=
getTemplate
(
self
.
root
,
file
)
if
err
!=
nil
{
Trace
(
"parse template err:"
,
file
,
err
)
}
else
{
...
...
@@ -122,8 +122,8 @@ func BuildTemplate(dir string) error {
return
nil
}
func
getTplDeep
(
file
string
,
t
*
template
.
Template
)
(
*
template
.
Template
,
error
)
{
fileabspath
:=
filepath
.
Join
(
ViewsPath
,
file
)
func
getTplDeep
(
root
,
file
string
,
t
*
template
.
Template
)
(
*
template
.
Template
,
error
)
{
fileabspath
:=
filepath
.
Join
(
root
,
file
)
data
,
err
:=
ioutil
.
ReadFile
(
fileabspath
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -143,7 +143,7 @@ func getTplDeep(file string, t *template.Template) (*template.Template, error) {
if
!
HasTemplateEXt
(
m
[
1
])
{
continue
}
t
,
err
=
getTplDeep
(
m
[
1
],
t
)
t
,
err
=
getTplDeep
(
root
,
m
[
1
],
t
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -152,9 +152,9 @@ func getTplDeep(file string, t *template.Template) (*template.Template, error) {
return
t
,
nil
}
func
getTemplate
(
file
string
)
(
t
*
template
.
Template
,
err
error
)
{
func
getTemplate
(
root
,
file
string
)
(
t
*
template
.
Template
,
err
error
)
{
t
=
template
.
New
(
file
)
.
Delims
(
TemplateLeft
,
TemplateRight
)
.
Funcs
(
beegoTplFuncMap
)
t
,
err
=
getTplDeep
(
file
,
t
)
t
,
err
=
getTplDeep
(
root
,
file
,
t
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
template_test.go
View file @
de2dd6e
...
...
@@ -18,32 +18,28 @@ func TestBuildTemplate(t *testing.T) {
t
.
Fatal
(
err
)
}
for
_
,
name
:=
range
files
{
if
_
,
err
:=
os
.
Create
(
filepath
.
Join
(
dir
,
name
));
err
!=
nil
{
if
f
,
err
:=
os
.
Create
(
filepath
.
Join
(
dir
,
name
));
err
!=
nil
{
t
.
Fatal
(
err
)
}
else
{
f
.
Close
()
}
}
if
err
:=
BuildTemplate
(
dir
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
len
(
BeeTemplates
)
!=
1
{
t
.
Fatalf
(
"should be 1 but got %v"
,
len
(
BeeTemplates
))
}
for
_
,
v
:=
range
BeeTemplates
{
if
len
(
v
.
Templates
())
!=
3
{
t
.
Errorf
(
"should be 3 but got %v"
,
len
(
v
.
Templates
()))
}
if
len
(
BeeTemplates
)
!=
2
{
t
.
Fatalf
(
"should be 2 but got %v"
,
len
(
BeeTemplates
))
}
AddTemplateExt
(
"mystyle"
)
if
err
:=
BuildTemplate
(
dir
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
len
(
BeeTemplates
)
!=
1
{
t
.
Fatalf
(
"should be 1 but got %v"
,
len
(
BeeTemplates
))
}
for
_
,
v
:=
range
BeeTemplates
{
if
len
(
v
.
Templates
())
!=
4
{
t
.
Errorf
(
"should be 4 but got %v"
,
len
(
v
.
Templates
()))
if
len
(
BeeTemplates
)
!=
3
{
t
.
Fatalf
(
"should be 3 but got %v"
,
len
(
BeeTemplates
))
}
for
_
,
name
:=
range
files
{
os
.
Remove
(
filepath
.
Join
(
dir
,
name
))
}
os
.
Remove
(
dir
)
}
...
...
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