templatekw: add default implementation of _hybrid.gen
authorYuya Nishihara <yuya@tcha.org>
Wed, 12 Apr 2017 21:10:47 +0900
changeset 31923 68c910fa9ee2
parent 31922 0f41f1e3c75c
child 31924 21f129354dd0
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.
mercurial/templatekw.py
--- 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: