[ANN] BackDoor 0.4.0: Attribute expansion

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>


<r:link>
<r:title />
</r:link>


<r:if_url matches="/news/">
<r:children:each limit=“3” order=“desc” by=“published_at”>


<r:link>
<r:title />
</r:link>


</r:children:each>


<r:link> More news… </r:link>


</r:if_url>
<r:unless_url matches="/news/">
<r:children:each order=“desc” by=“published_at”>


<r:link>
<r:title />
</r:link>


</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>


<r:link>
<r:title />
</r:link>


<r:ruby> @news = tag.locals.page.url =~ /news/; “” </r:ruby>
<r:children:each limit="#@news ? ‘3’:‘1000’" order=“desc”
by=“published_at”>


<r:link>
<r:title />
</r:link>


</r:children:each>
<r:if cond="@news">


<r:link> More news… </r:link>


</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

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

What a problematic release…

 There is a problem when running Radiant in "development" 

environment.
You get this error:

 "Error calling Dispatcher.dispatch #<NameError: method `attr' not

defined in Radius::TagBinding>"

 Seems that BackDoor gets loaded before Radius (?).  This does not

happen in “production” and “test” environments… I will take a look to
this in the following days, until then please use release 0.3.0 if you
use
“development” environment. Sorry for the inconvenience.

 /AITOR

OK, new 0.4.2 release solves the problem in development environment.

Enjoy,

/AITOR

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs