On 01/19/2011 03: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.
In XWiki.ConfigurableClass #setVariable velocity macro is called between
two HTML macros that generate only script tags:
{{html}}
<script>...</script>
{{html}}
One problem is that SCRIPT tag is considered a block level element by
the HTML macro and as a result something like:
before{{html}}<script>alert('Hi!')</script>{{/html}}after
fails to be rendered. In our case "before" and "after" are spaces
generated by #setVariable macro call.
If we leave empty lines before and after these two HTML macros they will
be rendered fine BUT we'll get a paragraph with spaces between the two
SCRIPT tags, spaces coming from the #setVariable macro call.
>
> 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.
Exactly. If I put the code of the #setVariable velocity macro in a wiki
page, inside a {{velocity}} macro, then spaces are filtered.
Thanks,
Marius
> Maybe macros.vm should also be passed through the
> whitespace filter before being parsed? Is that even possible?
>
_______________________________________________
devs mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/devs