[Twisted-web] Adding athena.LiveElement to an already-rendered
LivePage
Michał Pasternak
michal.dtz at gmail.com
Mon Nov 10 10:22:21 EST 2008
Jean-Paul Calderone pisze:
> On Sun, 09 Nov 2008 21:09:41 +0100, Michał Pasternak
> <michal.dtz at gmail.com> wrote:
>> Jean-Paul Calderone pisze:
>>> On Sun, 09 Nov 2008 13:28:26 +0100, Michał Pasternak
>>> <michal.dtz at gmail.com> wrote:
>>>> Hi,
>>>>
>>>> I want to be able to add athena.LiveElement to an already rendered
>>>> LivePage. Quick Googling revealed this blog entry:
>>>>
>>>>
>>>> http://techblog.ironfroggy.com/2006/01/nevow-post-render-injection-
>>>> of.html
>>>>
>>>> I'd like to know, if there are any other, simpler ways to do that -
>>>> or, maybe, is there a preferred method to do that in the API already?
>>>
>>> See Nevow.Athena.Widget.addChildWidgetFromWidgetInfo.
>> This method will not add the markup automatically. Am I right?
>>
>> I want to append incoming LiveFragments to the page.
>>
>> Right now, I am doing something like this on the client:
>>
>> // import Divmod.Runtime
>>
>> What.Ever = Nevow.Athena.Widget.subclass('What.Ever');
>> What.Ever.methods =(
>>
>> function foo(self) {
>> d = self.callRemote('getLiveFragment');
>>
>> d.addCallback(
>>
>> function liveFragmentReceived(lf) {
>>
>> d2 = self.addChildWidgetFromWidgetInfo(lf);
>>
>> d2.addCallback(
>>
>> function added(res) {
>>
>> d = Divmod.Runtime.theRuntime.parseXHTMLString(
>> lf.markup).documentElement;
>>
>> self.nodeById('lastNode').appendChild(d);
>>
>> });
>>
>> });
>
> You don't have to parse the markup. It's already parsed. The DOM
> element which results is the `node´ attribute of the Widget instance
> (which you get as `res´ - the result of the callback). You shouldn't
> use any attributes of `lf´, since it is an opaque handle: there is no
> API stability guarantee about it. The *only* thing you can do with it
> is pass it to `addChildWidgetFromWidgetInfo´.
Yes sir!
To whom it may concern: I've created a short how-to page:
http://divmod.org/trac/wiki/DivmodNevow/Athena/Tutorials/LiveElementsOnFly
--
m
More information about the Twisted-web
mailing list