You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by "Geir Magnusson Jr." <ge...@optonline.net> on 2000/12/21 15:21:03 UTC
interpolation 'enhancement'
For those of you that ignore commit diff-gibberish, last night I
checked in changes to the parser and the AST code to support
single-quote string literals ( '$foo' ) in VTL. Unlike their
double-quote siblings ( "$foo" ) they won't be interpolated. Think
'Perl' here. This was brought up and discussed a while back so I don't
think anyone will be upset, surprised or diappointed, but if so, say so.
To review :
1) There is a property stringliterals.interpolate, default true, that
controls interpolation of string literals.
2) When true (the default), any string literal contained in double-quote
characters ( " ) will be parsed and rendered. This can be as simple as
doing string concatenation :
#set( $directoryRoot = "www" )
#set( $templateName = "index.vm" )
#set( $template = "$directoryRoot/$templateName" )
$template - renders as -> www/index.vm
or invoking directives and Velocimacros :
#set( $templateName = "index.vm" )
#set( $template = "#if($root) #makedirectorypath( $root $template )
#else default/$templateName #end" )
and with $root not defined in the context :
$template - renders as -> default/index.vm
where #makedirectorypath() is some Velocimacro.
See interpolation.vm in test/templates for more [wacky] examples.
3) When the string literal is bounded by single-quote characters ( ' )
no interpolation occurs.
#set( $blargh = '$foo' )
$blargh - renders -> $foo
As always, comments, discussion, etc...
geir
P.S. Anyone think that the situational pun in the Subject was funny? :)
--
Geir Magnusson Jr. geirm@optonline.com
Velocity : it's not just a good idea. It should be the law.
http://jakarta.apache.org/velocity
Re: interpolation 'enhancement'
Posted by Daniel Rall <dl...@finemaltcoding.com>.
"Geir Magnusson Jr." <ge...@optonline.net> writes:
> For those of you that ignore commit diff-gibberish, last night I
> checked in changes to the parser and the AST code to support
> single-quote string literals ( '$foo' ) in VTL. Unlike their
> double-quote siblings ( "$foo" ) they won't be interpolated. Think
> 'Perl' here. This was brought up and discussed a while back so I don't
> think anyone will be upset, surprised or diappointed, but if so, say so.
+1
Daniel
Re: interpolation 'enhancement'
Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Christoph Reck wrote:
>
> What happens with a $reference within single quotes inside of
> another string, e.g.:
> <a href="javascript:doFileAction('$command','$name')">$command</a>
> Will $command and $name be expanded.
Yes, as you expect, because they aren't technically VTL string
literals. A VTL string literal is only found as :
1) the RHS of a #set() directive
2) an arg to a directive or a VM
3) an arg to a method of a reference object such as $foo.bar("woogie")
So the template :
#set($command="foo")
#set($name="woogie")
<a href="javascript:doFileAction('$command','$name')">$command</a>
outputs
<a href="javascript:doFileAction('foo','woogie')">foo</a>
like you expect, hope and wish for.
> The behaviour I would expect is like in a (c)shell:
> echo "'$HOME'"
> does an expand; whereas
> echo '$HOME'
> does not.
For the template :
#set($command="foo")
#set($e = "$command")
#set($f = "'$command'")
#set($g = '$command')
$e
$f
$g
you get :
foo
'foo'
$command
Which I think is what you want.
geir
>
> :) Christoph
>
> "Geir Magnusson Jr." wrote:
> >
> > For those of you that ignore commit diff-gibberish, last night I
> > checked in changes to the parser and the AST code to support
> > single-quote string literals ( '$foo' ) in VTL. Unlike their
> > double-quote siblings ( "$foo" ) they won't be interpolated. Think
> > 'Perl' here. This was brought up and discussed a while back so I don't
> > think anyone will be upset, surprised or diappointed, but if so, say so.
--
Geir Magnusson Jr. geirm@optonline.com
Velocity : it's not just a good idea. It should be the law.
http://jakarta.apache.org/velocity
Re: interpolation 'enhancement'
Posted by Christoph Reck <Ch...@dlr.de>.
What happens with a $reference within single quotes inside of
another string, e.g.:
<a href="javascript:doFileAction('$command','$name')">$command</a>
Will $command and $name be expanded.
The behaviour I would expect is like in a (c)shell:
echo "'$HOME'"
does an expand; whereas
echo '$HOME'
does not.
:) Christoph
"Geir Magnusson Jr." wrote:
>
> For those of you that ignore commit diff-gibberish, last night I
> checked in changes to the parser and the AST code to support
> single-quote string literals ( '$foo' ) in VTL. Unlike their
> double-quote siblings ( "$foo" ) they won't be interpolated. Think
> 'Perl' here. This was brought up and discussed a while back so I don't
> think anyone will be upset, surprised or diappointed, but if so, say so.
Re: interpolation 'enhancement'
Posted by Daniel Rall <dl...@finemaltcoding.com>.
"Geir Magnusson Jr." <ge...@optonline.net> writes:
> For those of you that ignore commit diff-gibberish, last night I
> checked in changes to the parser and the AST code to support
> single-quote string literals ( '$foo' ) in VTL. Unlike their
> double-quote siblings ( "$foo" ) they won't be interpolated. Think
> 'Perl' here. This was brought up and discussed a while back so I don't
> think anyone will be upset, surprised or diappointed, but if so, say so.
+1
Daniel