]> Cypherpunks repositories - gostls13.git/commitdiff
exp/template: documentation glitches and typos.
authorRob Pike <r@golang.org>
Mon, 11 Jul 2011 04:43:21 +0000 (14:43 +1000)
committerRob Pike <r@golang.org>
Mon, 11 Jul 2011 04:43:21 +0000 (14:43 +1000)
Also explain that len(v)==0 makes v a 'zero value'
in template execution.

R=golang-dev, dsymonds, adg, r
CC=golang-dev
https://golang.org/cl/4691041

src/pkg/exp/template/doc.go
src/pkg/exp/template/helper.go

index ae0b97ceda80335e69ea330770c8dbc292a2c3fc..736b1a3d874e599e14f9c9c729db73ef75f1ce46 100644 (file)
@@ -33,9 +33,9 @@ data, defined in detail below.
                is copied to the output.
 
        {{if pipeline}} T1 {{end}}
-               If the value of the pipeline is the zero value for its type, no
-               output is generated; otherwise, T1 is executed. Dot is
-               unaffected.
+               If the value of the pipeline is the "zero value" (see below) for
+               its type, no output is generated; otherwise, T1 is executed.
+               Dot is unaffected.
 
        {{if pipeline}} T1 {{else}} T0 {{end}}
                If the value of the pipeline is the zero value for its type, T0
@@ -60,7 +60,7 @@ data, defined in detail below.
 
        {{template argument pipeline}}
                If the value of the argument is a string, the template with that
-               name is executed with data set to the value of the pipeline . If
+               name is executed with data set to the value of the pipeline. If
                the value of arg is of type *Template, that template is
                executed.
 
@@ -74,6 +74,9 @@ data, defined in detail below.
                is unaffected and T0 is executed; otherwise, dot is set to the
                value of the pipeline and T1 is executed.
 
+"Zero value" means the true zero value in Go terms.  Also, for arrays, slices,
+maps, and strings, any value v with len(v)==0 counts as a zero value.
+
 Arguments
 
 An argument is a simple value, denoted by one of the following:
@@ -91,6 +94,12 @@ An argument is a simple value, denoted by one of the following:
                $
          The result is the value of the variable.
          Variables are described below.
+       - The name of a field of the data, which must be a struct, preceded
+         by a period, such as
+               .Field
+         The result is the value of the field. Field invocations may be
+         chained:
+           .Field1.Field2
        - The name of a niladic method of the data, preceded by a period,
          such as
                .Method
@@ -99,6 +108,9 @@ An argument is a simple value, denoted by one of the following:
          any type) or two return values, the second of which is an os.Error.
          If it has two and the returned error is non-nil, execution terminates
          and that error is returned to the caller as the value of Execute.
+         Method invocations may be chained, but only the last element of
+         the chain may be a method; other others must be struct fields:
+           .Field1.Field2.Method
        - The name of a niladic function, such as
                fun
          The result is the value of invoking the function, fun(). The return
@@ -187,7 +199,7 @@ the set but the Funcs methods can be used to add them.
 Predefined global functions are named as follows.
 
        and
-               Returns the boolean and AND of its arguments.
+               Returns the boolean AND of its arguments.
        html
                Returns the escaped HTML equivalent of the textual
                representation of its arguments.
@@ -201,7 +213,7 @@ Predefined global functions are named as follows.
        not
                Returns the boolean negation of its single argument.
        or
-               Returns the booland OR of its arguments.
+               Returns the boolean OR of its arguments.
        print
                An alias for fmt.Sprint
        printf
index def4f01f3746fc5ff3d8a211794bc2759b518cc0..baf54fdad816350627379afeca98537bfcffe682 100644 (file)
@@ -42,7 +42,7 @@ func (t *Template) MustParseFile(filename string) *Template {
        return t
 }
 
-// ParseFile is a helper function that creates a new *Template and parses
+// ParseFile is a helper function that creates a new Template and parses
 // the template definition from the named file.
 // The template name is the base name of the file.
 func ParseFile(filename string) (*Template, os.Error) {
@@ -50,7 +50,7 @@ func ParseFile(filename string) (*Template, os.Error) {
        return t, t.ParseFile(filename)
 }
 
-// MustParseFile is a helper function that creates a new *Template and parses
+// MustParseFile is a helper function that creates a new Template and parses
 // the template definition from the named file.
 // The template name is the base name of the file.
 // It panics if the file cannot be read or the template cannot be parsed.
@@ -85,14 +85,14 @@ func (s *Set) MustParseFile(filename string) *Set {
        return s
 }
 
-// ParseSetFile is a helper function that creates a new *Set and parses
+// ParseSetFile is a helper function that creates a new Set and parses
 // the set definition from the named file.
 func ParseSetFile(filename string) (*Set, os.Error) {
        s := NewSet()
        return s, s.ParseFile(filename)
 }
 
-// MustParseSetFile is a helper function that creates a new *Set and parses
+// MustParseSetFile is a helper function that creates a new Set and parses
 // the set definition from the named file.
 // It panics if the file cannot be read or the set cannot be parsed.
 func MustParseSetFile(filename string) *Set {