##// END OF EJS Templates
templater: always map over a wrapped object...
Yuya Nishihara -
r38231:7701c2d4 default
parent child Browse files
Show More
@@ -643,20 +643,6 b' def _formatfiltererror(arg, filt):'
643 return (_("template filter '%s' is not compatible with keyword '%s'")
643 return (_("template filter '%s' is not compatible with keyword '%s'")
644 % (fn, sym))
644 % (fn, sym))
645
645
646 def _checkeditermaps(darg, d):
647 try:
648 for v in d:
649 if not isinstance(v, dict):
650 raise TypeError
651 yield v
652 except TypeError:
653 sym = findsymbolicname(darg)
654 if sym:
655 raise error.ParseError(_("keyword '%s' is not iterable of mappings")
656 % sym)
657 else:
658 raise error.ParseError(_("%r is not iterable of mappings") % d)
659
660 def _iteroverlaymaps(context, origmapping, newmappings):
646 def _iteroverlaymaps(context, origmapping, newmappings):
661 """Generate combined mappings from the original mapping and an iterable
647 """Generate combined mappings from the original mapping and an iterable
662 of partial mappings to override the original"""
648 of partial mappings to override the original"""
@@ -665,23 +651,14 b' def _iteroverlaymaps(context, origmappin'
665 lm['index'] = i
651 lm['index'] = i
666 yield lm
652 yield lm
667
653
668 def _applymap(context, mapping, diter, targ):
654 def _applymap(context, mapping, d, targ):
669 for lm in _iteroverlaymaps(context, mapping, diter):
655 for lm in _iteroverlaymaps(context, mapping, d.itermaps(context)):
670 yield evalrawexp(context, lm, targ)
656 yield evalrawexp(context, lm, targ)
671
657
672 def runmap(context, mapping, data):
658 def runmap(context, mapping, data):
673 darg, targ = data
659 darg, targ = data
674 d = evalrawexp(context, mapping, darg)
660 d = evalwrapped(context, mapping, darg)
675 # TODO: a generator should be rejected because it is a thunk of lazy
661 return mappedgenerator(_applymap, args=(mapping, d, targ))
676 # string, but we can't because hgweb abuses generator as a keyword
677 # that returns a list of dicts.
678 # TODO: drop _checkeditermaps() and pass 'd' to mappedgenerator so it
679 # can be restarted.
680 if isinstance(d, wrapped):
681 diter = d.itermaps(context)
682 else:
683 diter = _checkeditermaps(darg, d)
684 return mappedgenerator(_applymap, args=(mapping, diter, targ))
685
662
686 def runmember(context, mapping, data):
663 def runmember(context, mapping, data):
687 darg, memb = data
664 darg, memb = data
@@ -3212,7 +3212,7 b' Test new-style inline templating:'
3212
3212
3213
3213
3214 $ hg log -R latesttag -r tip -T '{rev % "a"}\n'
3214 $ hg log -R latesttag -r tip -T '{rev % "a"}\n'
3215 hg: parse error: keyword 'rev' is not iterable of mappings
3215 hg: parse error: 11 is not iterable of mappings
3216 [255]
3216 [255]
3217 $ hg log -R latesttag -r tip -T '{get(extras, "unknown") % "a"}\n'
3217 $ hg log -R latesttag -r tip -T '{get(extras, "unknown") % "a"}\n'
3218 hg: parse error: None is not iterable of mappings
3218 hg: parse error: None is not iterable of mappings
General Comments 0
You need to be logged in to leave comments. Login now