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
18659e16
Commit
18659e16
authored
Jan 05, 2015
by
Black.Lee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add compare_not/not_nil methods for template
parent
07c628c7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
1 deletion
+21
-1
template.go
template.go
+3
-0
templatefunc.go
templatefunc.go
+8
-0
templatefunc_test.go
templatefunc_test.go
+10
-1
No files found.
template.go
View file @
18659e16
...
@@ -42,6 +42,9 @@ func init() {
...
@@ -42,6 +42,9 @@ func init() {
beegoTplFuncMap
[
"dateformat"
]
=
DateFormat
beegoTplFuncMap
[
"dateformat"
]
=
DateFormat
beegoTplFuncMap
[
"date"
]
=
Date
beegoTplFuncMap
[
"date"
]
=
Date
beegoTplFuncMap
[
"compare"
]
=
Compare
beegoTplFuncMap
[
"compare"
]
=
Compare
beegoTplFuncMap
[
"compare_not"
]
=
CompareNot
beegoTplFuncMap
[
"not_nil"
]
=
NotNil
beegoTplFuncMap
[
"not_null"
]
=
NotNil
beegoTplFuncMap
[
"substr"
]
=
Substr
beegoTplFuncMap
[
"substr"
]
=
Substr
beegoTplFuncMap
[
"html2str"
]
=
Html2str
beegoTplFuncMap
[
"html2str"
]
=
Html2str
beegoTplFuncMap
[
"str2html"
]
=
Str2html
beegoTplFuncMap
[
"str2html"
]
=
Str2html
...
...
templatefunc.go
View file @
18659e16
...
@@ -139,6 +139,14 @@ func Compare(a, b interface{}) (equal bool) {
...
@@ -139,6 +139,14 @@ func Compare(a, b interface{}) (equal bool) {
return
return
}
}
func
CompareNot
(
a
,
b
interface
{})
(
equal
bool
)
{
return
!
Compare
(
a
,
b
)
}
func
NotNil
(
a
interface
{})
(
is_nil
bool
)
{
return
CompareNot
(
a
,
nil
)
}
func
Config
(
returnType
,
key
string
,
defaultVal
interface
{})
(
value
interface
{},
err
error
)
{
func
Config
(
returnType
,
key
string
,
defaultVal
interface
{})
(
value
interface
{},
err
error
)
{
switch
returnType
{
switch
returnType
{
case
"String"
:
case
"String"
:
...
...
templatefunc_test.go
View file @
18659e16
...
@@ -72,7 +72,7 @@ func TestDate(t *testing.T) {
...
@@ -72,7 +72,7 @@ func TestDate(t *testing.T) {
}
}
}
}
func
TestCompare
(
t
*
testing
.
T
)
{
func
TestCompare
Related
(
t
*
testing
.
T
)
{
if
!
Compare
(
"abc"
,
"abc"
)
{
if
!
Compare
(
"abc"
,
"abc"
)
{
t
.
Error
(
"should be equal"
)
t
.
Error
(
"should be equal"
)
}
}
...
@@ -82,6 +82,15 @@ func TestCompare(t *testing.T) {
...
@@ -82,6 +82,15 @@ func TestCompare(t *testing.T) {
if
!
Compare
(
"1"
,
1
)
{
if
!
Compare
(
"1"
,
1
)
{
t
.
Error
(
"should be equal"
)
t
.
Error
(
"should be equal"
)
}
}
if
CompareNot
(
"abc"
,
"abc"
)
{
t
.
Error
(
"should be equal"
)
}
if
!
CompareNot
(
"abc"
,
"aBc"
)
{
t
.
Error
(
"should be not equal"
)
}
if
!
NotNil
(
"a string"
)
{
t
.
Error
(
"should not be nil"
)
}
}
}
func
TestHtmlquote
(
t
*
testing
.
T
)
{
func
TestHtmlquote
(
t
*
testing
.
T
)
{
...
...
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