##// END OF EJS Templates
templater: move templatefilters.func into the same place as the other funcs
Sean Farley -
r19227:8eef5b93 default
parent child Browse files
Show More
@@ -5,9 +5,8 b''
5 # This software may be used and distributed according to the terms of the
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version.
6 # GNU General Public License version 2 or any later version.
7
7
8 from i18n import _
9 import cgi, re, os, time, urllib
8 import cgi, re, os, time, urllib
10 import encoding, node, util, error
9 import encoding, node, util
11 import hbisect
10 import hbisect
12
11
13 def addbreaks(text):
12 def addbreaks(text):
@@ -401,34 +400,5 b' def websub(text, websubtable):'
401 text = regexp.sub(format, text)
400 text = regexp.sub(format, text)
402 return text
401 return text
403
402
404 def fillfunc(context, mapping, args):
405 if not (1 <= len(args) <= 2):
406 raise error.ParseError(_("fill expects one or two arguments"))
407
408 text = stringify(args[0][0](context, mapping, args[0][1]))
409 width = 76
410 if len(args) == 2:
411 try:
412 width = int(stringify(args[1][0](context, mapping, args[1][1])))
413 except ValueError:
414 raise error.ParseError(_("fill expects an integer width"))
415
416 return fill(text, width)
417
418 def datefunc(context, mapping, args):
419 if not (1 <= len(args) <= 2):
420 raise error.ParseError(_("date expects one or two arguments"))
421
422 date = args[0][0](context, mapping, args[0][1])
423 if len(args) == 2:
424 fmt = stringify(args[1][0](context, mapping, args[1][1]))
425 return util.datestr(date, fmt)
426 return util.datestr(date)
427
428 funcs = {
429 "fill": fillfunc,
430 "date": datefunc,
431 }
432
433 # tell hggettext to extract docstrings from these functions:
403 # tell hggettext to extract docstrings from these functions:
434 i18nfunctions = filters.values()
404 i18nfunctions = filters.values()
@@ -199,9 +199,6 b' def buildfunc(exp, context):'
199 if n in funcs:
199 if n in funcs:
200 f = funcs[n]
200 f = funcs[n]
201 return (f, args)
201 return (f, args)
202 if n in templatefilters.funcs:
203 f = templatefilters.funcs[n]
204 return (f, args)
205 if n in context._filters:
202 if n in context._filters:
206 if len(args) != 1:
203 if len(args) != 1:
207 raise error.ParseError(_("filter %s expects one argument") % n)
204 raise error.ParseError(_("filter %s expects one argument") % n)
@@ -301,6 +298,30 b' def rstdoc(context, mapping, args):'
301
298
302 return minirst.format(text, style=style, keep=['verbose'])
299 return minirst.format(text, style=style, keep=['verbose'])
303
300
301 def fill(context, mapping, args):
302 if not (1 <= len(args) <= 2):
303 raise error.ParseError(_("fill expects one or two arguments"))
304
305 text = stringify(args[0][0](context, mapping, args[0][1]))
306 width = 76
307 if len(args) == 2:
308 try:
309 width = int(stringify(args[1][0](context, mapping, args[1][1])))
310 except ValueError:
311 raise error.ParseError(_("fill expects an integer width"))
312
313 return templatefilters.fill(text, width)
314
315 def date(context, mapping, args):
316 if not (1 <= len(args) <= 2):
317 raise error.ParseError(_("date expects one or two arguments"))
318
319 date = args[0][0](context, mapping, args[0][1])
320 if len(args) == 2:
321 fmt = stringify(args[1][0](context, mapping, args[1][1]))
322 return util.datestr(date, fmt)
323 return util.datestr(date)
324
304 methods = {
325 methods = {
305 "string": lambda e, c: (runstring, e[1]),
326 "string": lambda e, c: (runstring, e[1]),
306 "symbol": lambda e, c: (runsymbol, e[1]),
327 "symbol": lambda e, c: (runsymbol, e[1]),
@@ -319,6 +340,8 b' funcs = {'
319 "label": label,
340 "label": label,
320 "rstdoc": rstdoc,
341 "rstdoc": rstdoc,
321 "sub": sub,
342 "sub": sub,
343 "fill": fill,
344 "date": date,
322 }
345 }
323
346
324 # template engine
347 # template engine
General Comments 0
You need to be logged in to leave comments. Login now