You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Erik Hatcher <er...@gmail.com> on 2010/10/19 22:06:15 UTC

dynamic directives

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: <http://github.com/erikhatcher/velaro>

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-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org


Re: dynamic directives

Posted by Nathan Bubna <nb...@gmail.com>.
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 <er...@gmail.com> 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: <http://github.com/erikhatcher/velaro>
>
> 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-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>

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