On Jan 20, 2011, at 1:38 AM, Sergiu Dumitriu wrote:
On 01/19/2011 03:13 PM, Vincent Massol wrote:
On Jan 19, 2011, at 2:30 PM, Sergiu Dumitriu wrote:
On 01/19/2011 02:20 PM, Vincent Massol wrote:
On Jan 19, 2011, at 2:05 PM, sdumitriu (SVN) wrote:
Author: sdumitriu Date: 2011-01-19 14:05:06 +0100 (Wed, 19 Jan 2011) New Revision: 33998
Modified: platform/web/trunk/standard/src/main/webapp/templates/macros.vm Log: XWIKI-5890: #setVariableFromRequest doesn't work with Velocity 1.7, replace with #readVariableFromRequest Corrected #setVariable so that it doesn't output any whitespace.
Modified: platform/web/trunk/standard/src/main/webapp/templates/macros.vm =================================================================== --- platform/web/trunk/standard/src/main/webapp/templates/macros.vm 2011-01-19 13:01:30 UTC (rev 33997) +++ platform/web/trunk/standard/src/main/webapp/templates/macros.vm 2011-01-19 13:05:06 UTC (rev 33998) @@ -1508,13 +1508,13 @@ * @param value the value to assign *### #macro(setVariable $variableName $value) - ## Only do this if the variable name is really a valid variable name - #if ($variableName.matches('[a-zA-Z_][a-zA-Z0-9_-]*')) - #evaluate("${escapetool.h}set(${escapetool.d}${variableName}=${escapetool.d}value)") - #elseif ($variableName.matches('\$[a-zA-Z_][a-zA-Z0-9_-]*')) - #evaluate("${escapetool.h}set(${variableName}=${escapetool.d}value)") - #end +## Only do this if the variable name is really a valid variable name +#if ($variableName.matches('[a-zA-Z_][a-zA-Z0-9_-]*')) +#evaluate("${escapetool.h}set(${escapetool.d}${variableName}=${escapetool.d}value)") +#elseif ($variableName.matches('\$[a-zA-Z_][a-zA-Z0-9_-]*')) +#evaluate("${escapetool.h}set(${variableName}=${escapetool.d}value)") #end +#end
So we can't use indentation in macros? Should we document this generally or is it specific to this macro (in which case maybe we should add a comment so that the next person doesn't start indenting it)?
I don't know, Marius complained that #setVariable creates whitespace, so I removed them for this macro. For the other macros, it depends. I'd say that utility macros that bring essential functionality should not output spaces.
The problem comes from the fact that in wiki content, {{velocity}} has a default whitespace filter which takes care of indentation whitespace, but calling global macros will output the whitespace present in the original macro. Maybe macros.vm should also be passed through the whitespace filter before being parsed? Is that even possible?
We could create a VelocityFilter that removes leading whitespaces *after* velocity has been executed (default filter removes leading white spaces *before* the velocity has been executed).
You'd use it like this:
{{velocity filter="indentafter"}} #myglobalmacro(....) {{/velocity}}
Would that work?
I'm not sure, since there's no way to know where the whitespace come from after the parsing is done. Something like this:
#foreach (...) #set (...) #end
will end up as a single row of spaces (since #set eats the newline), which isn't always on a single line, but could be somewhere in the middle of a row.
Yep, not optimal. -Vincent