templater: factor out runtemplate method
authorMatt Mackall <mpm@selenic.com>
Sat, 22 Sep 2012 13:02:33 -0500
changeset 17632 523625e46760
parent 17631 0b241d7a8c62
child 17633 312184f930b7
templater: factor out runtemplate method As a side-effect, this makes the output of runmap non-flattened
mercurial/templater.py
--- a/mercurial/templater.py	Fri Sep 21 18:54:00 2012 -0500
+++ b/mercurial/templater.py	Sat Sep 22 13:02:33 2012 -0500
@@ -161,6 +161,10 @@
     ctmpl = gettemplate(exp[2], context)
     return (runmap, (func, data, ctmpl))
 
+def runtemplate(context, mapping, template):
+    for func, data in template:
+        yield func(context, mapping, data)
+
 def runmap(context, mapping, data):
     func, data, ctmpl = data
     d = func(context, mapping, data)
@@ -172,8 +176,7 @@
     for i in d:
         if isinstance(i, dict):
             lm.update(i)
-            for f, d in ctmpl:
-                yield f(context, lm, d)
+            yield runtemplate(context, lm, ctmpl)
         else:
             # v is not an iterable of dicts, this happen when 'key'
             # has been fully expanded already and format is useless.
@@ -276,6 +279,7 @@
         generator.'''
         return _flatten(func(self, mapping, data) for func, data in
                          self._load(t))
+        return _flatten(runtemplate(self, mapping, self._load(t)))
 
 engines = {'default': engine}