![](https://secure.gravatar.com/avatar/44e3f98a2f3b7213d5f14b558a849dd2.jpg?s=120&d=mm&r=g)
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>
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 Any views expressed are my own and do not necessarily reflect the views of my employer.