Skip to content
Myr

[svn] fixes in jinja i18n and finished macro calling

Before adoption: this commit came in with the history the project adopted, so no landing records it.

--HG-- branch : trunk

authored by Armin Ronacher · committed by Armin Ronacher · parent 80bfa43 · Browse files · 2 files+44 added−31 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+44 added−31 removed

  • other:+44 added−31 removed

2 files+44 added−31 removed

modified:jinja/translators/python.py+11 added-3 removed
373 unmodified lines
374 """375 Handle macro declarations.376 """377 buf = []378 write = lambda x: buf.append(self.indent(x))379380 args = []381 defaults = []382 for name, n in node.arguments:383 args.append('context[\'%s\']' % name)384 if n is None:382 args.append('%s=Undefined' % name)385 defaults.append('Undefined')386 else:384 args.append('%s=%s' % (name, self.handle_node(n)))385 buf.append(self.indent('def macro(%s):' % ', '.join(args)))387 defaults.append(self.handle_node(n))388389 write('def macro(*args):')390 self.indention += 1391 write('%s = (args + %s[len(args):])' % (_to_tuple(args), _to_tuple(defaults)))392 write('macrobuffer = []')393 write('write = macrobuffer.append')394 buf.append(self.handle_node(node.body))395 write('return u\'\'.join(macrobuffer)')396 self.indention -= 1397 buf.append(self.indent('context[%r] = macro' % node.name))398399 return '\n'.join(buf)
366 unmodified lines
modified:jinja/parser.py+33 added-28 removed
256 unmodified lines
257 # save the initial line number for the resulting node258 flineno = lineno259 try:260 # check for string translations261 try:262 lineno, token, data = gen.next()263 except StopIteration:264 # no dynamic replacements265 replacements = {}266 first_var = None261 lineno, token, data = gen.next()262 if token == 'string':263 # check that there are not any more elements264 try:265 gen.next()266 except StopIteration:267 #XXX: what about escapes?268 return nodes.Trans(lineno, data[1:-1], None, None, None)269 raise TemplateSyntaxError('string based translations '270 'require at most one argument.',271 lineno)267 else:268 if token == 'string':269 # check that there are not any more elements270 try:271 gen.next()272 except StopIteration:273 #XXX: what about escapes?274 return nodes.Trans(lineno, data[1:-1], None, None, None)275 raise TemplateSyntaxError('string based translations '276 'require at most one argument.',277 lineno)278 # create a new generator with the popped item as first one279 def wrapgen(oldgen):280 yield lineno, token, data281 for item in oldgen:282 yield item283 gen = wrapgen(gen)284273 # create a new generator with the popped item as first one274 def wrapgen(oldgen):275 yield lineno, token, data276 for item in oldgen:277 yield item278 gen = wrapgen(gen)285 # block based translations286 first_var = None287 replacements = {}288 for arg in self.parse_python(lineno, gen, '_trans(%s)').expr.args:289 if arg.__class__ is not ast.Keyword:290 raise TemplateSyntaxError('translation tags need explicit '291 'names for values.', lineno)292 if first_var is None:293 first_var = arg.name294 replacements[arg.name] = arg.expr295280 # block based translations281 first_var = None282 replacements = {}283 for arg in self.parse_python(lineno, gen, '_trans(%s)').expr.args:284 if arg.__class__ is not ast.Keyword:285 raise TemplateSyntaxError('translation tags need explicit '286 'names for values.', lineno)287 if first_var is None:288 first_var = arg.name289 replacements[arg.name] = arg.expr290296 # look for endtrans/pluralize297 buf = singular = []298 plural = indicator = None299
181 unmodified lines