Mercurial > public > mercurial-scm > hg
comparison mercurial/templateutil.py @ 38266:80f423a14c90
templater: inline wraphybridvalue()
All wraphybridvalue() calls are now handled in the hybrid class.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Wed, 21 Mar 2018 12:06:18 +0900 |
parents | 41ae9b3cbfb9 |
children | fb874fc1d9b4 |
comparison
equal
deleted
inserted
replaced
38265:41ae9b3cbfb9 | 38266:80f423a14c90 |
---|---|
191 return self._wrapvalue(val, val) | 191 return self._wrapvalue(val, val) |
192 | 192 |
193 def _wrapvalue(self, key, val): | 193 def _wrapvalue(self, key, val): |
194 if val is None: | 194 if val is None: |
195 return | 195 return |
196 return wraphybridvalue(self, key, val) | 196 if util.safehasattr(val, '_makemap'): |
197 # a nested hybrid list/dict, which has its own way of map operation | |
198 return val | |
199 return mappable(None, key, val, self._makemap) | |
197 | 200 |
198 def itermaps(self, context): | 201 def itermaps(self, context): |
199 makemap = self._makemap | 202 makemap = self._makemap |
200 for x in self._values: | 203 for x in self._values: |
201 yield makemap(x) | 204 yield makemap(x) |
419 """Return an object which can be stringified possibly by using a legacy | 422 """Return an object which can be stringified possibly by using a legacy |
420 template""" | 423 template""" |
421 if not isinstance(thing, wrapped): | 424 if not isinstance(thing, wrapped): |
422 return thing | 425 return thing |
423 return thing.show(context, mapping) | 426 return thing.show(context, mapping) |
424 | |
425 def wraphybridvalue(container, key, value): | |
426 """Wrap an element of hybrid container to be mappable | |
427 | |
428 The key is passed to the makemap function of the given container, which | |
429 should be an item generated by iter(container). | |
430 """ | |
431 makemap = getattr(container, '_makemap', None) | |
432 if makemap is None: | |
433 return value | |
434 if util.safehasattr(value, '_makemap'): | |
435 # a nested hybrid list/dict, which has its own way of map operation | |
436 return value | |
437 return mappable(None, key, value, makemap) | |
438 | 427 |
439 def compatdict(context, mapping, name, data, key='key', value='value', | 428 def compatdict(context, mapping, name, data, key='key', value='value', |
440 fmt=None, plural=None, separator=' '): | 429 fmt=None, plural=None, separator=' '): |
441 """Wrap data like hybriddict(), but also supports old-style list template | 430 """Wrap data like hybriddict(), but also supports old-style list template |
442 | 431 |