aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2011-12-14 11:22:17 -0800
committerRob Pike <r@golang.org>2011-12-14 11:22:17 -0800
commit1402d1a68615d037365158578b0c4861e0fb4157 (patch)
treeb4b9d080ba94a7ba0e30ceb9bef6eaf4739e5adc
parent78821616d69c068bcab85e96ab97f0f157700840 (diff)
downloadgo-1402d1a68615d037365158578b0c4861e0fb4157.tar.gz
go-1402d1a68615d037365158578b0c4861e0fb4157.zip
html/template: define the FuncMap type locally
This redefinition means that the public signature of html/template does not refer to text/template. Fixes #2546. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/5487083
-rw-r--r--src/pkg/html/template/escape_test.go4
-rw-r--r--src/pkg/html/template/template.go12
2 files changed, 12 insertions, 4 deletions
diff --git a/src/pkg/html/template/escape_test.go b/src/pkg/html/template/escape_test.go
index cdeed48b82..2d15c71844 100644
--- a/src/pkg/html/template/escape_test.go
+++ b/src/pkg/html/template/escape_test.go
@@ -654,7 +654,7 @@ func TestEscape(t *testing.T) {
for _, test := range tests {
tmpl := New(test.name)
// TODO: Move noescape into template/func.go
- tmpl.Funcs(template.FuncMap{
+ tmpl.Funcs(FuncMap{
"noescape": func(a ...interface{}) string {
return fmt.Sprint(a...)
},
@@ -792,7 +792,7 @@ func TestEscapeSet(t *testing.T) {
// pred is a template function that returns the predecessor of a
// natural number for testing recursive templates.
- fns := template.FuncMap{"pred": func(a ...interface{}) (interface{}, error) {
+ fns := FuncMap{"pred": func(a ...interface{}) (interface{}, error) {
if len(a) == 1 {
if i, _ := a[0].(int); i > 0 {
return i - 1, nil
diff --git a/src/pkg/html/template/template.go b/src/pkg/html/template/template.go
index 4657f6ec52..9ffe41413a 100644
--- a/src/pkg/html/template/template.go
+++ b/src/pkg/html/template/template.go
@@ -154,12 +154,20 @@ func (t *Template) Name() string {
return t.text.Name()
}
+// FuncMap is the type of the map defining the mapping from names to
+// functions. Each function must have either a single return value, or two
+// return values of which the second has type error. In that case, if the
+// second (error) argument evaluates to non-nil during execution, execution
+// terminates and Execute returns that error. FuncMap has the same base type
+// as template.FuncMap, copied here so clients need not import "text/template".
+type FuncMap map[string]interface{}
+
// Funcs adds the elements of the argument map to the template's function map.
// It panics if a value in the map is not a function with appropriate return
// type. However, it is legal to overwrite elements of the map. The return
// value is the template, so calls can be chained.
-func (t *Template) Funcs(funcMap template.FuncMap) *Template {
- t.text.Funcs(funcMap)
+func (t *Template) Funcs(funcMap FuncMap) *Template {
+ t.text.Funcs(template.FuncMap(funcMap))
return t
}