Mercurial > public > mercurial-scm > hg-stable
diff mercurial/templatefuncs.py @ 37327:ebf139cbd4a1
templater: abstract away from joinfmt
Future patches will add a wrapper for a list of template mappings, which
will implement a custom join() something like {join(mappings % template)}.
The original join() function is broken down as follows:
if hasattr(joinset, 'joinfmt'):
# hybrid.join() where values must be a list or a dict
joinitems((joinfmt(x) for x in values), sep)
elif isinstance(joinset, templateutil.wrapped):
# mappable.join()
show()
else:
# a plain list, a generator, or a byte string; joinfmt was identity()
joinset = templateutil.unwrapvalue(context, joinset)
joinitems(pycompat.maybebytestr(joinset), joiner)
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 17 Mar 2018 22:06:31 +0900 |
parents | 41a5d815d2c1 |
children | f83cb91b052e |
line wrap: on
line diff
--- a/mercurial/templatefuncs.py Tue Mar 20 23:16:28 2018 +0900 +++ b/mercurial/templatefuncs.py Sat Mar 17 22:06:31 2018 +0900 @@ -316,16 +316,16 @@ # i18n: "join" is a keyword raise error.ParseError(_("join expects one or two arguments")) - # TODO: perhaps this should be evalfuncarg(), but it can't because hgweb - # abuses generator as a keyword that returns a list of dicts. joinset = evalrawexp(context, mapping, args[0]) - joinset = templateutil.unwrapvalue(context, mapping, joinset) - joinfmt = getattr(joinset, 'joinfmt', pycompat.identity) joiner = " " if len(args) > 1: joiner = evalstring(context, mapping, args[1]) - itemiter = (joinfmt(x) for x in pycompat.maybebytestr(joinset)) - return templateutil.joinitems(itemiter, joiner) + if isinstance(joinset, templateutil.wrapped): + return joinset.join(context, mapping, joiner) + # TODO: perhaps a generator should be stringify()-ed here, but we can't + # because hgweb abuses it as a keyword that returns a list of dicts. + joinset = templateutil.unwrapvalue(context, mapping, joinset) + return templateutil.joinitems(pycompat.maybebytestr(joinset), joiner) @templatefunc('label(label, expr)') def label(context, mapping, args):