[Twisted-web] How to insert an Athena event handler using Stan?
exarkun at divmod.com
Tue Oct 31 09:25:31 CST 2006
On Tue, 31 Oct 2006 16:38:22 +0200, kgi <iacovou at gmail.com> wrote:
>On Tuesday 31 October 2006 15:12, Tristan Seligmann wrote:
>> * kgi <iacovou at gmail.com> [2006-10-31 11:58:35 +0200]:
>> > However, if one has stan-based rather than file-based XHTML, it's neither
>> > documented nor obvious how this should be done. I've managed to get this
>> > far:
>> > from nevow import stan
>> > ...
>> > _athena = stan.Proto (
>> > 'athena:handler event="onkeypress" handler="keyPressed"'
>> > )
>> > ...
>> > T.input ( type = "text", _class = "sw-input" ) [ _athena ]
>> stan.Proto takes a tag name, so you would really want
>> just stan.Proto('athena:handler'). However, there's already one of these
>> in athena, so you can just do:
>> from nevow import stan, athena
>> # ...
>> T.input(type='text', _class='sw-input')[
>> athena.handler(event='onkeypress', handler='keypressed']
>Thanks, Tristan; that's certainly a step forward: the tag is now being
>recognised and replaced. However, it's not quite perfect yet: the generated
>HTML is escaped:
> _handler = athena.handler ( event = 'onkeypress', handler = 'keyPressed' )
> T.input ( _class = "sw-input", type = "text" ) [ _handler ],
><input type="text" class="sw-input" onkeypress="return
>Should I be wrapping it in anything else (T.raw()?).
Are you sure this is causing a problem? It looks correct to me. :)
<tag onkeypress="return foo("bar")"> would seriously confuse an html parser.
More information about the Twisted-web