[Radiant] [ANN] BackDoor 0.4.0: Attribute expansion
Aitor Garay-Romero
me at aitor.name
Wed Dec 12 09:00:33 CST 2007
Just after releasing it, i noticed a small detail. I have corrected this
in the new 0.4.1 version. From the CHANGELOG:
=== 0.4.1
* Automatically convert to string the result of evaluating tag attributes,
so the user does not have to take care of this
/AITOR
On Dec 12, 2007 1:43 PM, Aitor Garay-Romero <me at aitor.name> wrote:
> Hi there!,
>
> New feature: Attribute expansion. From the README:
>
> ---- 8< ----
> == Attribute expansion
>
> Back Door allows evaluating tag's attributes as Ruby code. If a tag's
> attribute starts with the "#" symbol, the rest of the attribute is
> evaluated, and the attribute's value is replaced with the evaluated value.
> This works for both standard Radiant (Radius) tags and Back Door's own tags.
>
>
> As an example, consider a side-bar where we want to show first and second
> level pages. But for the "news" page, we want to limit the number of
> children to 3 and add an extra link to see all news. Without Back Door this
> could be implemented as:
>
> <r:children:each>
> <h2 class="menu-heading">
> <r:link>
> <r:title />
> </r:link>
> </h2>
> <r:if_url matches="/news/">
> <r:children:each limit="3" order="desc" by="published_at">
> <h3 class="menu-subheading">
> <r:link>
> <r:title />
> </r:link>
> </h3>
> </r:children:each>
> <h3 class="menu-subheading">
> <r:link> More news... </r:link>
> </h3>
> </r:if_url>
> <r:unless_url matches="/news/">
> <r:children:each order="desc" by="published_at">
> <h3 class="menu-subheading">
> <r:link>
> <r:title />
> </r:link>
> </h3>
> </r:children:each>
> </r:unless_url>
> </r:children:each>
>
> Clearly there is too much duplication. With Back Door this can be
> rewritten as:
>
> <r:children:each>
> <h2 class="menu-heading">
> <r:link>
> <r:title />
> </r:link>
> </h2>
> <r:ruby> @news = tag.locals.page.url =~ /news/; "" </r:ruby>
> <r:children:each limit="#@news ? '3':'1000'" order="desc"
> by="published_at">
> <h3 class="menu-subheading">
> <r:link>
> <r:title />
> </r:link>
> </h3>
> </r:children:each>
> <r:if cond="@news">
> <h3 class="menu-subheading">
> <r:link> More news... </r:link>
> </h3>
> </r:if>
> </r:children:each>
>
> Note how the "limit" attribute of the <r:children:each> tag uses the "#"
> symbol to make it dynamic.
> ---- 8< ----
>
> /AITOR
>
>
More information about the Radiant
mailing list