Mercurial > public > mercurial-scm > hg-stable
diff mercurial/templater.py @ 19227:8eef5b93db9d
templater: move templatefilters.func into the same place as the other funcs
author | Sean Farley <sean.michael.farley@gmail.com> |
---|---|
date | Wed, 10 Apr 2013 18:56:38 -0500 |
parents | d982edcfe7f0 |
children | 889807c79384 |
line wrap: on
line diff
--- 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