templatefilters: add "nonempty" template filter
It ensures that at least "(none)" is returned in case the argument
passed is None or ''. This is primarily useful to render empty
changelog messages for hgweb but may be useful for others, too.
--- a/mercurial/templatefilters.py Mon Apr 27 22:15:36 2009 +0200
+++ b/mercurial/templatefilters.py Mon Apr 20 11:34:15 2009 +0200
@@ -165,6 +165,9 @@
else:
return dir
+def nonempty(str):
+ return str or "(none)"
+
filters = {
"addbreaks": nl2br,
"basename": os.path.basename,
@@ -183,6 +186,7 @@
"isodatesec": lambda x: util.datestr(x, '%Y-%m-%d %H:%M:%S %1%2'),
"json": json,
"jsonescape": jsonescape,
+ "nonempty": nonempty,
"obfuscate": obfuscate,
"permissions": permissions,
"person": person,