288 if isinstance(thing, types.GeneratorType): |
288 if isinstance(thing, types.GeneratorType): |
289 thing = stringify(thing) |
289 thing = stringify(thing) |
290 return thing |
290 return thing |
291 |
291 |
292 def evalboolean(context, mapping, arg): |
292 def evalboolean(context, mapping, arg): |
|
293 """Evaluate given argument as boolean, but also takes boolean literals""" |
293 func, data = arg |
294 func, data = arg |
294 thing = func(context, mapping, data) |
295 if func is runsymbol: |
|
296 thing = func(context, mapping, data, default=None) |
|
297 if thing is None: |
|
298 # not a template keyword, takes as a boolean literal |
|
299 thing = util.parsebool(data) |
|
300 else: |
|
301 thing = func(context, mapping, data) |
295 if isinstance(thing, bool): |
302 if isinstance(thing, bool): |
296 return thing |
303 return thing |
297 # other objects are evaluated as strings, which means 0 is True, but |
304 # 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 '' |
305 # empty dict/list should be False as they are expected to be '' |
299 return bool(stringify(thing)) |
306 return bool(stringify(thing)) |
514 right = False |
521 right = False |
515 fillchar = ' ' |
522 fillchar = ' ' |
516 if len(args) > 2: |
523 if len(args) > 2: |
517 fillchar = evalstring(context, mapping, args[2]) |
524 fillchar = evalstring(context, mapping, args[2]) |
518 if len(args) > 3: |
525 if len(args) > 3: |
519 right = util.parsebool(args[3][1]) |
526 right = evalboolean(context, mapping, args[3]) |
520 |
527 |
521 if right: |
528 if right: |
522 return text.rjust(width, fillchar) |
529 return text.rjust(width, fillchar) |
523 else: |
530 else: |
524 return text.ljust(width, fillchar) |
531 return text.ljust(width, fillchar) |