[PATCH v3] templater: add separate() template function
Yuya Nishihara
yuya at tcha.org
Thu May 5 22:43:26 EDT 2016
On Thu, 05 May 2016 13:52:26 -0700, Martin von Zweigbergk via Mercurial-devel wrote:
> # HG changeset patch
> # User Martin von Zweigbergk <martinvonz at google.com>
> # Date 1462294194 25200
> # Tue May 03 09:49:54 2016 -0700
> # Node ID 9a9fd3c8c8434c52e642cb5f32d423e09800e607
> # Parent 8eba4cdcfd810d80785c94d770a442c5bd1f9d0f
> templater: add separate() template function
Looks good and simple as a start. I'll push to the committed repo, thanks.
> + at templatefunc('separate(sep, args)')
> +def separate(context, mapping, args):
> + """Add a separator between non-empty arguments."""
> + if not args:
> + # i18n: "separate" is a keyword
> + raise error.ParseError(_("separate expects at least one argument"))
> +
> + sep = evalstring(context, mapping, args[0])
> + first = True
> + for arg in args[1:]:
> + argstr = evalstring(context, mapping, arg)
> + if not argstr:
> + continue
> + if first:
> + first = False
> + else:
> + yield sep
> + yield argstr
> +
> @templatefunc('label(label, expr)')
Moved the definition next to rstdoc().
More information about the Mercurial-devel
mailing list