On Mar 6, 2:38 am, Christophe Porteneuve <[EMAIL PROTECTED]> wrote:
> Nicolás Sanguinetti a écrit :
>
> > But what about declaring a toTemplateReplacements in the object? (the
> > following is untested)
>
> Yes, that's the current way to go.
>
[snipped]
>
> Absolutely.  I can understand, however, people wanting to squeeze more
> power out of evaluate/interpolate...

I guess what I was looking for was a way to only invoke the methods on
an object if they were included in the template. The specific use case
I've been playing with is a "formatted date" class where each instance
has a Date and a Template for rendering the date. Say for the sake of
the argument your options for rendering a month in a Template string
are:

m - Month number, no padding.
mm - Two digit month number, zero padded
mmm - "Short" name for month (e.g., "Mar" or "Apr")
mmmm - "Full" name for month (e.g., "March" or "April")

Typically only one of the placeholders for month will appear in such a
template, and therefore only one function is invoked. Using the
toTemplateReplacement() approach, all four of the functions would be
invoked, not knowing which placeholder for month (if any) will be used
in the Template.

If Template was extended to include a method like getPlaceholders() or
something of that nature that returned the placeholder strings, then
those in turn could be passed to a toTemplateReplacement() on the
object being rendered as a "hint", which the toTemplateReplacement()
implementation could choose to apply or not. I've seen a couple folks
mention a function for retrieving the placeholders, and I think that
at least seems like a useful idea.

I'll be working today on a subclass of Template that would provide
some of the extended services without having to patch the "core"
Template class. I'm just very happy that there is so much that one can
do even with this one area of Prototype that it sparks discussion on
how to build on it.

Cheers,
G
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Spinoffs" 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/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to