[
https://issues.apache.org/jira/browse/VELOCITY-666?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Jarkko Viinamäki updated VELOCITY-666:
--------------------------------------
Description:
Inspired by VELOCITY-583 (BlockMacro support) I implemented the same
functionality in a slightly different way.
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
was:
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.
Summary: Blockmacro support (allows any AST as macro body argument)
(was: RFC: new directive: #call)
Modified the issue title and description to reflect better what was actually
implemented.
> Blockmacro support (allows any AST as macro body argument)
> ----------------------------------------------------------
>
> 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
> Fix For: 1.7
>
> Attachments: velocity-blockmacro.patch, velocity-call-directive.patch
>
>
> Inspired by VELOCITY-583 (BlockMacro support) I implemented the same
> functionality in a slightly different way.
> 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
--
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]