diff mercurial/templatekw.py @ 31924:21f129354dd0

templatekw: add public function to wrap a list by _hybrid object
author Yuya Nishihara <yuya@tcha.org>
date Wed, 05 Apr 2017 22:25:36 +0900
parents 68c910fa9ee2
children 5b2241e84982
line wrap: on
line diff
--- a/mercurial/templatekw.py	Wed Apr 12 21:10:47 2017 +0900
+++ b/mercurial/templatekw.py	Wed Apr 05 22:25:36 2017 +0900
@@ -62,6 +62,10 @@
             raise AttributeError(name)
         return getattr(self._values, name)
 
+def hybridlist(data, name, fmt='%s', gen=None):
+    """Wrap data to support both list-like and string-like operations"""
+    return _hybrid(gen, data, lambda x: {name: x}, lambda d: fmt % d[name])
+
 def unwraphybrid(thing):
     """Return an object which can be stringified possibly by using a legacy
     template"""
@@ -73,7 +77,7 @@
     if not element:
         element = name
     f = _showlist(name, values, plural, separator, **args)
-    return _hybrid(f, values, lambda x: {element: x}, lambda d: d[element])
+    return hybridlist(values, name=element, gen=f)
 
 def _showlist(name, values, plural=None, separator=' ', **args):
     '''expand set of values.