[ 
https://issues.apache.org/jira/browse/VELOCITY-680?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12674753#action_12674753
 ] 

claude edited comment on VELOCITY-680 at 2/18/09 11:25 AM:
-------------------------------------------------------------------

> 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($request.foo = 'bar')
#set($session.foo = 'bar' )
#set($application.foo = '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)
  I am at iteration $foreach.counter
  #set($foreach.foo = 'bar')
  #if($i == 'I want to break out') $foreach.break #end
  #if( $i == 'red alert' ) $template.stop
#end

#macro(mymacro) #set($mymacro.mylocal = 'bar') #end

#foreach($i in $foo)
  #set($outer = $foreach)
  #foreach($j in $bar)
     break inner loop : $foreach.break
     break outer loop : $outer.break
  #end
#end

etc...



      was (Author: claude):
    > 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($request.foo = 'bar')
#set($session.foo = 'bar' )
#set($application.foo = '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($foreach.foo = 'bar')
  #if($i == 'I want to break out') $foreach.break() #end
  #if( $i == 'red alert' ) $template.stop()
#end
#macro(mymacro) #set($mymacro.mylocal = 'bar') #end

etc...


  
> RFC: New #local directive that behaves like #set but puts things into local 
> context in macro rendering
> ------------------------------------------------------------------------------------------------------
>
>                 Key: VELOCITY-680
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-680
>             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: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to