aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/text
diff options
context:
space:
mode:
authorNigel Tao <nigeltao@golang.org>2012-02-15 16:16:30 +1100
committerNigel Tao <nigeltao@golang.org>2012-02-15 16:16:30 +1100
commit0c5239410e90f14dadf87d73a7d8e9161eb0bec0 (patch)
tree6139b6d1f9af82287af34c322645dfbc5464a175 /src/pkg/text
parentaca8071fd53fc4f60771fe816b1e7c20c5c674fb (diff)
downloadgo-0c5239410e90f14dadf87d73a7d8e9161eb0bec0.tar.xz
html/template: add Clone and AddParseTree. Make text/template's Clone
return (*Template, error), not just *Template. Fixes #2757. R=r CC=golang-dev https://golang.org/cl/5665044
Diffstat (limited to 'src/pkg/text')
-rw-r--r--src/pkg/text/template/multi_test.go2
-rw-r--r--src/pkg/text/template/template.go8
2 files changed, 5 insertions, 5 deletions
diff --git a/src/pkg/text/template/multi_test.go b/src/pkg/text/template/multi_test.go
index 274f5ef147..f205e6be1b 100644
--- a/src/pkg/text/template/multi_test.go
+++ b/src/pkg/text/template/multi_test.go
@@ -193,7 +193,7 @@ func TestClone(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- clone := root.Clone()
+ clone := Must(root.Clone())
// Add variants to both.
_, err = root.Parse(cloneText3)
if err != nil {
diff --git a/src/pkg/text/template/template.go b/src/pkg/text/template/template.go
index 87e39d3af7..7494f9d8c4 100644
--- a/src/pkg/text/template/template.go
+++ b/src/pkg/text/template/template.go
@@ -69,9 +69,9 @@ func (t *Template) init() {
// templates. The actual representation is not copied, but the name space of
// associated templates is, so further calls to Parse in the copy will add
// templates to the copy but not to the original. Clone can be used to prepare
-// common templates and use them with variant definitions for other templates by
-// adding the variants after the clone is made.
-func (t *Template) Clone() *Template {
+// common templates and use them with variant definitions for other templates
+// by adding the variants after the clone is made.
+func (t *Template) Clone() (*Template, error) {
nt := t.copy(nil)
nt.init()
nt.tmpl[t.name] = nt
@@ -89,7 +89,7 @@ func (t *Template) Clone() *Template {
for k, v := range t.execFuncs {
nt.execFuncs[k] = v
}
- return nt
+ return nt, nil
}
// copy returns a shallow copy of t, with common set to the argument.