Show More
@@ -91,6 +91,16 b' class wrapped(object):' | |||||
91 | A returned value must be serializable by templaterfilters.json(). |
|
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 | class wrappedbytes(wrapped): |
|
104 | class wrappedbytes(wrapped): | |
95 | """Wrapper for byte string""" |
|
105 | """Wrapper for byte string""" | |
96 |
|
106 | |||
@@ -243,7 +253,7 b' class hybrid(wrapped):' | |||||
243 | for k, v in xs.iteritems()} |
|
253 | for k, v in xs.iteritems()} | |
244 | return [unwrapvalue(context, mapping, x) for x in xs] |
|
254 | return [unwrapvalue(context, mapping, x) for x in xs] | |
245 |
|
255 | |||
246 | class hybriditem(wrapped): |
|
256 | class hybriditem(mappable, wrapped): | |
247 | """Wrapper for non-list/dict object to support map operation |
|
257 | """Wrapper for non-list/dict object to support map operation | |
248 |
|
258 | |||
249 | This class allows us to handle both: |
|
259 | This class allows us to handle both: | |
@@ -258,7 +268,7 b' class hybriditem(wrapped):' | |||||
258 | self._value = value # may be generator of strings |
|
268 | self._value = value # may be generator of strings | |
259 | self._makemap = makemap |
|
269 | self._makemap = makemap | |
260 |
|
270 | |||
261 | def tomap(self): |
|
271 | def tomap(self, context): | |
262 | return self._makemap(self._key) |
|
272 | return self._makemap(self._key) | |
263 |
|
273 | |||
264 | def contains(self, context, mapping, item): |
|
274 | def contains(self, context, mapping, item): | |
@@ -277,9 +287,6 b' class hybriditem(wrapped):' | |||||
277 | w = makewrapped(context, mapping, self._value) |
|
287 | w = makewrapped(context, mapping, self._value) | |
278 | return w.getmax(context, mapping) |
|
288 | return w.getmax(context, mapping) | |
279 |
|
289 | |||
280 | def itermaps(self, context): |
|
|||
281 | yield self.tomap() |
|
|||
282 |
|
||||
283 | def join(self, context, mapping, sep): |
|
290 | def join(self, context, mapping, sep): | |
284 | w = makewrapped(context, mapping, self._value) |
|
291 | w = makewrapped(context, mapping, self._value) | |
285 | return w.join(context, mapping, sep) |
|
292 | return w.join(context, mapping, sep) | |
@@ -775,8 +782,8 b' def runmap(context, mapping, data):' | |||||
775 | def runmember(context, mapping, data): |
|
782 | def runmember(context, mapping, data): | |
776 | darg, memb = data |
|
783 | darg, memb = data | |
777 | d = evalwrapped(context, mapping, darg) |
|
784 | d = evalwrapped(context, mapping, darg) | |
778 | if util.safehasattr(d, 'tomap'): |
|
785 | if isinstance(d, mappable): | |
779 | lm = context.overlaymap(mapping, d.tomap()) |
|
786 | lm = context.overlaymap(mapping, d.tomap(context)) | |
780 | return runsymbol(context, lm, memb) |
|
787 | return runsymbol(context, lm, memb) | |
781 | try: |
|
788 | try: | |
782 | return d.getmember(context, mapping, memb) |
|
789 | return d.getmember(context, mapping, memb) |
General Comments 0
You need to be logged in to leave comments.
Login now