webcommands: move nonempty logic from JavaScript to Python
This avoids hard-coding the '(none)' string in the JavaScript for each
style and avoids the {nonexisting|nonempty} hack which only works
since the template system don't complain about undefined variables.
--- a/mercurial/hgweb/webcommands.py Mon Apr 20 12:10:04 2009 +0200
+++ b/mercurial/hgweb/webcommands.py Tue Apr 28 17:28:00 2009 +0200
@@ -646,7 +646,7 @@
node = short(ctx.node())
age = templatefilters.age(ctx.date())
desc = templatefilters.firstline(ctx.description())
- desc = cgi.escape(desc)
+ desc = cgi.escape(templatefilters.nonempty(desc))
user = cgi.escape(templatefilters.person(ctx.user()))
branch = ctx.branch()
branch = branch, web.repo.branchtags().get(branch) == ctx.node()
--- a/templates/gitweb/graph.tmpl Mon Apr 20 12:10:04 2009 +0200
+++ b/templates/gitweb/graph.tmpl Tue Apr 28 17:28:00 2009 +0200
@@ -78,10 +78,7 @@
item = item.replace(/_PARITY/, 'parity' + parity);
item = item.replace(/_NODEID/, cur[0]);
item = item.replace(/_NODEID/, cur[0]);
- if (cur[3] != '')
- item = item.replace(/_DESC/, cur[3]);
- else
- item = item.replace(/_DESC/, '(none)');
+ item = item.replace(/_DESC/, cur[3]);
item = item.replace(/_USER/, cur[4]);
item = item.replace(/_DATE/, cur[5]);
--- a/templates/monoblue/graph.tmpl Mon Apr 20 12:10:04 2009 +0200
+++ b/templates/monoblue/graph.tmpl Tue Apr 28 17:28:00 2009 +0200
@@ -75,10 +75,7 @@
item = item.replace(/_PARITY/, 'parity' + parity);
item = item.replace(/_NODEID/, cur[0]);
item = item.replace(/_NODEID/, cur[0]);
- if (cur[3] != '')
- item = item.replace(/_DESC/, cur[3]);
- else
- item = item.replace(/_DESC/, '(none)');
+ item = item.replace(/_DESC/, cur[3]);
item = item.replace(/_USER/, cur[4]);
item = item.replace(/_DATE/, cur[5]);
--- a/templates/paper/graph.tmpl Mon Apr 20 12:10:04 2009 +0200
+++ b/templates/paper/graph.tmpl Tue Apr 28 17:28:00 2009 +0200
@@ -86,10 +86,7 @@
item = item.replace(/_PARITY/, 'parity' + parity);
item = item.replace(/_NODEID/, cur[0]);
item = item.replace(/_NODEID/, cur[0]);
- if (cur[3] != '')
- item = item.replace(/_DESC/, cur[3]);
- else
- item = item.replace(/_DESC/, '(none)');
+ item = item.replace(/_DESC/, cur[3]);
item = item.replace(/_USER/, cur[4]);
item = item.replace(/_DATE/, cur[5]);
--- a/templates/spartan/graph.tmpl Mon Apr 20 12:10:04 2009 +0200
+++ b/templates/spartan/graph.tmpl Tue Apr 28 17:28:00 2009 +0200
@@ -70,10 +70,7 @@
item = item.replace(/_PARITY/, 'parity' + parity);
item = item.replace(/_NODEID/, cur[0]);
item = item.replace(/_NODEID/, cur[0]);
- if (cur[3] != '')
- item = item.replace(/_DESC/, cur[3]);
- else
- item = item.replace(/_DESC/, '(none)');
+ item = item.replace(/_DESC/, cur[3]);
item = item.replace(/_USER/, cur[4]);
item = item.replace(/_DATE/, cur[5]);
Binary file tests/test-hgweb-commands.out has changed
--- a/tests/test-hgweb-empty.out Mon Apr 20 12:10:04 2009 +0200
+++ b/tests/test-hgweb-empty.out Tue Apr 28 17:28:00 2009 +0200
@@ -230,10 +230,7 @@
item = item.replace(/_PARITY/, 'parity' + parity);
item = item.replace(/_NODEID/, cur[0]);
item = item.replace(/_NODEID/, cur[0]);
- if (cur[3] != '')
- item = item.replace(/_DESC/, cur[3]);
- else
- item = item.replace(/_DESC/, '(none)');
+ item = item.replace(/_DESC/, cur[3]);
item = item.replace(/_USER/, cur[4]);
item = item.replace(/_DATE/, cur[5]);