Mercurial > hg-stable
changeset 17638:e2711975be00
templatefilters: add parameterized fill function
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Mon, 24 Sep 2012 15:54:44 -0500 |
parents | 02d2166ef5f1 |
children | d42cc3c880b6 |
files | mercurial/templatefilters.py |
diffstat | 1 files changed, 20 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/templatefilters.py Mon Sep 24 15:28:04 2012 -0500 +++ b/mercurial/templatefilters.py Mon Sep 24 15:54:44 2012 -0500 @@ -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 @@ "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()