##// END OF EJS Templates
templater: promote tomap() to an interface type...
Yuya Nishihara -
r38303:e7269789 default
parent child Browse files
Show More
@@ -91,6 +91,16 b' class wrapped(object):'
91 91 A returned value must be serializable by templaterfilters.json().
92 92 """
93 93
94 class mappable(object):
95 """Object which can be converted to a single template mapping"""
96
97 def itermaps(self, context):
98 yield self.tomap(context)
99
100 @abc.abstractmethod
101 def tomap(self, context):
102 """Create a single template mapping representing this"""
103
94 104 class wrappedbytes(wrapped):
95 105 """Wrapper for byte string"""
96 106
@@ -243,7 +253,7 b' class hybrid(wrapped):'
243 253 for k, v in xs.iteritems()}
244 254 return [unwrapvalue(context, mapping, x) for x in xs]
245 255
246 class hybriditem(wrapped):
256 class hybriditem(mappable, wrapped):
247 257 """Wrapper for non-list/dict object to support map operation
248 258
249 259 This class allows us to handle both:
@@ -258,7 +268,7 b' class hybriditem(wrapped):'
258 268 self._value = value # may be generator of strings
259 269 self._makemap = makemap
260 270
261 def tomap(self):
271 def tomap(self, context):
262 272 return self._makemap(self._key)
263 273
264 274 def contains(self, context, mapping, item):
@@ -277,9 +287,6 b' class hybriditem(wrapped):'
277 287 w = makewrapped(context, mapping, self._value)
278 288 return w.getmax(context, mapping)
279 289
280 def itermaps(self, context):
281 yield self.tomap()
282
283 290 def join(self, context, mapping, sep):
284 291 w = makewrapped(context, mapping, self._value)
285 292 return w.join(context, mapping, sep)
@@ -775,8 +782,8 b' def runmap(context, mapping, data):'
775 782 def runmember(context, mapping, data):
776 783 darg, memb = data
777 784 d = evalwrapped(context, mapping, darg)
778 if util.safehasattr(d, 'tomap'):
779 lm = context.overlaymap(mapping, d.tomap())
785 if isinstance(d, mappable):
786 lm = context.overlaymap(mapping, d.tomap(context))
780 787 return runsymbol(context, lm, memb)
781 788 try:
782 789 return d.getmember(context, mapping, memb)
General Comments 0
You need to be logged in to leave comments. Login now