Show More
@@ -327,6 +327,26 b' def pad(context, mapping, args):' | |||||
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 | |
@@ -607,6 +627,7 b' funcs = {' | |||||
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, |
@@ -3252,3 +3252,21 b' Test word for invalid numbers' | |||||
3252 | $ hg log -Gv -R a --template "{word('a', desc)}" |
|
3252 | $ hg log -Gv -R a --template "{word('a', desc)}" | |
3253 | hg: parse error: word expects an integer index |
|
3253 | hg: parse error: word expects an integer index | |
3254 | [255] |
|
3254 | [255] | |
|
3255 | ||||
|
3256 | Test indent and not adding to empty lines | |||
|
3257 | ||||
|
3258 | $ hg log -T "-----\n{indent(desc, '>> ', ' > ')}\n" -r 0:1 -R a | |||
|
3259 | ----- | |||
|
3260 | > line 1 | |||
|
3261 | >> line 2 | |||
|
3262 | ----- | |||
|
3263 | > other 1 | |||
|
3264 | >> other 2 | |||
|
3265 | ||||
|
3266 | >> other 3 | |||
|
3267 | ||||
|
3268 | Test with non-strings like dates | |||
|
3269 | ||||
|
3270 | $ hg log -T "{indent(date, ' ')}\n" -r 2:3 -R a | |||
|
3271 | 1200000.00 | |||
|
3272 | 1300000.00 |
General Comments 0
You need to be logged in to leave comments.
Login now