Re: dynamic directives

2010-10-19 Thread Nathan Bubna
I think you'll have to hack Velocity directly.  We don't have an event
handler that can intercept a non-macro.  Though, that would be nice!
(patches welcome)  But a few simple edits to the RuntimeMacro class
should give you the hook you need.  Basically, in the
RuntimeMacro.render method, once it has failed to find an already
defined VelocimacroProxy, you could create your macro, use
RuntimeInstance.addVelocimacro to add it, then do the vmProxy lookup
again.  Make sense?

On Tue, Oct 19, 2010 at 1:06 PM, Erik Hatcher  wrote:
> I have a desire to hook when unknown directives are called from a template.
>
> The use case is to enable Velocity as a templating engine for JRuby on Rails 
> (and other JRuby'ish things, possibly Sinatra, etc).  I've created some code 
> to get part of the way there: 
>
> What I'd like to be able to cleanly facilitate is templates that call any of 
> Rails view helper methods, like this: #url_for() where there is no actual 
> implementation of a UrlFor Directive or #macro definition.  I'd like to be 
> able to dynamically delegate to any view helpers that Rails is providing, and 
> if not then fall back to standard Velocity handling.
>
> I've looked around the 1.6.4 source code a bit and see RuntimeMacro and 
> VelocimacroProxy as some potential leads in how to go about this.  But I'm 
> not quite seeing if/how to hook into this capability.
>
> Is this possible?  If so, any pointers to get me going?
>
> Thanks!
>        Erik
>
>
> -
> To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org
> For additional commands, e-mail: user-h...@velocity.apache.org
>
>

-
To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org
For additional commands, e-mail: user-h...@velocity.apache.org



dynamic directives

2010-10-19 Thread Erik Hatcher
I have a desire to hook when unknown directives are called from a template.  

The use case is to enable Velocity as a templating engine for JRuby on Rails 
(and other JRuby'ish things, possibly Sinatra, etc).  I've created some code to 
get part of the way there: 

What I'd like to be able to cleanly facilitate is templates that call any of 
Rails view helper methods, like this: #url_for() where there is no actual 
implementation of a UrlFor Directive or #macro definition.  I'd like to be able 
to dynamically delegate to any view helpers that Rails is providing, and if not 
then fall back to standard Velocity handling.

I've looked around the 1.6.4 source code a bit and see RuntimeMacro and 
VelocimacroProxy as some potential leads in how to go about this.  But I'm not 
quite seeing if/how to hook into this capability.

Is this possible?  If so, any pointers to get me going?

Thanks!
Erik


-
To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org
For additional commands, e-mail: user-h...@velocity.apache.org