comparison mercurial/templater.py @ 34328:dd28b1f55eb8

templatekw: just pass underlying value (or key) to joinfmt() function Before, iter(hybrid) was proxied to hybrid.gen, which generated formatted strings. That's why we had to apply joinfmt() to the dicts generated by hybrid.itermaps(). Since this weird API was fixed at a0f2d83f8083, we can get rid of the makemap() calls from join().
author Yuya Nishihara <yuya@tcha.org>
date Sun, 24 Sep 2017 15:22:46 +0900
parents e60c601953d7
children 6367318327f0
comparison
equal deleted inserted replaced
34327:4647e0a8d3d7 34328:dd28b1f55eb8
766 raise error.ParseError(_("join expects one or two arguments")) 766 raise error.ParseError(_("join expects one or two arguments"))
767 767
768 # TODO: perhaps this should be evalfuncarg(), but it can't because hgweb 768 # TODO: perhaps this should be evalfuncarg(), but it can't because hgweb
769 # abuses generator as a keyword that returns a list of dicts. 769 # abuses generator as a keyword that returns a list of dicts.
770 joinset = evalrawexp(context, mapping, args[0]) 770 joinset = evalrawexp(context, mapping, args[0])
771 if util.safehasattr(joinset, 'itermaps'): 771 joinfmt = getattr(joinset, 'joinfmt', pycompat.identity)
772 jf = joinset.joinfmt
773 joinset = [jf(x) for x in joinset.itermaps()]
774
775 joiner = " " 772 joiner = " "
776 if len(args) > 1: 773 if len(args) > 1:
777 joiner = evalstring(context, mapping, args[1]) 774 joiner = evalstring(context, mapping, args[1])
778 775
779 first = True 776 first = True
780 for x in joinset: 777 for x in joinset:
781 if first: 778 if first:
782 first = False 779 first = False
783 else: 780 else:
784 yield joiner 781 yield joiner
785 yield x 782 yield joinfmt(x)
786 783
787 @templatefunc('label(label, expr)') 784 @templatefunc('label(label, expr)')
788 def label(context, mapping, args): 785 def label(context, mapping, args):
789 """Apply a label to generated content. Content with 786 """Apply a label to generated content. Content with
790 a label applied can result in additional post-processing, such as 787 a label applied can result in additional post-processing, such as