##// END OF EJS Templates
templater: factor out function that evaluates argument as integer...
Yuya Nishihara -
r28343:a6c2310b default
parent child Browse files
Show More
@@ -220,6 +220,12 b' def evalfuncarg(context, mapping, arg):'
220 thing = stringify(thing)
220 thing = stringify(thing)
221 return thing
221 return thing
222
222
223 def evalinteger(context, mapping, arg, err):
224 try:
225 return int(stringify(arg[0](context, mapping, arg[1])))
226 except ValueError:
227 raise error.ParseError(err)
228
223 def runinteger(context, mapping, data):
229 def runinteger(context, mapping, data):
224 return int(data)
230 return int(data)
225
231
@@ -373,11 +379,9 b' def fill(context, mapping, args):'
373 initindent = ''
379 initindent = ''
374 hangindent = ''
380 hangindent = ''
375 if 2 <= len(args) <= 4:
381 if 2 <= len(args) <= 4:
376 try:
382 width = evalinteger(context, mapping, args[1],
377 width = int(stringify(args[1][0](context, mapping, args[1][1])))
383 # i18n: "fill" is a keyword
378 except ValueError:
384 _("fill expects an integer width"))
379 # i18n: "fill" is a keyword
380 raise error.ParseError(_("fill expects an integer width"))
381 try:
385 try:
382 initindent = stringify(args[2][0](context, mapping, args[2][1]))
386 initindent = stringify(args[2][0](context, mapping, args[2][1]))
383 hangindent = stringify(args[3][0](context, mapping, args[3][1]))
387 hangindent = stringify(args[3][0](context, mapping, args[3][1]))
@@ -710,11 +714,9 b' def word(context, mapping, args):'
710 raise error.ParseError(_("word expects two or three arguments, got %d")
714 raise error.ParseError(_("word expects two or three arguments, got %d")
711 % len(args))
715 % len(args))
712
716
713 try:
717 num = evalinteger(context, mapping, args[0],
714 num = int(stringify(args[0][0](context, mapping, args[0][1])))
718 # i18n: "word" is a keyword
715 except ValueError:
719 _("word expects an integer index"))
716 # i18n: "word" is a keyword
717 raise error.ParseError(_("word expects an integer index"))
718 text = stringify(args[1][0](context, mapping, args[1][1]))
720 text = stringify(args[1][0](context, mapping, args[1][1]))
719 if len(args) == 3:
721 if len(args) == 3:
720 splitter = stringify(args[2][0](context, mapping, args[2][1]))
722 splitter = stringify(args[2][0](context, mapping, args[2][1]))
General Comments 0
You need to be logged in to leave comments. Login now