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
0476da50
authored
2013-09-13 17:41:31 +0800
by
astaxie
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
improve template
1 parent
943fe971
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
9 deletions
template.go
template.go
View file @
0476da5
...
...
@@ -126,15 +126,15 @@ func BuildTemplate(dir string) error {
return
nil
}
func
getTplDeep
(
root
,
file
string
,
t
*
template
.
Template
)
(
*
template
.
Template
,
error
)
{
func
getTplDeep
(
root
,
file
string
,
t
*
template
.
Template
)
(
*
template
.
Template
,
[][]
string
,
error
)
{
fileabspath
:=
filepath
.
Join
(
root
,
file
)
data
,
err
:=
ioutil
.
ReadFile
(
fileabspath
)
if
err
!=
nil
{
return
nil
,
err
return
nil
,
[][]
string
{},
err
}
t
,
err
=
t
.
New
(
file
)
.
Parse
(
string
(
data
))
if
err
!=
nil
{
return
nil
,
err
return
nil
,
[][]
string
{},
err
}
reg
:=
regexp
.
MustCompile
(
"{{[ ]*template[ ]+
\"
([^
\"
]+)
\"
"
)
allsub
:=
reg
.
FindAllStringSubmatch
(
string
(
data
),
-
1
)
...
...
@@ -147,27 +147,58 @@ func getTplDeep(root, file string, t *template.Template) (*template.Template, er
if
!
HasTemplateEXt
(
m
[
1
])
{
continue
}
t
,
err
=
getTplDeep
(
root
,
m
[
1
],
t
)
t
,
_
,
err
=
getTplDeep
(
root
,
m
[
1
],
t
)
if
err
!=
nil
{
return
nil
,
err
return
nil
,
[][]
string
{},
err
}
}
}
return
t
,
nil
return
t
,
allsub
,
nil
}
func
getTemplate
(
root
,
file
string
,
others
...
string
)
(
t
*
template
.
Template
,
err
error
)
{
t
=
template
.
New
(
file
)
.
Delims
(
TemplateLeft
,
TemplateRight
)
.
Funcs
(
beegoTplFuncMap
)
t
,
err
=
getTplDeep
(
root
,
file
,
t
)
var
submods
[][]
string
t
,
submods
,
err
=
getTplDeep
(
root
,
file
,
t
)
for
_
,
m
:=
range
submods
{
if
len
(
m
)
==
2
{
templ
:=
t
.
Lookup
(
m
[
1
])
if
templ
!=
nil
{
continue
}
//first check filename
for
_
,
otherfile
:=
range
others
{
if
temp
:=
t
.
Lookup
(
otherfile
);
temp
!=
nil
{
if
otherfile
==
m
[
1
]
{
t
,
_
,
err
=
getTplDeep
(
root
,
otherfile
,
t
)
if
err
!=
nil
{
Trace
(
"template parse file err:"
,
err
)
}
break
}
}
//second check define
for
_
,
otherfile
:=
range
others
{
fileabspath
:=
filepath
.
Join
(
root
,
otherfile
)
data
,
err
:=
ioutil
.
ReadFile
(
fileabspath
)
if
err
!=
nil
{
continue
}
t
,
err
=
getTplDeep
(
root
,
otherfile
,
t
)
reg
:=
regexp
.
MustCompile
(
"{{[ ]*define[ ]+
\"
([^
\"
]+)
\"
"
)
allsub
:=
reg
.
FindAllStringSubmatch
(
string
(
data
),
-
1
)
for
_
,
sub
:=
range
allsub
{
if
len
(
sub
)
==
2
&&
sub
[
1
]
==
m
[
1
]
{
t
,
_
,
err
=
getTplDeep
(
root
,
otherfile
,
t
)
if
err
!=
nil
{
Trace
(
"template parse file err:"
,
err
)
}
break
}
}
}
}
}
if
err
!=
nil
{
return
nil
,
err
}
...
...
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