[Twisted-web] Slot/pattern/key changes
Matt Goodall
twisted-web@twistedmatrix.com
Wed, 11 Feb 2004 09:32:40 +0000
On Tue, 2004-02-10 at 22:58, Matt Goodall wrote:
> On Tue, 2004-02-10 at 21:30, James Y Knight wrote:
> > This is a set of *BACKWARDS-INCOMPATIBLE* changes that simplifies and
> > clarifies the set of attributes nevow has for finding elements. Tests
> > pass, and my app works (both after being updated slightly for the API
> > changes).
> >
> > There used to be 3 attributes you could put on elements to locate them:
> > slot, pattern, and key. They all did similar but slightly different
> > things.
> >
> > - Filling slots with data is a useful concept but 'slot' shouldn' t be
> > an attribute. A slot is something that gets replaced with the given
> > data, and is thus better as a standalone element. It has been replaced
> > with the following:
> > slot('slotname') in a stan tree, or <nevow:slot name="slotname" /> in
> > an (X)HTML template.
> > context.slotted() (which could locate a slot) has been eliminated and
> > replaced with context.fillSlots(slotname, stantree). Note that you
> > cannot locate slots, you can just specify data for them to fill
> > themselves with.
> >
> > - Assigning unique keys is also a useful concept, but it doesn't
> > require the "context.keyed()" method. That method has been eliminated.
> > HTMLRenderer used it to find the key="content" in HTML files used as
> > sub-renderers, now it uses pattern="content".
> >
> > - Patterns remain as the only way to locate a sub-element of your
> > renderer. There are now 3 methods to locate them, depending on what you
> > want to do. patternGenerator() replaces patterns(), onePattern()
> > semi-replaces keyed(), and allPatterns() replaces the direct use of
> > specialMatches that the sequence renderer previous did. Please see the
> > docs in context.py for these three methods for precise behavior.
> >
> > So, in summary, to convert your old code to new code:
> > 1) If you had "div(style="border:1px", slot="myslot")" replace it with
> > div(style="border: 1px")[slot("myslot")].
> > 2) If you had a template with "<div style="border:1px"
> > nevow:slot="myslot" />" replace it with "<div
> > style="border:1px"><nevow:slot name="myslot" /></div>
> > 3) If you had "context.slotted("myslot").clear()[a(href="foo")["bar"]]
> > replace it with context.fillSlot("myslot", a(href="foo")["bar"]]
> > 4) If you used keyed(), convert key= to pattern= and keyed() to
> > onePattern().
> > 5) If you used patterns(), just rename it to patternGenerator()
>
> I have one more use case that is not possible/easy with the proposed
> change:
>
> HTML:
> <a nevow:slot="email" class="whatever" href="email:">email</a>
>
> Rendered by:
> context.slotted('email')(href=['mailto:','a@bc.com'])['Mr X']
>
> Result:
> <a class="whatever" href="email:a@bc.com">Mr X</a>
It looks like this should be possible using something like this:
HTML:
<nevow:slot name="email"/><a pattern="email" href="#"
class="whatever">name</a>
Rendered by:
context.fillSlots(
'email',
context.onePattern('email')(href=['mailto:a@bc.com'])['Mr X']
)
Although James's patch needs a couple of small changes to make that
work.
>
> >
> > Also included in this patch are doc cleanups, removing excess xml()
> > wrappings, replacing yield by return when possible, and the ability to
> > use the "<nevow:invisible>" element in a (x)html template file, with
> > the same behavior as the invisible stan tag.
> >
> > James
--
__
/ \__ Matt Goodall, Pollenation Internet Ltd
\__/ \ w: http://www.pollenation.net
__/ \__/ e: matt@pollenation.net
/ \__/ \ t: +44 (0)113 2252500
\__/ \__/
/ \ Any views expressed are my own and do not necessarily
\__/ reflect the views of my employer.