diff 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
line wrap: on
line diff
--- a/mercurial/templatefilters.py	Thu May 01 19:57:25 2014 +0900
+++ b/mercurial/templatefilters.py	Thu Jun 12 17:45:41 2014 -0700
@@ -8,6 +8,7 @@
 import cgi, re, os, time, urllib
 import encoding, node, util
 import hbisect
+import templatekw
 
 def addbreaks(text):
     """:addbreaks: Any text. Add an XHTML "<br />" tag before the end of
@@ -302,6 +303,10 @@
     """:shortdate: Date. Returns a date like "2006-09-18"."""
     return util.shortdate(text)
 
+def splitlines(text):
+    """:splitlines: Any text. Split text into a list of lines."""
+    return templatekw.showlist('line', text.splitlines(), 'lines')
+
 def stringescape(text):
     return text.encode('string_escape')
 
@@ -384,6 +389,7 @@
     "short": short,
     "shortbisect": shortbisect,
     "shortdate": shortdate,
+    "splitlines": splitlines,
     "stringescape": stringescape,
     "stringify": stringify,
     "strip": strip,