comparison 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
comparison
equal deleted inserted replaced
19226:c58b6ab4c26f 19227:8eef5b93db9d
197 n = getsymbol(exp[1]) 197 n = getsymbol(exp[1])
198 args = [compileexp(x, context) for x in getlist(exp[2])] 198 args = [compileexp(x, context) for x in getlist(exp[2])]
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)
208 f = context._filters[n] 205 f = context._filters[n]
209 return (runfilter, (args[0][0], args[0][1], f)) 206 return (runfilter, (args[0][0], args[0][1], f))
298 295
299 text = stringify(args[0][0](context, mapping, args[0][1])) 296 text = stringify(args[0][0](context, mapping, args[0][1]))
300 style = stringify(args[1][0](context, mapping, args[1][1])) 297 style = stringify(args[1][0](context, mapping, args[1][1]))
301 298
302 return minirst.format(text, style=style, keep=['verbose']) 299 return minirst.format(text, style=style, keep=['verbose'])
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)
303 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]),
307 "group": lambda e, c: compileexp(e[1], c), 328 "group": lambda e, c: compileexp(e[1], c),
317 "ifeq": ifeq, 338 "ifeq": ifeq,
318 "join": join, 339 "join": join,
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
325 348
326 path = ['templates', '../templates'] 349 path = ['templates', '../templates']