comparison mercurial/templateutil.py @ 37324:c2f74b8f6b7f

templater: pass context to itermaps() for future extension Unlike show() and tovalue(), a base mapping isn't passed to itermaps() since it is the function to generate a partial mapping.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 18 Mar 2018 23:24:50 +0900
parents 8c31b434697f
children 41a5d815d2c1
comparison
equal deleted inserted replaced
37323:8c31b434697f 37324:c2f74b8f6b7f
36 """ 36 """
37 37
38 __metaclass__ = abc.ABCMeta 38 __metaclass__ = abc.ABCMeta
39 39
40 @abc.abstractmethod 40 @abc.abstractmethod
41 def itermaps(self): 41 def itermaps(self, context):
42 """Yield each template mapping""" 42 """Yield each template mapping"""
43 43
44 @abc.abstractmethod 44 @abc.abstractmethod
45 def show(self, context, mapping): 45 def show(self, context, mapping):
46 """Return a bytes or (possibly nested) generator of bytes representing 46 """Return a bytes or (possibly nested) generator of bytes representing
86 """Default generator to stringify this as {join(self, ' ')}""" 86 """Default generator to stringify this as {join(self, ' ')}"""
87 for i, x in enumerate(self._values): 87 for i, x in enumerate(self._values):
88 if i > 0: 88 if i > 0:
89 yield ' ' 89 yield ' '
90 yield self.joinfmt(x) 90 yield self.joinfmt(x)
91 def itermaps(self): 91 def itermaps(self, context):
92 makemap = self._makemap 92 makemap = self._makemap
93 for x in self._values: 93 for x in self._values:
94 yield makemap(x) 94 yield makemap(x)
95 95
96 def show(self, context, mapping): 96 def show(self, context, mapping):
137 self._makemap = makemap 137 self._makemap = makemap
138 138
139 def tomap(self): 139 def tomap(self):
140 return self._makemap(self._key) 140 return self._makemap(self._key)
141 141
142 def itermaps(self): 142 def itermaps(self, context):
143 yield self.tomap() 143 yield self.tomap()
144 144
145 def show(self, context, mapping): 145 def show(self, context, mapping):
146 # TODO: switch gen to (context, mapping) API? 146 # TODO: switch gen to (context, mapping) API?
147 gen = self._gen 147 gen = self._gen
496 496
497 def runmap(context, mapping, data): 497 def runmap(context, mapping, data):
498 darg, targ = data 498 darg, targ = data
499 d = evalrawexp(context, mapping, darg) 499 d = evalrawexp(context, mapping, darg)
500 if isinstance(d, wrapped): 500 if isinstance(d, wrapped):
501 diter = d.itermaps() 501 diter = d.itermaps(context)
502 else: 502 else:
503 try: 503 try:
504 diter = iter(d) 504 diter = iter(d)
505 except TypeError: 505 except TypeError:
506 sym = findsymbolicname(darg) 506 sym = findsymbolicname(darg)