Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
a09ba8b6
Commit
a09ba8b6
authored
Aug 08, 2011
by
David Symonds
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
exp/template: url filter.
R=r CC=golang-dev
https://golang.org/cl/4837063
parent
ec010fdd
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
0 deletions
+21
-0
src/pkg/exp/template/doc.go
src/pkg/exp/template/doc.go
+3
-0
src/pkg/exp/template/exec_test.go
src/pkg/exp/template/exec_test.go
+3
-0
src/pkg/exp/template/funcs.go
src/pkg/exp/template/funcs.go
+15
-0
No files found.
src/pkg/exp/template/doc.go
View file @
a09ba8b6
...
...
@@ -244,6 +244,9 @@ Predefined global functions are named as follows.
An alias for fmt.Sprintf
println
An alias for fmt.Sprintln
url
Returns the escaped value of the textual representation of
its arguments in a form suitable for embedding in a URL.
The boolean functions take any zero value to be false and a non-zero value to
be true.
...
...
src/pkg/exp/template/exec_test.go
View file @
a09ba8b6
...
...
@@ -283,6 +283,9 @@ var execTests = []execTest{
// JavaScript.
{
"js"
,
`{{js .}}`
,
`It\'d be nice.`
,
`It'd be nice.`
,
true
},
// URL.
{
"url"
,
`{{"http://www.example.org/"|url}}`
,
"http%3A%2F%2Fwww.example.org%2F"
,
nil
,
true
},
// Booleans
{
"not"
,
"{{not true}} {{not false}}"
,
"false true"
,
nil
,
true
},
{
"and"
,
"{{and false 0}} {{and 1 0}} {{and 0 true}} {{and 1 1}}"
,
"false 0 0 1"
,
nil
,
true
},
...
...
src/pkg/exp/template/funcs.go
View file @
a09ba8b6
...
...
@@ -7,6 +7,7 @@ package template
import
(
"bytes"
"fmt"
"http"
"io"
"os"
"reflect"
...
...
@@ -31,6 +32,7 @@ var funcs = map[string]reflect.Value{
"print"
:
reflect
.
ValueOf
(
fmt
.
Sprint
),
"printf"
:
reflect
.
ValueOf
(
fmt
.
Sprintf
),
"println"
:
reflect
.
ValueOf
(
fmt
.
Sprintln
),
"url"
:
reflect
.
ValueOf
(
URLEscaper
),
}
// addFuncs adds to values the functions in funcs, converting them to reflect.Values.
...
...
@@ -318,3 +320,16 @@ func JSEscaper(args ...interface{}) string {
}
return
JSEscapeString
(
s
)
}
// URLEscaper returns the escaped value of the textual representation of its
// arguments in a form suitable for embedding in a URL.
func
URLEscaper
(
args
...
interface
{})
string
{
s
,
ok
:=
""
,
false
if
len
(
args
)
==
1
{
s
,
ok
=
args
[
0
]
.
(
string
)
}
if
!
ok
{
s
=
fmt
.
Sprint
(
args
...
)
}
return
http
.
URLEscape
(
s
)
}
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