changeset 31923:68c910fa9ee2

templatekw: add default implementation of _hybrid.gen This is convenient for new template keyword, which doesn't need to support the legacy list hack (provided by _showlist()), but still wants to have a string representation.
author Yuya Nishihara <yuya@tcha.org>
date Wed, 12 Apr 2017 21:10:47 +0900
parents 0f41f1e3c75c
children 21f129354dd0
files mercurial/templatekw.py
diffstat 1 files changed, 11 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/templatekw.py	Sun Apr 09 11:58:27 2017 +0900
+++ b/mercurial/templatekw.py	Wed Apr 12 21:10:47 2017 +0900
@@ -32,10 +32,20 @@
     """
 
     def __init__(self, gen, values, makemap, joinfmt):
-        self.gen = gen
+        if gen is not None:
+            self.gen = gen
         self._values = values
         self._makemap = makemap
         self.joinfmt = joinfmt
+    @util.propertycache
+    def gen(self):
+        return self._defaultgen()
+    def _defaultgen(self):
+        """Generator to stringify this as {join(self, ' ')}"""
+        for i, d in enumerate(self.itermaps()):
+            if i > 0:
+                yield ' '
+            yield self.joinfmt(d)
     def itermaps(self):
         makemap = self._makemap
         for x in self._values: