"io"
"io/ioutil"
"path/filepath"
+ "reflect"
"sync"
"text/template"
"text/template/parse"
}
return parseFiles(t, filenames...)
}
+
+// 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) {
+ return template.IsTrue(val)
+}
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)
}
}
}
-// 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
// Boolean logic.
func truth(a interface{}) bool {
- t, _ := isTrue(reflect.ValueOf(a))
+ t, _ := IsTrue(reflect.ValueOf(a))
return t
}
}
// not returns the Boolean negation of its argument.
-func not(arg interface{}) (truth bool) {
- truth, _ = isTrue(reflect.ValueOf(arg))
- return !truth
+func not(arg interface{}) bool {
+ return !truth(arg)
}
// Comparison.