# HG changeset patch # User Sean Farley # Date 1365638198 18000 # Node ID 8eef5b93db9d2d4f89463a5d5740ce71694e8284 # Parent c58b6ab4c26fcf673ad706bf0f42685a8dfcd72d templater: move templatefilters.func into the same place as the other funcs diff -r c58b6ab4c26f -r 8eef5b93db9d mercurial/templatefilters.py --- a/mercurial/templatefilters.py Wed May 22 17:31:43 2013 -0500 +++ b/mercurial/templatefilters.py Wed Apr 10 18:56:38 2013 -0500 @@ -5,9 +5,8 @@ # This software may be used and distributed according to the terms of the # GNU General Public License version 2 or any later version. -from i18n import _ import cgi, re, os, time, urllib -import encoding, node, util, error +import encoding, node, util import hbisect def addbreaks(text): @@ -401,34 +400,5 @@ text = regexp.sub(format, text) return text -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) - -def datefunc(context, mapping, args): - if not (1 <= len(args) <= 2): - raise error.ParseError(_("date expects one or two arguments")) - - date = args[0][0](context, mapping, args[0][1]) - if len(args) == 2: - fmt = stringify(args[1][0](context, mapping, args[1][1])) - return util.datestr(date, fmt) - return util.datestr(date) - -funcs = { - "fill": fillfunc, - "date": datefunc, -} - # tell hggettext to extract docstrings from these functions: i18nfunctions = filters.values() diff -r c58b6ab4c26f -r 8eef5b93db9d mercurial/templater.py --- a/mercurial/templater.py Wed May 22 17:31:43 2013 -0500 +++ b/mercurial/templater.py Wed Apr 10 18:56:38 2013 -0500 @@ -199,9 +199,6 @@ if n in funcs: f = funcs[n] return (f, args) - if n in templatefilters.funcs: - f = templatefilters.funcs[n] - return (f, args) if n in context._filters: if len(args) != 1: raise error.ParseError(_("filter %s expects one argument") % n) @@ -301,6 +298,30 @@ return minirst.format(text, style=style, keep=['verbose']) +def fill(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 templatefilters.fill(text, width) + +def date(context, mapping, args): + if not (1 <= len(args) <= 2): + raise error.ParseError(_("date expects one or two arguments")) + + date = args[0][0](context, mapping, args[0][1]) + if len(args) == 2: + fmt = stringify(args[1][0](context, mapping, args[1][1])) + return util.datestr(date, fmt) + return util.datestr(date) + methods = { "string": lambda e, c: (runstring, e[1]), "symbol": lambda e, c: (runsymbol, e[1]), @@ -319,6 +340,8 @@ "label": label, "rstdoc": rstdoc, "sub": sub, + "fill": fill, + "date": date, } # template engine