comparison mercurial/templater.py @ 25489:ef8956aa8755

templater: introduce indent function
author Ryan McElroy <rmcelroy@fb.com>
date Sat, 04 Apr 2015 01:03:52 -0700
parents 081b08e4ea13
children ad14fb602e5e
comparison
equal deleted inserted replaced
25488:89ce95f907bd 25489:ef8956aa8755
325 if right: 325 if right:
326 return text.rjust(width, fillchar) 326 return text.rjust(width, fillchar)
327 else: 327 else:
328 return text.ljust(width, fillchar) 328 return text.ljust(width, fillchar)
329 329
330 def indent(context, mapping, args):
331 """:indent(text, indentchars[, firstline]): Indents all non-empty lines
332 with the characters given in the indentchars string. An optional
333 third parameter will override the indent for the first line only
334 if present."""
335 if not (2 <= len(args) <= 3):
336 # i18n: "indent" is a keyword
337 raise error.ParseError(_("indent() expects two or three arguments"))
338
339 text = stringify(args[0][0](context, mapping, args[0][1]))
340 indent = stringify(args[1][0](context, mapping, args[1][1]))
341
342 if len(args) == 3:
343 firstline = stringify(args[2][0](context, mapping, args[2][1]))
344 else:
345 firstline = indent
346
347 # the indent function doesn't indent the first line, so we do it here
348 return templatefilters.indent(firstline + text, indent)
349
330 def get(context, mapping, args): 350 def get(context, mapping, args):
331 """:get(dict, key): Get an attribute/key from an object. Some keywords 351 """:get(dict, key): Get an attribute/key from an object. Some keywords
332 are complex types. This function allows you to obtain the value of an 352 are complex types. This function allows you to obtain the value of an
333 attribute on these type.""" 353 attribute on these type."""
334 if len(args) != 2: 354 if len(args) != 2:
605 "fill": fill, 625 "fill": fill,
606 "get": get, 626 "get": get,
607 "if": if_, 627 "if": if_,
608 "ifcontains": ifcontains, 628 "ifcontains": ifcontains,
609 "ifeq": ifeq, 629 "ifeq": ifeq,
630 "indent": indent,
610 "join": join, 631 "join": join,
611 "label": label, 632 "label": label,
612 "pad": pad, 633 "pad": pad,
613 "revset": revset, 634 "revset": revset,
614 "rstdoc": rstdoc, 635 "rstdoc": rstdoc,