1
0
mirror of https://github.com/golang/go synced 2024-10-04 10:31:22 -06:00
Commit Graph

53 Commits

Author SHA1 Message Date
Rob Pike
0e45890c8b text/template/parse: restore the goroutine
To avoid goroutines during init, the nextItem function was a
clever workaround. Now that init goroutines are permitted,
restore the original, simpler design.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/6282043
2012-06-01 18:34:14 -07:00
Ugorji Nwoke
4f7c33cd5a text/template: exec should accept interface value as valid.
Currently, if you pass some data to a template as an interface (e.g. interface{})
and extract that value that value as a parameter for a function, it fails, saying
wrong type.

This is because it is only looking at the interface type, not the interface content.

This CL uses the underlying content as the parameter to the func.

Fixes #3642.

R=golang-dev, r, r
CC=golang-dev
https://golang.org/cl/6218052
2012-05-22 15:21:35 -07:00
Rob Pike
459837c86e all: fix errors found by go vet
R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6125044
2012-04-25 11:33:27 +10:00
Rob Pike
11820899a5 text/template: improve the error reporting for unexported fields.
Changes suggested by rsc after last CL.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6117044
2012-04-24 13:11:59 +10:00
Rob Pike
a8098cbcfd text/template: detect unexported fields better
Moves the error detection back into execution, where it used to be,
and improves the error message.
Rolls back most of 6009048, which broke lower-case keys in maps.
If it weren't for maps we could detect this at compile time rather than
execution time.

Fixes #3542.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/6098051
2012-04-23 15:39:02 +10:00
Shenghou Ma
3180137b86 text/template/parse: fix doc comment
Fixes #3529.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/6037046
2012-04-15 21:50:21 +08:00
Rob Pike
2d0d3d8f9e text/template: catch unexported fields during parse
It's a common error to reference unexported field names in templates,
especially for newcomers. This catches the error at parse time rather than
execute time so the rare few who check errors will notice right away.

These were always an error, so the net behavior is unchanged.
Should break no existing code, just identify the error earlier.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/6009048
2012-04-12 15:57:09 +10:00
Nigel Tao
6277656d69 html, exp/html: escape ' and " as ' and ", since IE8 and
below do not support '.

This makes package html consistent with package text/template's
HTMLEscape function.

Fixes #3489.

R=rsc, mikesamuel, dsymonds
CC=golang-dev
https://golang.org/cl/5992071
2012-04-12 09:35:43 +10:00
Rob Pike
065db4ea99 text/template: pipelined arg was not typechecked
Without this fix, an erroneous template causes a panic; should be caught safely.
The bug did not affect correct templates.

Fixes #3267.

R=golang-dev, dsymonds, rsc
CC=golang-dev
https://golang.org/cl/5900065
2012-04-03 11:44:52 +10:00
Robert Griesemer
43ad726f34 text/template: fix typo in package comment
Fixes #3383.

R=iant, bradfitz
CC=golang-dev
https://golang.org/cl/5891045
2012-03-23 11:31:29 -07:00
Rob Pike
d6ad6f0e61 text/template: variables do not take arguments
R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/5821044
2012-03-14 10:46:21 +11:00
Rob Pike
8170d81f4f text/template: fix a couple of parse bugs around identifiers.
1) Poor error checking in variable declarations admitted
$x=2 or even $x%2.
2) Need white space or suitable termination character
after identifiers, so $x+2 doesn't parse, in case we want it
to mean something one day.
Number 2 in particular prevents mistakes that we will have
to honor later and so is necessary for Go 1.

Fixes #3270.
Fixes #3271.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5795073
2012-03-14 07:03:11 +11:00
Rob Pike
227a04d771 text/template: one more test case
Missed a case for variadic functions with too few arguments.
The code passes, and with the right error, but might as well record the test case.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/5732050
2012-03-04 08:06:26 +11:00
Rob Pike
f1d3ff1660 text/template: clean up function values
The recent addition of automatic function invocation generated
some troublesome ambiguities. Restore the previous behavior
and compensate by providing a "call" builtin to make it easy to
do what the automatic invocation did, but in a clear and explicit
manner.

Fixes #3140.

At least for now.

R=golang-dev, dsymonds, r
CC=golang-dev
https://golang.org/cl/5720065
2012-03-03 23:14:20 +11:00
Rob Pike
dd001b5931 text/template: add examples that use multiple templates
Fixes #2742.

R=golang-dev, peterthrun, adg
CC=golang-dev
https://golang.org/cl/5699083
2012-03-01 14:55:18 +11:00
Rob Pike
26c2443d80 text/template: add example showing use of custom function
R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/5694100
2012-02-28 15:50:41 +11:00
Rob Pike
180541b2b1 text/template: fix redefinition bugs
R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/5696087
2012-02-28 14:23:57 +11:00
Russ Cox
ebae73bb24 pprof: add Profile type
Makes it possible for client code to maintain its own profiles,
and also reduces the API surface by giving us a type that
models built-in profiles.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5684056
2012-02-22 21:46:12 -05:00
Robert Griesemer
5f2ecbff71 text/tabwriter: fix documentation by adding an example.
R=rsc, r
CC=golang-dev
https://golang.org/cl/5685069
2012-02-21 14:48:17 -08:00
Rob Pike
68b35b0852 templates: minor edits to the documentation
R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5677084
2012-02-19 07:45:12 +11:00
Andrew Gerrand
11e113db57 godoc: make example code more readable with new comment convention
go/doc: move Examples to go/ast
cmd/go: use go/doc to read examples
src/pkg: update examples to use new convention

This is to make whole file examples more readable. When presented as a
complete function, preceding an Example with its output is confusing.
The new convention is to put the expected output in the final comment
of the example, preceded by the string "output:" (case insensitive).

An idiomatic example looks like this:

// This example demonstrates Foo by doing bar and quux.
func ExampleFoo() {
        // example body that does bar and quux

        // Output:
        // example output
}

R=rsc, gri
CC=golang-dev
https://golang.org/cl/5673053
2012-02-16 11:50:28 +11:00
Nigel Tao
0c5239410e 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
2012-02-15 16:16:30 +11:00
Rob Pike
aca8071fd5 text/template: evaluate function fields
Just an oversight they didn't work and easy to address.

Fixes #3025.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/5656059
2012-02-15 16:05:34 +11:00
Rob Pike
47424d90ec text/template: drop reference to os.EPERM in the test
R=golang-dev, gri
CC=golang-dev
https://golang.org/cl/5654077
2012-02-14 07:11:39 +11:00
Rob Pike
b027a0f118 text/template/parse: deep Copy method for nodes
This will help html/template copy templates.

R=golang-dev, gri, nigeltao, r
CC=golang-dev
https://golang.org/cl/5653062
2012-02-11 14:21:16 +11:00
Rob Pike
0357af80b4 template: refer HTML users to html/template
Fixes #2963.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5650051
2012-02-10 14:21:36 +11:00
Robert Griesemer
88a9e76e28 text/scanner: update comments
Fixes #2962.

R=rsc
CC=golang-dev
https://golang.org/cl/5652048
2012-02-09 15:26:08 -08:00
Mikio Hara
d082e5976e text/template/parse: fix comment
R=r, rsc
CC=golang-dev
https://golang.org/cl/5644055
2012-02-09 07:47:48 +09:00
Russ Cox
ae7497bda6 doc: remove overuse of simply
Specifically, remove simply where it is claiming that the
code or the action to be carried out is simple, since the
reader might disagree.

R=golang-dev, bradfitz, gri
CC=golang-dev
https://golang.org/cl/5637048
2012-02-06 13:34:35 -05:00
Russ Cox
2050a9e478 build: remove Make.pkg, Make.tool
Consequently, remove many package Makefiles,
and shorten the few that remain.

gomake becomes 'go tool make'.

Turn off test phases of run.bash that do not work,
flagged with $BROKEN.  Future CLs will restore these,
but this seemed like a big enough CL already.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5601057
2012-01-30 23:43:46 -05:00
Andrew Gerrand
0bb8ce2984 text/template: add example for Template
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5564050
2012-01-25 09:24:25 +11:00
Rob Pike
c837e612bd text/template/parse: use human error prints
The previous version of all the node.String methods printed the parse
tree and was useful for developing the parse tree code. Now that that's done,
we might as well print the nodes using the standard template syntax.
It's much easier to read and makes error reporting look more natural.

Helps issue 2644.

R=rsc, n13m3y3r
CC=golang-dev
https://golang.org/cl/5553066
2012-01-19 13:51:37 -08:00
Rob Pike
4985ee3dcb text/template: fix nil error on redefinition
Fixes #2720.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/5545072
2012-01-17 13:24:59 -08:00
Rob Pike
a5950df89e template: for range on a map, sort the keys if feasible.
Fixes #2696.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5543055
2012-01-13 14:09:13 -08:00
Rémy Oudompheng
f5d024a746 text/template: handle panic values that are not errors.
The recover code assumes that the panic() argument was
an error, but it is usually a simple string.
Fixes #2663.

R=golang-dev, r, r, gri
CC=golang-dev, remy
https://golang.org/cl/5527046
2012-01-09 12:54:31 -08:00
Rob Pike
4869996b92 template: better error message for empty templates
New("x").ParseFiles("y") can result in an empty "x" template.
Make the message clearer that this is the problem. The error
returns from both template packages in this case were
confusing.

I considered making the method use "x" instead of "y" in
this case, but that just made other situations confusing
and harder to explain.

Fixes #2594.

R=golang-dev, rsc, r
CC=golang-dev
https://golang.org/cl/5498048
2011-12-20 12:58:23 -08:00
Gustavo Niemeyer
12f473f807 text/template: fix handing of nil arguments to functions
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5494070
2011-12-18 22:14:11 -02:00
Russ Cox
2666b815a3 use new strconv API
All but 3 cases (in gcimporter.go and hixie.go)
are automatic conversions using gofix.

No attempt is made to use the new Append functions
even though there are definitely opportunities.

R=golang-dev, gri
CC=golang-dev
https://golang.org/cl/5447069
2011-12-05 15:48:46 -05:00
Rob Pike
e6b3371781 template: move the empty check into parse, which needs it when constructing
tree sets.

R=golang-dev, gri
CC=golang-dev
https://golang.org/cl/5449062
2011-12-01 17:24:54 -08:00
Rob Pike
d38cc47c0c text/template: replace Add with AddParseTree
Makes it clear we're adding exactly one tree and creating a
new template for it.

R=rsc
CC=golang-dev
https://golang.org/cl/5448077
2011-12-01 09:19:53 -08:00
Rob Pike
5f6027e9ad text/template: address a couple of issues for html/template
- allow Lookup to work on uninitialized templates
- fix bug in add: can't error after parser is stopped
- add Add method for html/template

R=adg, rogpeppe, r, rsc
CC=golang-dev
https://golang.org/cl/5436080
2011-11-28 10:42:57 -08:00
Rob Pike
e9025df7ad text/template: rename the method Template.Template to Template.Lookup
Calling it Template makes it clumsy to embed the type, which html/template
depends on.

R=golang-dev, gri
CC=golang-dev
https://golang.org/cl/5432079
2011-11-26 08:32:55 -08:00
Rob Pike
0197cc49ae text/template: fix bug in Clone
Cloned template copied the root template incorrectly.
Add test of self-consistency.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/5436063
2011-11-24 16:07:19 -08:00
Rob Pike
f56db6f534 text/template: new, simpler API
The Set type is gone. Instead, templates are automatically associated by
being parsed together; nested definitions implicitly create associations.
Only associated templates can invoke one another.

This approach dramatically reduces the breadth of the construction API.

For now, html/template is deleted from src/pkg/Makefile, so this can
be checked in. Nothing in the tree depends on it. It will be updated next.

R=dsymonds, adg, rsc, r, gri, mikesamuel, nigeltao
CC=golang-dev
https://golang.org/cl/5415060
2011-11-23 20:17:22 -08:00
Rob Pike
10e012c85f template/parse: rename Set to Parse
Preamble to the simplification of the template API.
Although the signature of Parse (nee Set) changes,
it's really an internal function, used only by
text/template.

R=golang-dev, rsc, gri, r
CC=golang-dev
https://golang.org/cl/5415052
2011-11-18 13:10:15 -08:00
Rob Pike
25d2987dd9 text/template: refactor set parsing
Parse {{define}} blocks during template parsing rather than separately as a set-specific thing.
This cleans up set parse significantly, and enables the next step, if we want, to unify the
API for templates and sets.
Other than an argument change to parse.Parse, which is in effect an internal function and
unused by client code, there is no API change and no spec change yet.

R=golang-dev, rsc, r
CC=golang-dev
https://golang.org/cl/5393049
2011-11-17 22:53:23 -08:00
Russ Cox
fd34e78b53 various: reduce overuse of os.EINVAL + others
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5372081
2011-11-13 22:42:42 -05:00
Rob Pike
45e3bcb343 renaming_3: gofix -r go1pkgrename src/pkg/[m-z]*
R=rsc
CC=golang-dev
https://golang.org/cl/5345045
2011-11-08 15:41:54 -08:00
Rob Pike
6ab6c49fce renaming_1: hand-edited files for go 1 renaming
This contains the files that required handiwork, mostly
Makefiles with updated TARGs, plus the two packages
with modified package names.
html/template/doc.go needs a separate edit pass.
test/fixedbugs/bug358.go is not legal go so gofix fails on it.

R=rsc
CC=golang-dev
https://golang.org/cl/5340050
2011-11-08 15:38:47 -08:00
Rob Pike
3e94e757ef text/template: make redefinition of a template in a set more consistent.
Also make it agree with the documentation. You get an error, unless you're
calling Add explicitly, in which case it panics since that's almost certainly
a bug. The discrepancy was caused by a panic that wasn't turned into
an error along one path; deleted the offending function for clarity.

R=r, rsc
CC=golang-dev
https://golang.org/cl/5354045
2011-11-08 14:33:07 -08:00