aboutsummaryrefslogtreecommitdiff
path: root/src/text/template/exec.go
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2015-09-15 09:27:22 -0700
committerRob Pike <r@golang.org>2015-09-17 23:08:33 +0000
commita326c3e1ad3713c3e1c3373a45c6907e10fb1579 (patch)
tree2ccaf926d80fe816714c8fb4a68fbe560bae70d6 /src/text/template/exec.go
parent1216e181352c76d93d0ac501d22a5b7175c4cbf2 (diff)
downloadgo-a326c3e1ad3713c3e1c3373a45c6907e10fb1579.tar.xz
text/template: export isTrue
The definition of 'truth' used by if etc. is not trivial to compute, so publish the implementation to allow custom template functions to have the same definition as the template language itself. Fixes #12033. Change-Id: Icdfd6039722d7d3f984ba0905105eb3253e14831 Reviewed-on: https://go-review.googlesource.com/14593 Reviewed-by: Andrew Gerrand <adg@golang.org>
Diffstat (limited to 'src/text/template/exec.go')
-rw-r--r--src/text/template/exec.go9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/text/template/exec.go b/src/text/template/exec.go
index 625e9b54d6..8d74255070 100644
--- a/src/text/template/exec.go
+++ b/src/text/template/exec.go
@@ -242,7 +242,7 @@ func (s *state) walk(dot reflect.Value, node parse.Node) {
func (s *state) walkIfOrWith(typ parse.NodeType, dot reflect.Value, pipe *parse.PipeNode, list, elseList *parse.ListNode) {
defer s.pop(s.mark())
val := s.evalPipeline(dot, pipe)
- truth, ok := isTrue(val)
+ truth, ok := IsTrue(val)
if !ok {
s.errorf("if/with can't use %v", val)
}
@@ -257,9 +257,10 @@ func (s *state) walkIfOrWith(typ parse.NodeType, dot reflect.Value, pipe *parse.
}
}
-// isTrue reports whether the value is 'true', in the sense of not the zero of its type,
-// and whether the value has a meaningful truth value.
-func isTrue(val reflect.Value) (truth, ok bool) {
+// IsTrue reports whether the value is 'true', in the sense of not the zero of its type,
+// and whether the value has a meaningful truth value. This is the definition of
+// truth used by if and other such actions.
+func IsTrue(val reflect.Value) (truth, ok bool) {
if !val.IsValid() {
// Something like var x interface{}, never set. It's a form of nil.
return false, true