Show More
@@ -62,6 +62,8 b' In addition to filters, there are some b' | |||||
62 |
|
62 | |||
63 | - rstdoc(text, style) |
|
63 | - rstdoc(text, style) | |
64 |
|
64 | |||
|
65 | - strip(text, chars) | |||
|
66 | ||||
65 | Also, for any expression that returns a list, there is a list operator: |
|
67 | Also, for any expression that returns a list, there is a list operator: | |
66 |
|
68 | |||
67 | - expr % "{template}" |
|
69 | - expr % "{template}" |
@@ -333,6 +333,16 b' def date(context, mapping, args):' | |||||
333 | return util.datestr(date, fmt) |
|
333 | return util.datestr(date, fmt) | |
334 | return util.datestr(date) |
|
334 | return util.datestr(date) | |
335 |
|
335 | |||
|
336 | def strip(context, mapping, args): | |||
|
337 | if not (1 <= len(args) <= 2): | |||
|
338 | raise error.ParseError(_("strip expects one or two arguments")) | |||
|
339 | ||||
|
340 | text = args[0][0](context, mapping, args[0][1]) | |||
|
341 | if len(args) == 2: | |||
|
342 | chars = args[1][0](context, mapping, args[1][1]) | |||
|
343 | return text.strip(chars) | |||
|
344 | return text.strip() | |||
|
345 | ||||
336 | methods = { |
|
346 | methods = { | |
337 | "string": lambda e, c: (runstring, e[1]), |
|
347 | "string": lambda e, c: (runstring, e[1]), | |
338 | "symbol": lambda e, c: (runsymbol, e[1]), |
|
348 | "symbol": lambda e, c: (runsymbol, e[1]), | |
@@ -353,6 +363,7 b' funcs = {' | |||||
353 | "sub": sub, |
|
363 | "sub": sub, | |
354 | "fill": fill, |
|
364 | "fill": fill, | |
355 | "date": date, |
|
365 | "date": date, | |
|
366 | "strip": strip, | |||
356 | } |
|
367 | } | |
357 |
|
368 | |||
358 | # template engine |
|
369 | # template engine |
@@ -1536,3 +1536,31 b' Test the sub function of templating for ' | |||||
1536 |
|
1536 | |||
1537 | $ hg log -R latesttag -r 10 --template '{sub("[0-9]", "x", "{rev}")}\n' |
|
1537 | $ hg log -R latesttag -r 10 --template '{sub("[0-9]", "x", "{rev}")}\n' | |
1538 | xx |
|
1538 | xx | |
|
1539 | ||||
|
1540 | Test the strip function with chars specified: | |||
|
1541 | ||||
|
1542 | $ hg log -R latesttag --template '{desc}\n' | |||
|
1543 | at3 | |||
|
1544 | t5 | |||
|
1545 | t3 | |||
|
1546 | t2 | |||
|
1547 | t1 | |||
|
1548 | merge | |||
|
1549 | h2e | |||
|
1550 | h2d | |||
|
1551 | h1c | |||
|
1552 | b | |||
|
1553 | a | |||
|
1554 | ||||
|
1555 | $ hg log -R latesttag --template '{strip(desc, "te")}\n' | |||
|
1556 | at3 | |||
|
1557 | 5 | |||
|
1558 | 3 | |||
|
1559 | 2 | |||
|
1560 | 1 | |||
|
1561 | merg | |||
|
1562 | h2 | |||
|
1563 | h2d | |||
|
1564 | h1c | |||
|
1565 | b | |||
|
1566 | a |
General Comments 0
You need to be logged in to leave comments.
Login now