templatefilters: add "nonempty" template filter
authorRocco Rutte <pdmef@gmx.net>
Mon, 20 Apr 2009 11:34:15 +0200
changeset 8234 27dbe534397b
parent 8233 655c435efe92
child 8235 89bc3946c8f3
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.
mercurial/templatefilters.py
--- 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,