[PATCH 08 of 10 RFC] templatekw: add labelify to _showlist to mimic ''.join()
Sean Farley
sean.michael.farley at gmail.com
Thu Dec 20 23:37:58 CST 2012
# HG changeset patch
# User Sean Farley <sean.michael.farley at gmail.com>
# Date 1356045924 21600
# Node ID 17ff3c6ffb3fb21e6431fc01626ba29e1e448a1b
# Parent a4f4ae7e3e20324f706677d898aac343734ce3a3
templatekw: add labelify to _showlist to mimic ''.join()
This patch represents one of the prices of labeling a list of values: because this is now a list of dictionaries, we can't use ''.join(). Therefore, this hacks the yield to append a space.
Mayhaps we could use the built-in template version of 'join'?
diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
--- a/mercurial/templatekw.py
+++ b/mercurial/templatekw.py
@@ -61,23 +61,30 @@
return
if name not in templ:
if isinstance(values[0], str):
yield ' '.join(values)
else:
- for v in values:
- yield dict(v, **args)
+ for i, v in enumerate(values):
+ # should this use template function 'join'? if so then I don't
+ # know how to pass context and mapping yet. So, just append a
+ # ' ' for now.
+ data, label = delabelify(v)
+ if isinstance(data, str) and i < len(values) - 1:
+ data += ' '
+ yield dict(labelify(data, label), **args)
return
startname = 'start_' + names
if startname in templ:
yield templ(startname, **args)
vargs = args.copy()
def one(v, tag=name):
+ val, label = delabelify(v)
try:
- vargs.update(v)
+ vargs.update(val)
except (AttributeError, ValueError):
try:
- for a, b in v:
+ for a, b in val:
vargs[a] = b
except ValueError:
vargs[name] = v
return templ(tag, **vargs)
lastname = 'last_' + name
More information about the Mercurial-devel
mailing list