mercurial/templatefuncs.py
changeset 37327 ebf139cbd4a1
parent 37325 41a5d815d2c1
child 37674 f83cb91b052e
equal deleted inserted replaced
37326:9cd88dd3bf64 37327:ebf139cbd4a1
   314     """Join items in a list with a delimiter."""
   314     """Join items in a list with a delimiter."""
   315     if not (1 <= len(args) <= 2):
   315     if not (1 <= len(args) <= 2):
   316         # i18n: "join" is a keyword
   316         # i18n: "join" is a keyword
   317         raise error.ParseError(_("join expects one or two arguments"))
   317         raise error.ParseError(_("join expects one or two arguments"))
   318 
   318 
   319     # TODO: perhaps this should be evalfuncarg(), but it can't because hgweb
       
   320     # abuses generator as a keyword that returns a list of dicts.
       
   321     joinset = evalrawexp(context, mapping, args[0])
   319     joinset = evalrawexp(context, mapping, args[0])
   322     joinset = templateutil.unwrapvalue(context, mapping, joinset)
       
   323     joinfmt = getattr(joinset, 'joinfmt', pycompat.identity)
       
   324     joiner = " "
   320     joiner = " "
   325     if len(args) > 1:
   321     if len(args) > 1:
   326         joiner = evalstring(context, mapping, args[1])
   322         joiner = evalstring(context, mapping, args[1])
   327     itemiter = (joinfmt(x) for x in pycompat.maybebytestr(joinset))
   323     if isinstance(joinset, templateutil.wrapped):
   328     return templateutil.joinitems(itemiter, joiner)
   324         return joinset.join(context, mapping, joiner)
       
   325     # TODO: perhaps a generator should be stringify()-ed here, but we can't
       
   326     # because hgweb abuses it as a keyword that returns a list of dicts.
       
   327     joinset = templateutil.unwrapvalue(context, mapping, joinset)
       
   328     return templateutil.joinitems(pycompat.maybebytestr(joinset), joiner)
   329 
   329 
   330 @templatefunc('label(label, expr)')
   330 @templatefunc('label(label, expr)')
   331 def label(context, mapping, args):
   331 def label(context, mapping, args):
   332     """Apply a label to generated content. Content with
   332     """Apply a label to generated content. Content with
   333     a label applied can result in additional post-processing, such as
   333     a label applied can result in additional post-processing, such as