Mercurial > hg
changeset 31924:21f129354dd0
templatekw: add public function to wrap a list by _hybrid object
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Wed, 05 Apr 2017 22:25:36 +0900 |
parents | 68c910fa9ee2 |
children | 5b2241e84982 |
files | mercurial/formatter.py mercurial/templatekw.py |
diffstat | 2 files changed, 6 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/formatter.py Wed Apr 12 21:10:47 2017 +0900 +++ b/mercurial/formatter.py Wed Apr 05 22:25:36 2017 +0900 @@ -329,8 +329,7 @@ data = list(data) def f(): yield _plainconverter.formatlist(data, name, fmt, sep) - return templatekw._hybrid(f(), data, lambda x: {name: x}, - lambda d: fmt % d[name]) + return templatekw.hybridlist(data, name=name, fmt=fmt, gen=f()) class templateformatter(baseformatter): def __init__(self, ui, out, topic, opts):
--- a/mercurial/templatekw.py Wed Apr 12 21:10:47 2017 +0900 +++ b/mercurial/templatekw.py Wed Apr 05 22:25:36 2017 +0900 @@ -62,6 +62,10 @@ raise AttributeError(name) return getattr(self._values, name) +def hybridlist(data, name, fmt='%s', gen=None): + """Wrap data to support both list-like and string-like operations""" + return _hybrid(gen, data, lambda x: {name: x}, lambda d: fmt % d[name]) + def unwraphybrid(thing): """Return an object which can be stringified possibly by using a legacy template""" @@ -73,7 +77,7 @@ if not element: element = name f = _showlist(name, values, plural, separator, **args) - return _hybrid(f, values, lambda x: {element: x}, lambda d: d[element]) + return hybridlist(values, name=element, gen=f) def _showlist(name, values, plural=None, separator=' ', **args): '''expand set of values.