comparison mercurial/templatefuncs.py @ 37325:41a5d815d2c1

templater: factor out generator of join()-ed items Prepares for defining join() behavior per wrapped types and getting rid of the public joinfmt attribute.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 17 Mar 2018 21:42:27 +0900
parents 9e8128e84326
children ebf139cbd4a1
comparison
equal deleted inserted replaced
37324:c2f74b8f6b7f 37325:41a5d815d2c1
322 joinset = templateutil.unwrapvalue(context, mapping, joinset) 322 joinset = templateutil.unwrapvalue(context, mapping, joinset)
323 joinfmt = getattr(joinset, 'joinfmt', pycompat.identity) 323 joinfmt = getattr(joinset, 'joinfmt', pycompat.identity)
324 joiner = " " 324 joiner = " "
325 if len(args) > 1: 325 if len(args) > 1:
326 joiner = evalstring(context, mapping, args[1]) 326 joiner = evalstring(context, mapping, args[1])
327 327 itemiter = (joinfmt(x) for x in pycompat.maybebytestr(joinset))
328 first = True 328 return templateutil.joinitems(itemiter, joiner)
329 for x in pycompat.maybebytestr(joinset):
330 if first:
331 first = False
332 else:
333 yield joiner
334 yield joinfmt(x)
335 329
336 @templatefunc('label(label, expr)') 330 @templatefunc('label(label, expr)')
337 def label(context, mapping, args): 331 def label(context, mapping, args):
338 """Apply a label to generated content. Content with 332 """Apply a label to generated content. Content with
339 a label applied can result in additional post-processing, such as 333 a label applied can result in additional post-processing, such as