Hi,

I'm trying to learn how to write a Jinja2 extension. I managed to write it 
but basically it intents to write a <div>Hello</div> with this code:

class BaseExtension(Extension):
>   
>     def parse(self, parser):
>         stream = parser.stream
>         tag = stream.next()
>         # get arguments
>         args = []
>         kwargs = []
>         while not stream.current.test_any('block_end'):
>             if args or kwargs:
>                 stream.expect('comma')
>             if stream.current.test('name') and 
> stream.look().test('assign'):
>                 key = nodes.Const(stream.next().value)
>                 stream.skip()
>                 value = parser.parse_expression()
>                 kwargs.append(nodes.Pair(key, value, lineno=key.lineno))
>             else:
>                 args.append(parser.parse_expression())
>
>         def make_call_node(*kw):
>             return self.call_method('_call', args=[
>                 nodes.List(args),
>                 nodes.Dict(kwargs),
>             ], kwargs=kw)
>
>         return nodes.Output([make_call_node()]).set_lineno(tag.lineno)
>         #eturn nodes.CallBlock([make_call_node()]).set_lineno(tag.lineno)
>
> class SnippetExtension(BaseExtension):
>     
>     tags = set(['snippet'])
>
>     @classmethod
>     def _call(cls, args, kwargs):
>         assert len(args) == 1
>         *return '<div>Hello</div>'*
>

The extension work ok but in the template I get:

&lt;div&gt;Carlos&lt;/div&gt;
>


Any idea what I am doing wrong?

Thanks.



-- 
You received this message because you are subscribed to the Google Groups 
"pocoo-libs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pocoo-libs.
For more options, visit https://groups.google.com/d/optout.

Reply via email to