comparison 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
comparison
equal deleted inserted replaced
8359:07ddec2ea203 8360:acc202b71619
5 # This software may be used and distributed according to the terms of the 5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2, incorporated herein by reference. 6 # GNU General Public License version 2, incorporated herein by reference.
7 7
8 import cgi, re, os, time, urllib, textwrap 8 import cgi, re, os, time, urllib, textwrap
9 import util, templater, encoding 9 import util, templater, encoding
10
11 def stringify(thing):
12 '''turn nested template iterator into string.'''
13 if hasattr(thing, '__iter__') and not isinstance(thing, str):
14 return "".join([stringify(t) for t in thing if t is not None])
15 return str(thing)
10 16
11 agescales = [("second", 1), 17 agescales = [("second", 1),
12 ("minute", 60), 18 ("minute", 60),
13 ("hour", 3600), 19 ("hour", 3600),
14 ("day", 3600 * 24), 20 ("day", 3600 * 24),
192 "person": person, 198 "person": person,
193 "rfc822date": lambda x: util.datestr(x, "%a, %d %b %Y %H:%M:%S %1%2"), 199 "rfc822date": lambda x: util.datestr(x, "%a, %d %b %Y %H:%M:%S %1%2"),
194 "rfc3339date": lambda x: util.datestr(x, "%Y-%m-%dT%H:%M:%S%1:%2"), 200 "rfc3339date": lambda x: util.datestr(x, "%Y-%m-%dT%H:%M:%S%1:%2"),
195 "short": lambda x: x[:12], 201 "short": lambda x: x[:12],
196 "shortdate": util.shortdate, 202 "shortdate": util.shortdate,
197 "stringify": templater.stringify, 203 "stringify": stringify,
198 "strip": lambda x: x.strip(), 204 "strip": lambda x: x.strip(),
199 "urlescape": lambda x: urllib.quote(x), 205 "urlescape": lambda x: urllib.quote(x),
200 "user": lambda x: util.shortuser(x), 206 "user": lambda x: util.shortuser(x),
201 "stringescape": lambda x: x.encode('string_escape'), 207 "stringescape": lambda x: x.encode('string_escape'),
202 "xmlescape": xmlescape, 208 "xmlescape": xmlescape,