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
44bd3beb
Commit
44bd3beb
authored
Sep 08, 2015
by
astaxie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
golint happy with template
parent
8615f875
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
23 deletions
+19
-23
template.go
template.go
+14
-18
template_test.go
template_test.go
+5
-5
No files found.
template.go
View file @
44bd3beb
...
...
@@ -28,17 +28,14 @@ import (
)
var
(
beegoTplFuncMap
template
.
FuncMap
// beego template caching map and supported template file extensions.
BeeTemplates
map
[
string
]
*
template
.
Template
BeeTemplateExt
[]
string
beegoTplFuncMap
=
make
(
template
.
FuncMap
)
// BeeTemplates caching map and supported template file extensions.
BeeTemplates
=
make
(
map
[
string
]
*
template
.
Template
)
// BeeTemplateExt stores the template extention which will build
BeeTemplateExt
=
[]
string
{
"tpl"
,
"html"
}
)
func
init
()
{
BeeTemplates
=
make
(
map
[
string
]
*
template
.
Template
)
beegoTplFuncMap
=
make
(
template
.
FuncMap
)
BeeTemplateExt
=
make
([]
string
,
0
)
BeeTemplateExt
=
append
(
BeeTemplateExt
,
"tpl"
,
"html"
)
beegoTplFuncMap
[
"dateformat"
]
=
DateFormat
beegoTplFuncMap
[
"date"
]
=
Date
beegoTplFuncMap
[
"compare"
]
=
Compare
...
...
@@ -79,7 +76,7 @@ type templatefile struct {
files
map
[
string
][]
string
}
func
(
sel
f
*
templatefile
)
visit
(
paths
string
,
f
os
.
FileInfo
,
err
error
)
error
{
func
(
t
f
*
templatefile
)
visit
(
paths
string
,
f
os
.
FileInfo
,
err
error
)
error
{
if
f
==
nil
{
return
err
}
...
...
@@ -92,21 +89,21 @@ func (self *templatefile) visit(paths string, f os.FileInfo, err error) error {
replace
:=
strings
.
NewReplacer
(
"
\\
"
,
"/"
)
a
:=
[]
byte
(
paths
)
a
=
a
[
len
([]
byte
(
sel
f
.
root
))
:
]
a
=
a
[
len
([]
byte
(
t
f
.
root
))
:
]
file
:=
strings
.
TrimLeft
(
replace
.
Replace
(
string
(
a
)),
"/"
)
subdir
:=
filepath
.
Dir
(
file
)
if
_
,
ok
:=
sel
f
.
files
[
subdir
];
ok
{
self
.
files
[
subdir
]
=
append
(
sel
f
.
files
[
subdir
],
file
)
if
_
,
ok
:=
t
f
.
files
[
subdir
];
ok
{
tf
.
files
[
subdir
]
=
append
(
t
f
.
files
[
subdir
],
file
)
}
else
{
m
:=
make
([]
string
,
1
)
m
[
0
]
=
file
sel
f
.
files
[
subdir
]
=
m
t
f
.
files
[
subdir
]
=
m
}
return
nil
}
// return this path contains supported template extension of beego or not.
//
HasTemplateExt
return this path contains supported template extension of beego or not.
func
HasTemplateExt
(
paths
string
)
bool
{
for
_
,
v
:=
range
BeeTemplateExt
{
if
strings
.
HasSuffix
(
paths
,
"."
+
v
)
{
...
...
@@ -116,7 +113,7 @@ func HasTemplateExt(paths string) bool {
return
false
}
// add new extension for template.
//
AddTemplateExt
add new extension for template.
func
AddTemplateExt
(
ext
string
)
{
for
_
,
v
:=
range
BeeTemplateExt
{
if
v
==
ext
{
...
...
@@ -126,15 +123,14 @@ func AddTemplateExt(ext string) {
BeeTemplateExt
=
append
(
BeeTemplateExt
,
ext
)
}
// build all template files in a directory.
//
BuildTemplate will
build all template files in a directory.
// it makes beego can render any template file in view directory.
func
BuildTemplate
(
dir
string
,
files
...
string
)
error
{
if
_
,
err
:=
os
.
Stat
(
dir
);
err
!=
nil
{
if
os
.
IsNotExist
(
err
)
{
return
nil
}
else
{
return
errors
.
New
(
"dir open err"
)
}
return
errors
.
New
(
"dir open err"
)
}
self
:=
&
templatefile
{
root
:
dir
,
...
...
template_test.go
View file @
44bd3beb
...
...
@@ -20,11 +20,11 @@ import (
"testing"
)
var
header
string
=
`{{define "header"}}
var
header
=
`{{define "header"}}
<h1>Hello, astaxie!</h1>
{{end}}`
var
index
string
=
`<!DOCTYPE html>
var
index
=
`<!DOCTYPE html>
<html>
<head>
<title>beego welcome template</title>
...
...
@@ -37,7 +37,7 @@ var index string = `<!DOCTYPE html>
</html>
`
var
block
string
=
`{{define "block"}}
var
block
=
`{{define "block"}}
<h1>Hello, blocks!</h1>
{{end}}`
...
...
@@ -82,7 +82,7 @@ func TestTemplate(t *testing.T) {
os
.
RemoveAll
(
dir
)
}
var
menu
string
=
`<div class="menu">
var
menu
=
`<div class="menu">
<ul>
<li>menu1</li>
<li>menu2</li>
...
...
@@ -90,7 +90,7 @@ var menu string = `<div class="menu">
</ul>
</div>
`
var
user
string
=
`<!DOCTYPE html>
var
user
=
`<!DOCTYPE html>
<html>
<head>
<title>beego welcome template</title>
...
...
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