[
https://issues.apache.org/jira/browse/VELOCITY-666?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Jarkko Viinamäki updated VELOCITY-666:
--------------------------------------
Attachment: velocity-blockmacro.patch
Hmm I agree that #call... format is a bit ugly. Jonathan is right though that
nesting is an important feature that the engine should support.
Here's another attempt to fix this issue (velocity-blockmacro.patch). I renamed
the feature to BlockMacro. I also removed it from directives.properties so it
does not clash with anything that already exists.
The new syntax is:
#...@yourmacroname($arg1 $arg2) any valid velocity AST here #end
so basically the syntax is exactly the same as for normal macros except you put
that @ prefix to the macro name. That tells Velocity that there's a macro AST
body that should be passed to the actual macro.
And in the macro you can refer to the passed body 0-N times. Like:
#macro(yourMacroName $foo $bar)
$bodyContent
#end
Anyway, since normal Velocity macros are LINE directives, there must be some
way to tell Velocity when a body follows the call. I think this is pretty clean
syntax.
> 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-blockmacro.patch, 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: [email protected]
For additional commands, e-mail: [email protected]