[PATCH 1 of 2] templater: move templatefilters.func into the same place as the other funcs

Wagner Bruna wagner.bruna+mercurial at gmail.com
Mon May 20 17:37:11 CDT 2013


Em 20-05-2013 18:45, Sean Farley escreveu:
> # HG changeset patch
> # User Sean Farley <sean.michael.farley at gmail.com>
> # Date 1365638198 18000
> #      Wed Apr 10 18:56:38 2013 -0500
> # Node ID 4edf5b7dddd1a3ab5350590256f5145b54ea1e30
> # Parent  0ec31231afad3fc171f882226aae50d4737559b5
> templater: move templatefilters.func into the same place as the other funcs
> 
> diff --git a/mercurial/templatefilters.py b/mercurial/templatefilters.py
> --- a/mercurial/templatefilters.py
> +++ b/mercurial/templatefilters.py
> @@ -3,13 +3,12 @@
>  # Copyright 2005-2008 Matt Mackall <mpm at selenic.com>
>  #
>  # 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

The module still needs those, for error reporting (which suggests it also
needs a few (doc)tests).

Regards,
Wagner

>  import hbisect
>  
>  def addbreaks(text):
>      """:addbreaks: Any text. Add an XHTML "<br />" tag before the end of
>      every line except the last.
> @@ -399,36 +398,7 @@
>      if websubtable:
>          for regexp, format in websubtable:
>              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 --git a/mercurial/templater.py b/mercurial/templater.py
> --- a/mercurial/templater.py
> +++ b/mercurial/templater.py
> @@ -197,13 +197,10 @@
>      n = getsymbol(exp[1])
>      args = [compileexp(x, context) for x in getlist(exp[2])]
>      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)
>          f = context._filters[n]
>          return (runfilter, (args[0][0], args[0][1], f))
> @@ -299,10 +296,34 @@
>      text = stringify(args[0][0](context, mapping, args[0][1]))
>      style = stringify(args[1][0](context, mapping, args[1][1]))
>  
>      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]),
>      "group": lambda e, c: compileexp(e[1], c),
>  #    ".": buildmember,
> @@ -317,10 +338,12 @@
>      "ifeq": ifeq,
>      "join": join,
>      "label": label,
>      "rstdoc": rstdoc,
>      "sub": sub,
> +    "fill": fill,
> +    "date": date,
>  }
>  
>  # template engine
>  
>  path = ['templates', '../templates']


More information about the Mercurial-devel mailing list