##// END OF EJS Templates
templater: fix if() to not evaluate False as bool('False')...
Yuya Nishihara -
r29816:034412ca default
parent child Browse files
Show More
@@ -289,6 +289,15 b' def evalfuncarg(context, mapping, arg):'
289 289 thing = stringify(thing)
290 290 return thing
291 291
292 def evalboolean(context, mapping, arg):
293 func, data = arg
294 thing = func(context, mapping, data)
295 if isinstance(thing, bool):
296 return thing
297 # other objects are evaluated as strings, which means 0 is True, but
298 # empty dict/list should be False as they are expected to be ''
299 return bool(stringify(thing))
300
292 301 def evalinteger(context, mapping, arg, err):
293 302 v = evalfuncarg(context, mapping, arg)
294 303 try:
@@ -560,7 +569,7 b' def if_(context, mapping, args):'
560 569 # i18n: "if" is a keyword
561 570 raise error.ParseError(_("if expects two or three arguments"))
562 571
563 test = evalstring(context, mapping, args[0])
572 test = evalboolean(context, mapping, args[0])
564 573 if test:
565 574 yield args[1][0](context, mapping, args[1][1])
566 575 elif len(args) == 3:
@@ -516,6 +516,8 b' template output:'
516 516 }
517 517 ]
518 518
519 $ hg branches --closed -T '{if(closed, "{branch}\n")}'
520 c
519 521
520 522 Tests of revision branch name caching
521 523
General Comments 0
You need to be logged in to leave comments. Login now