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

Nathan Bubna commented on VELOCITY-666:
---------------------------------------

I share your skepticism about committing this.  I don't know that

#macro( strong $txt $bodyContent )
<strong>$bodyContent</strong> $txt
#end
#define( $bodyContent )
<u>This text is underlined and bold</u>
#end
#strong( $foobar $bodyContent )

Is awkward or long enough to warrant another directive just to shorten it to 
this

#macro( strong $txt )
<strong>$bodyContent</strong> $txt
#end
#call( 'strong' $foobar )
<u>This text is underlined and bold</u>
#end

It is hard to find the right balance in these things.  Right now, i am inclined 
to leave this out, as it doesn't seem to provide any needed function, just a 
somewhat better syntax.   And i think what we really want syntactically is this:

#macro( strong $txt )
<strong>$bodyContent</strong> $txt
#end
#strong( $foobar )
<u>This text is underlined and bold</u>
#end

If that happens, #call will just be a complication for us to deprecate and for 
users to change uses thereof.

I also happen to know that there are longtime users who are in the habit of 
using a #call( $tool.doThis() ) macro and recommending that practice to others. 
  Adding this directive will surely break things for people upgrading.

I think the bottom line for me is that each directive we add risks conflict 
with existing macros, increases the famously-low learning curve for Velocity 
and--as you said--increases the internal complexity/size of Velocity.  If we 
are going to add a new directive, then i think we should be sure that it is 
well worth the cost.  I don't think #call has crossed that threshold, unless i 
am missing something it can do.

If it could be implemented in such a way that it didn't require so many 
internal patches, it would be fine as an optional user directive (like #local). 
 I'm not sure, though, if that is possible for this.

> RFC: new directive: #call
> -------------------------
>
>                 Key: VELOCITY-666
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-666
>             Project: Velocity
>          Issue Type: Improvement
>    Affects Versions: 1.6.2, 1.7
>            Reporter: Jarkko Viinamäki
>         Attachments: velocity-call-directive.patch
>
>
> Inspired by VELOCITY-583 (BlockMacro support) I implemented the same 
> functionality in a slightly different way.
> This patch introduces a new directive #call("mymacro" $arg1 $arg2 ... ) any 
> valid Velocity content here #end
> This directive causes a call to defined macro with given arguments AND passes 
> the enclosed AST as an argument which can be referenced with $bodyContent 
> (default, name is configurable).
> An example:
>  #set($foobar = "yeah!")
>  
>  #macro(strong $txt)
>  <strong>$bodyContent</strong> $txt
>  #end
>  #call("strong" $foobar)
>  <u>This text is underlined and bold</u>
>  #end
>  
> Will print:
>  <strong><u>This text is underlined and bold<u></strong> yeah!
> Like I commented in  VELOCITY-583 the same thing can be done by first using 
> #define to build up some custom AST and then pass that AST as an argument to 
> some macro. While it works, it's not as convenient as this syntax. This patch 
> however increases the amount of code lines in Velocity and the implementation 
> is a bit "hackish" so even I'm not totally convinced whether we should commit 
> this. 
> But anyway, here it is, I'd love to hear your comments.

-- 
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: dev-unsubscr...@velocity.apache.org
For additional commands, e-mail: dev-h...@velocity.apache.org

Reply via email to