# HG changeset patch # User Matt Mackall # Date 2012-09-24 20:54:44 # Node ID e2711975be00710517f0d41635140015300b3ebb # Parent 02d2166ef5f1aea1e6ed6a4ee60cd00200038f9a templatefilters: add parameterized fill function diff --git a/mercurial/templatefilters.py b/mercurial/templatefilters.py --- a/mercurial/templatefilters.py +++ b/mercurial/templatefilters.py @@ -6,7 +6,7 @@ # GNU General Public License version 2 or any later version. import cgi, re, os, time, urllib -import encoding, node, util +import encoding, node, util, error import hbisect def addbreaks(text): @@ -391,5 +391,24 @@ filters = { "xmlescape": xmlescape, } +def fillfunc(context, mapping, args): + if not (1 <= len(args) <= 2): + raise error.ParseError(_("fill expects one or two arguments")) + + text = stringify(args[0][0](context, mapping, args[0][1])) + width = 76 + if len(args) == 2: + try: + width = int(stringify(args[1][0](context, mapping, args[1][1]))) + except ValueError: + raise error.ParseError(_("fill expects an integer width")) + + return fill(text, width) + + +funcs = { + "fill": fillfunc, +} + # tell hggettext to extract docstrings from these functions: i18nfunctions = filters.values()