changeset 36550:c3692364b344

templatekw: add compatlist() as a replacement for showlist() Just like compatdict(), this is mostly a copy of showlist(). showchildren() is ported to the new API as an example.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 25 Feb 2018 16:14:37 +0900
parents a7fbe11a5d59
children c3df20906689
files mercurial/templatekw.py
diffstat 1 files changed, 15 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/templatekw.py	Sun Feb 25 16:03:19 2018 +0900
+++ b/mercurial/templatekw.py	Sun Feb 25 16:14:37 2018 +0900
@@ -148,6 +148,17 @@
     f = _showlist(name, c, t, mapping, plural, separator)
     return hybriddict(data, key=key, value=value, fmt=fmt, gen=f)
 
+def compatlist(context, mapping, name, data, element=None, fmt='%s',
+               plural=None, separator=' '):
+    """Wrap data like hybridlist(), but also supports old-style list template
+
+    This exists for backward compatibility with the old-style template. Use
+    hybridlist() for new template keywords.
+    """
+    t = context.resource(mapping, 'templ')
+    f = _showlist(name, data, t, mapping, plural, separator)
+    return hybridlist(data, name=element or name, fmt=fmt, gen=f)
+
 def showdict(name, data, mapping, plural=None, key='key', value='value',
              fmt='%s=%s', separator=' '):
     c = [{key: k, value: v} for k, v in data.iteritems()]
@@ -397,13 +408,12 @@
     f = _showlist('bookmark', bookmarks, args['templ'], args)
     return _hybrid(f, bookmarks, makemap, pycompat.identity)
 
-@templatekeyword('children')
-def showchildren(**args):
+@templatekeyword('children', requires={'ctx', 'templ'})
+def showchildren(context, mapping):
     """List of strings. The children of the changeset."""
-    args = pycompat.byteskwargs(args)
-    ctx = args['ctx']
+    ctx = context.resource(mapping, 'ctx')
     childrevs = ['%d:%s' % (cctx.rev(), cctx) for cctx in ctx.children()]
-    return showlist('children', childrevs, args, element='child')
+    return compatlist(context, mapping, 'children', childrevs, element='child')
 
 # Deprecated, but kept alive for help generation a purpose.
 @templatekeyword('currentbookmark', requires={'repo', 'ctx'})