File Temple escaping

Hi,

I am using IDEA 3.0.5 and I run into some issue with
the file templates.

The File Template implementation is using Velocity
to generate actual instances but it seems to mess
with the template before passing it on to Velocity.

One thing which is done for sure is the extraction
of all the variables used and the user is prompted
to enter values for all of them before an instance
is created.

All nice so far, but some string that IDEA thinks
are Velocity variables are not actual variables
and there seems to be no way to escape them. Some
things that look like variables but aren't are:
- CVS keywords ($Log$)
- JSP Expression Language expressions ($)
- true variables used internally with a #set macro,
IDEA should not prompt for these

Using proper Velocity escaping does not work, it is
either ignored or generates a parse error.

The main question is: how can you escape variables
in file templates so IDEA ignores them?

Thanks,
Marius

4 comments

This is a shortcoming in Ariadna, you cannot perform a proper escaping.
In latest EAP builds you may escape \$Log$ and this will result in $Log$ in
final text.
Friendly,
Eugene

"Marius Scurtescu" <mscurtescu@healthmetrx.com> wrote in message
news:3FA03543.8000701@healthmetrx.com...

Hi,

>

I am using IDEA 3.0.5 and I run into some issue with
the file templates.

>

The File Template implementation is using Velocity
to generate actual instances but it seems to mess
with the template before passing it on to Velocity.

>

One thing which is done for sure is the extraction
of all the variables used and the user is prompted
to enter values for all of them before an instance
is created.

>

All nice so far, but some string that IDEA thinks
are Velocity variables are not actual variables
and there seems to be no way to escape them. Some
things that look like variables but aren't are:
- CVS keywords ($Log$)
- JSP Expression Language expressions ($)
- true variables used internally with a #set macro,
IDEA should not prompt for these

>

Using proper Velocity escaping does not work, it is
either ignored or generates a parse error.

>

The main question is: how can you escape variables
in file templates so IDEA ignores them?

>

Thanks,
Marius

>


0

Thanks Eugene, I am looking forward for the new version.

It would be nice if you had to explicitly specify
what variables should IDEA prompt for before instantiating
a template. This way you could use the full syntax
of Velocity. This is probably the only case in
which I wish IDEA was less smart ;)

One more question. Is there a variable holding the
name of the newly created file?

Marius

Evgueny Vigdorchik wrote:

This is a shortcoming in Ariadna, you cannot perform a proper escaping.
In latest EAP builds you may escape \$Log$ and this will result in $Log$ in
final text.
Friendly,
Eugene

"Marius Scurtescu" <mscurtescu@healthmetrx.com> wrote in message
news:3FA03543.8000701@healthmetrx.com...

>>Hi,
>>
>>I am using IDEA 3.0.5 and I run into some issue with
>>the file templates.
>>
>>The File Template implementation is using Velocity
>>to generate actual instances but it seems to mess
>>with the template before passing it on to Velocity.
>>
>>One thing which is done for sure is the extraction
>>of all the variables used and the user is prompted
>>to enter values for all of them before an instance
>>is created.
>>
>>All nice so far, but some string that IDEA thinks
>>are Velocity variables are not actual variables
>>and there seems to be no way to escape them. Some
>>things that look like variables but aren't are:
>>- CVS keywords ($Log$)
>>- JSP Expression Language expressions ($)
>>- true variables used internally with a #set macro,
>>IDEA should not prompt for these
>>
>>Using proper Velocity escaping does not work, it is
>>either ignored or generates a parse error.
>>
>>The main question is: how can you escape variables
>>in file templates so IDEA ignores them?
>>
>>Thanks,
>>Marius
>>



0


"Marius Scurtescu" <mscurtescu@healthmetrx.com> wrote in message
news:3FA143BB.7050905@healthmetrx.com...

Thanks Eugene, I am looking forward for the new version.

>

It would be nice if you had to explicitly specify
what variables should IDEA prompt for before instantiating
a template. This way you could use the full syntax
of Velocity. This is probably the only case in
which I wish IDEA was less smart ;)

Why, I think escaping the variable reference does exactly what you want,
i.e. it supresses IDEA prompt for variable value.
I think it's explicit enough.
>

One more question. Is there a variable holding the
name of the newly created file?

>

It is the value of the variable you were prompted or for java files it is
class name plus extension.

Eugene.


0

Evgueny Vigdorchik wrote:

"Marius Scurtescu" <mscurtescu@healthmetrx.com> wrote in message
news:3FA143BB.7050905@healthmetrx.com...

>>Thanks Eugene, I am looking forward for the new version.
>>
>>It would be nice if you had to explicitly specify
>>what variables should IDEA prompt for before instantiating
>>a template. This way you could use the full syntax
>>of Velocity. This is probably the only case in
>>which I wish IDEA was less smart ;)


Why, I think escaping the variable reference does exactly what you want,
i.e. it supresses IDEA prompt for variable value.
I think it's explicit enough.


Because you may want to fully use Velocity and set your
own variables inside the template. Those variables
should not be prompted for. I was trying this as a
workaround to the escape problem:

#set( $var = '$Log$' )
/* $var */

Nice try, now IDEA is prompting for $var instead of $Log.

>>One more question. Is there a variable holding the
>>name of the newly created file?
>>


It is the value of the variable you were prompted or for java files it is
class name plus extension.


Yes, but what exactly is the variable name? The online
help is documenting $, $, $
and $, where is the file name?

I am trying to create a template for JSP file and the
name of the file should be inserted as a comment at
the top of the file. It would be nice if IDEA inserted
this name automatically, but I could not find a way
to do it.


Eugene.


Thanks,
Marius

0

Please sign in to leave a comment.