# HG changeset patch # User Matt Mackall # Date 1348337076 18000 # Node ID 312184f930b7fecceb6d7b90314a7e52eb0692be # Parent 523625e46760ed73181a9ad6bab50a9564d0e599 template: add join function This allows: {join(files % "{files}", ", ") }\n to produce a properly comma-separated list diff -r 523625e46760 -r 312184f930b7 mercurial/templater.py --- a/mercurial/templater.py Sat Sep 22 13:02:33 2012 -0500 +++ b/mercurial/templater.py Sat Sep 22 13:04:36 2012 -0500 @@ -195,6 +195,26 @@ f = context._filters[n] return (runfilter, (args[0][0], args[0][1], f)) +def join(context, mapping, args): + if not (1 <= len(args) <= 2): + raise error.ParseError(_("join expects one or two arguments")) + + joinset = args[0][0](context, mapping, args[0][1]) + if util.safehasattr(joinset, '__call__'): + joinset = [x.values()[0] for x in joinset()] + + joiner = " " + if len(args) > 1: + joiner = args[1][0](context, mapping, args[1][1]) + + first = True + for x in joinset: + if first: + first = False + else: + yield joiner + yield x + methods = { "string": lambda e, c: (runstring, e[1]), "symbol": lambda e, c: (runsymbol, e[1]), @@ -206,6 +226,7 @@ } funcs = { + "join": join, } # template engine