Nice :)

Thanks,
TF

On Mar 3, 10:24 pm, Bryan Larsen <[email protected]> wrote:
> Here are a couple of potentially useful tags.   Note that if <count>
> is modified to use this.try.+(0) instead of this.try.to_int the two
> tags could potentially merged into one.
>
> Bryan
>
> <!--
> A convenience tag to output a sum of counts and a correctly pluralised
> label.  Works with any type of collection.
>
> ### Usage
>
>     <count-all:comments attribute="votes"/> -> <span class="count">17
> Votes</span>
>
> If no `label` is passed, the attribute is used as the label.
>
> All attributes are passed to `<count>` unchanged, including `label`,
> `prefix`, `if-any` and `lowercase`
> -->
> <def tag="count-all" attrs="attribute, label">
>   <%
>     count = this.inject(0) {|total, item|
>       val = item.send(attribute)
>       # inspired by rapid_core.dryml:497
>       total + (val.try.to_int || val.try.total_entries ||
> (val.try.loaded? && val.try.length) || val.try.count ||
> val.try.length)
>     }
>
>     label ||= attribute.singularize.humanize
>   %>
>
>   <count with="&count" label="&label" merge-attrs />
> </def>
>
> <!--
> A convenience tag to output a sum of attribute values.  Works with any
> type of collection.
>
> ### Usage
>
>     <sum:comments attribute="score"/> -> 42
>
> -->
> <def tag="sum" attrs="attribute">
>   <%=
>     this.inject(nil) {|total, item|
>       val = item.send(attribute)
>       c = val.try.+(0) || val.try.total_entries || (val.try.loaded? &&
> val.try.length) || val.try.count || val.try.length
>       if total.nil?
>         c
>       else
>         total+c
>       end
>     }
>
>   %>
> </def>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Hobo 
Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/hobousers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to