velocity-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Claude Brisson (JIRA)" <>
Subject [jira] Commented: (VELOCITY-680) RFC: New #local directive that behaves like #set but puts things into local context in macro rendering
Date Wed, 18 Feb 2009 19:24:02 GMT


Claude Brisson commented on VELOCITY-680:

> Basically, i don't want more directives for #setlocal and #setglobal support. To my eyes,
it's inflexible, non-extensible clutter, especially if we keep around config options like
velocimacro.context.localscope to complicate the possibilities. 

I agree - if we find a nice way of specifying the context in #set, it's better than multiplying
the number of directives.
But why not just specify the scope as a second optional argument to #set, as in :

#set( $foo = $bar, parse ) 

Visually complex syntaxes can really scare people coming from the world of the web design
- brackets followed by parenthesis are really confusing.

> Depending on the implementation, this syntax might be extensible and allow VelocityView
contexts to recognize and handle things like:
> #set[request]( $foo = 'bar' )
> #set[session]( $foo = 'bar' )
> #set[application]( $foo = 'bar' )

Those ones already have a very natural syntax (which I didn't include in the trunk to avoid
having the tools depending on a too recent version of the engine - but, by the way, it's enough
not to configure its use by default, so I'll include it!):

#set($ = 'bar')
#set($ = 'bar' )
#set($ = 'bar' )

Since $request, $session and $application all are legitimate objects, I don't think we need
something else.

Ah. Speaking of this, I think of another solution about the scoped syntax debate, which in
fact is the one I like the most now that I think of it: the tools approach.
Why not give each scope an object representing it, that is a $foreach, a $template and a $macro?
It looks like really very customizable (as users can inherit hose objects) and flexible. That
would give things like:

#foreach($i in $collection)
  #set($ = 'bar')
  #if($i == 'I want to break out') $foreach.break() #end
  #if( $i == 'red alert' ) $template.stop()
#macro(mymacro) #set($mymacro.mylocal = 'bar') #end


> RFC: New #local directive that behaves like #set but puts things into local context in
macro rendering
> ------------------------------------------------------------------------------------------------------
>                 Key: VELOCITY-680
>                 URL:
>             Project: Velocity
>          Issue Type: New Feature
>    Affects Versions: 1.7
>            Reporter: Jarkko Viinamäki
>         Attachments: velocity-local-directive-1.1.patch, velocity-local-directive.patch
> It would be very useful to be able to set variables that are in local macro scope. That
is, they do not overwrite "global" variables and are thrown away after macro rendering. This
would allow people to build macro libraries that do not clash so easily with each other.
> There is some implementation of a "LocalDirective" in experimental/localdirective but
I didn't quite get it and it doesn't follow the same syntax as #set. I used a few minutes
to hack together this alternative implementation which behaves exactly like #set but it puts
things in local context only.
> There's only one test case since this is Request-for-Comments type of patch.

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message