diff mercurial/templatefilters.py @ 8360:acc202b71619

templater: provide the standard template filters by default
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Tue, 12 May 2009 12:04:05 +0200
parents 27dbe534397b
children 4b798b100c32
line wrap: on
line diff
--- a/mercurial/templatefilters.py	Tue May 12 10:57:55 2009 +0200
+++ b/mercurial/templatefilters.py	Tue May 12 12:04:05 2009 +0200
@@ -8,6 +8,12 @@
 import cgi, re, os, time, urllib, textwrap
 import util, templater, encoding
 
+def stringify(thing):
+    '''turn nested template iterator into string.'''
+    if hasattr(thing, '__iter__') and not isinstance(thing, str):
+        return "".join([stringify(t) for t in thing if t is not None])
+    return str(thing)
+
 agescales = [("second", 1),
              ("minute", 60),
              ("hour", 3600),
@@ -194,7 +200,7 @@
     "rfc3339date": lambda x: util.datestr(x, "%Y-%m-%dT%H:%M:%S%1:%2"),
     "short": lambda x: x[:12],
     "shortdate": util.shortdate,
-    "stringify": templater.stringify,
+    "stringify": stringify,
     "strip": lambda x: x.strip(),
     "urlescape": lambda x: urllib.quote(x),
     "user": lambda x: util.shortuser(x),