Mercurial > public > mercurial-scm > hg
comparison mercurial/templatefilters.py @ 21820:cce404b0c918
templatefilter: add splitlines function
This is useful for applying changes to each line, and it's especially powerful
when used in conjunction with conditionals to modify lines based on content.
author | Ryan McElroy <rmcelroy@fb.com> |
---|---|
date | Thu, 12 Jun 2014 17:45:41 -0700 |
parents | e828975722c8 |
children | cf599f8a2da8 |
comparison
equal
deleted
inserted
replaced
21819:816754e75f2f | 21820:cce404b0c918 |
---|---|
6 # GNU General Public License version 2 or any later version. | 6 # GNU General Public License version 2 or any later version. |
7 | 7 |
8 import cgi, re, os, time, urllib | 8 import cgi, re, os, time, urllib |
9 import encoding, node, util | 9 import encoding, node, util |
10 import hbisect | 10 import hbisect |
11 import templatekw | |
11 | 12 |
12 def addbreaks(text): | 13 def addbreaks(text): |
13 """:addbreaks: Any text. Add an XHTML "<br />" tag before the end of | 14 """:addbreaks: Any text. Add an XHTML "<br />" tag before the end of |
14 every line except the last. | 15 every line except the last. |
15 """ | 16 """ |
299 return hbisect.shortlabel(text) or ' ' | 300 return hbisect.shortlabel(text) or ' ' |
300 | 301 |
301 def shortdate(text): | 302 def shortdate(text): |
302 """:shortdate: Date. Returns a date like "2006-09-18".""" | 303 """:shortdate: Date. Returns a date like "2006-09-18".""" |
303 return util.shortdate(text) | 304 return util.shortdate(text) |
305 | |
306 def splitlines(text): | |
307 """:splitlines: Any text. Split text into a list of lines.""" | |
308 return templatekw.showlist('line', text.splitlines(), 'lines') | |
304 | 309 |
305 def stringescape(text): | 310 def stringescape(text): |
306 return text.encode('string_escape') | 311 return text.encode('string_escape') |
307 | 312 |
308 def stringify(thing): | 313 def stringify(thing): |
382 "rfc3339date": rfc3339date, | 387 "rfc3339date": rfc3339date, |
383 "rfc822date": rfc822date, | 388 "rfc822date": rfc822date, |
384 "short": short, | 389 "short": short, |
385 "shortbisect": shortbisect, | 390 "shortbisect": shortbisect, |
386 "shortdate": shortdate, | 391 "shortdate": shortdate, |
392 "splitlines": splitlines, | |
387 "stringescape": stringescape, | 393 "stringescape": stringescape, |
388 "stringify": stringify, | 394 "stringify": stringify, |
389 "strip": strip, | 395 "strip": strip, |
390 "stripdir": stripdir, | 396 "stripdir": stripdir, |
391 "tabindent": tabindent, | 397 "tabindent": tabindent, |