Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
二次元的罪恶王冠
beego
提交
0ac7e342
B
beego
项目概览
二次元的罪恶王冠
/
beego
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
B
beego
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
0ac7e342
编写于
7月 31, 2013
作者:
A
astaxie
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #118 from miraclesu/test
Refactor template visit & Add template test
上级
5ccdaeb0
2a9852fa
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
72 addition
and
22 deletion
+72
-22
template.go
template.go
+23
-22
template_test.go
template_test.go
+49
-0
未找到文件。
template.go
浏览文件 @
0ac7e342
...
...
@@ -51,34 +51,35 @@ func (self *templatefile) visit(paths string, f os.FileInfo, err error) error {
if
f
==
nil
{
return
err
}
if
f
.
IsDir
()
{
if
f
.
IsDir
()
||
(
f
.
Mode
()
&
os
.
ModeSymlink
)
>
0
{
return
nil
}
else
if
(
f
.
Mode
()
&
os
.
ModeSymlink
)
>
0
{
}
if
!
HasTemplateEXt
(
paths
)
{
return
nil
}
replace
:=
strings
.
NewReplacer
(
"
\\
"
,
"/"
)
a
:=
[]
byte
(
paths
)
a
=
a
[
len
([]
byte
(
self
.
root
))
:
]
subdir
:=
path
.
Dir
(
strings
.
TrimLeft
(
replace
.
Replace
(
string
(
a
)),
"/"
))
if
_
,
ok
:=
self
.
files
[
subdir
];
ok
{
self
.
files
[
subdir
]
=
append
(
self
.
files
[
subdir
],
paths
)
}
else
{
hasExt
:=
false
for
_
,
v
:=
range
BeeTemplateExt
{
if
strings
.
HasSuffix
(
paths
,
v
)
{
hasExt
=
true
break
}
}
if
hasExt
{
replace
:=
strings
.
NewReplacer
(
"
\\
"
,
"/"
)
a
:=
[]
byte
(
paths
)
a
=
a
[
len
([]
byte
(
self
.
root
))
:
]
subdir
:=
path
.
Dir
(
strings
.
TrimLeft
(
replace
.
Replace
(
string
(
a
)),
"/"
))
if
_
,
ok
:=
self
.
files
[
subdir
];
ok
{
self
.
files
[
subdir
]
=
append
(
self
.
files
[
subdir
],
paths
)
}
else
{
m
:=
make
([]
string
,
1
)
m
[
0
]
=
paths
self
.
files
[
subdir
]
=
m
}
m
:=
make
([]
string
,
1
)
m
[
0
]
=
paths
self
.
files
[
subdir
]
=
m
}
return
nil
}
func
HasTemplateEXt
(
paths
string
)
bool
{
for
_
,
v
:=
range
BeeTemplateExt
{
if
strings
.
HasSuffix
(
paths
,
"."
+
v
)
{
return
true
}
}
return
nil
return
false
}
func
AddTemplateExt
(
ext
string
)
{
...
...
template_test.go
0 → 100644
浏览文件 @
0ac7e342
package
beego
import
(
"os"
"path/filepath"
"testing"
)
func
TestBuildTemplate
(
t
*
testing
.
T
)
{
dir
:=
"_beeTmp"
files
:=
[]
string
{
"1.tpl"
,
"2.html"
,
"3.htmltpl"
,
"4.mystyle"
,
}
if
err
:=
os
.
MkdirAll
(
dir
,
0777
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
for
_
,
name
:=
range
files
{
if
_
,
err
:=
os
.
Create
(
filepath
.
Join
(
dir
,
name
));
err
!=
nil
{
t
.
Fatal
(
err
)
}
}
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
()))
}
}
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
()))
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录