]> Cypherpunks repositories - gostls13.git/commit
text/template: allow grouping of pipelines using parentheses
authorRob Pike <r@golang.org>
Fri, 24 Aug 2012 19:37:23 +0000 (12:37 -0700)
committerRob Pike <r@golang.org>
Fri, 24 Aug 2012 19:37:23 +0000 (12:37 -0700)
commitcc842c738ea9a64570e306cbab37c3e3cf9a35dd
treed551a023206f14351558585b953835f87d623efc
parent3bd8684facfadb57ba649cae6b067e3a3ecb1208
text/template: allow grouping of pipelines using parentheses

Based on work by Russ Cox. From his CL:

        This is generally useful but especially helpful when trying
        to use the built-in boolean operators.  It lets you write:

        {{if not (f 1)}} foo {{end}}
        {{if and (f 1) (g 2)}} bar {{end}}
        {{if or (f 1) (g 2)}} quux {{end}}

        instead of

        {{if f 1 | not}} foo {{end}}
        {{if f 1}}{{if g 2}} bar {{end}}{{end}}
        {{$do := 0}}{{if f 1}}{{$do := 1}}{{else if g 2}}{{$do := 1}}{{end}}{{if $do}} quux {{end}}

The result can be a bit LISPy but the benefit in expressiveness and readability
for such a small change justifies it.

I believe no changes are required to html/template.

Fixes #3276.

R=golang-dev, adg, rogpeppe, minux.ma
CC=golang-dev
https://golang.org/cl/6482056
src/pkg/text/template/doc.go
src/pkg/text/template/exec.go
src/pkg/text/template/exec_test.go
src/pkg/text/template/parse/lex.go
src/pkg/text/template/parse/lex_test.go
src/pkg/text/template/parse/node.go
src/pkg/text/template/parse/parse.go
src/pkg/text/template/parse/parse_test.go