Reformat Velocity HTML code

I'm trying to reformat Velocity web pages, *.vm.

IDEA does not keep the indentation of #if #else #end directives, expecially the nested ones.

I can't find any places where to configure that in Code Style or Editor section.

Is it possible at all?

cheers
nodje

12 comments
Comment actions Permalink

When IDEA reformats template files it uses the formatter of template
data language of a file. In your case, I suggest, it's HTML language.
Such behavior is convenient in case you have much of a code in template
data language (i.e. HTML) and less part in Velocity language.

I think IDEA should use (or provide option to choose) template language
(e.g. Velocity) formatter for files written mostly in a template language.

nodje wrote:

I'm trying to reformat Velocity web pages, *.vm.

IDEA does not keep the indentation of #if #else #end directives, expecially the nested ones.

I can't find any places where to configure that in Code Style or Editor section.

Is it possible at all?

cheers
nodje

---
Original message URL: http://www.jetbrains.net/devnet/message/5239497#5239497

0
Comment actions Permalink

Hello nodje,

please, create a JIRA ticket if you interested in this option :)


Alexey Chmutov wrote:

When IDEA reformats template files it uses the formatter of template
data language of a file. In your case, I suggest, it's HTML language.
Such behavior is convenient in case you have much of a code in template
data language (i.e. HTML) and less part in Velocity language.

I think IDEA should use (or provide option to choose) template language
(e.g. Velocity) formatter for files written mostly in a template language.

nodje wrote:

>> I'm trying to reformat Velocity web pages, *.vm.
>>
>> IDEA does not keep the indentation of #if #else #end directives,
>> expecially the nested ones.
>>
>> I can't find any places where to configure that in Code Style or
>> Editor section.
>>
>> Is it possible at all?
>>
>> cheers
>> nodje
>>
>> ---
>> Original message URL:
>> http://www.jetbrains.net/devnet/message/5239497#5239497

0
Comment actions Permalink

Hi Alexey

I understand your point but I wouldn't want to mess up my HTML page either by using a Velocity template reformater.
Idealy, I would like the HTML reformater to be able to recognize Velocity tags!

After all the only thing it needs is to know that things behind # are Velocity directives. And it does already since these tags are highlighted correctly.
So it seem it's just a matter of adding a rule for those # directives so that they get proper indentation during reformat process, isn't?

0
Comment actions Permalink

nodje,
I'm not sure I understand you.
What do you mean proper indentation? Please, provide an example.
During reformat process, indentation of Velocity directives is computed
using the containing HTML construct rather than the containing Velocity
construct. In other words, structure of Velocity directives of a file
being formatted is ignored, only structure of data template language
(HTML tags) is considered.
Velocity directives and HTML tags are processed (i.e. highlighted,
completed, resolved) correctly because of building of independant tree
structures for both languages.

Hi Alexey

I understand your point but I wouldn't want to mess up my HTML page either by using a Velocity template reformater.
Idealy, I would like the HTML reformater to be able to recognize Velocity tags!

After all the only thing it needs is to know that things behind # are Velocity directives. And it does already since these tags are highlighted correctly.
So it seem it's just a matter of adding a rule for those # directives so that they get proper indentation during reformat process, isn't?

---
Original message URL: http://www.jetbrains.net/devnet/message/5239632#5239632

0
Comment actions Permalink

ok, let me give you an exemple, that should be more clear:

here a a piece of manually indented code:

<tr>
    #set ($url = $!request.session.getAttribute('headerForm').professionDocumentURL)
    #set ($baseUrl = $!request.session.getAttribute('headerForm').documentBaseURL)
    <td colspan="2">
        <a href="javascript:lienPDF('$baseUrl','$url')">
            <img src="web/img/comprendrelecalcul.gif" alt="" height="42" width="350" border="0">
        </a>
    </td>
    <td/>
    <td colspan="2">
        #if ($!mustDisplayContributionOption)
            #if ($!isVeterinary)
                <a href="$link.setAction('/enterWorkforceVeterinaire')?dispatch=consult">
                    <img src="web/img/consultdeclaration.gif" alt="" height="21" width="350" border="0">
                </a>
            #else
                <a href="$link.setAction('/enterWorkforce')?dispatch=consult">
                    <img src="web/img/consultdeclaration.gif" alt="" height="21" width="350" border="0">
                </a>
            #end
        #elseif ($!displayDownPaymentOption)
            #if ($!displayReceiptAndContribution)
                <a href="$link.setAction('/memberLinkAction')?whichMemberLink=supprimeracompte">...</a>
            #else
                #if ($!displayReceiptOnly)
                    <a href="$link.setAction('/downPaymentTaxAmountAndVatAction')?dispatch=prepare">...</a>
                #else
                    #if ($!displayNoReceiptNorContribution)
                        <a href="$link.setAction('/enterWorkforceDownPayment')?dispatch=consult">...</a>
                    #end
                #end
            #end
        #end
    </td>
</tr>

The same piece of code after Idea auto reformat:

<tr>
    #set ($url = $!request.session.getAttribute('headerForm').professionDocumentURL)
    #set ($baseUrl = $!request.session.getAttribute('headerForm').documentBaseURL)
    <td colspan="2">
        <a href="javascript:lienPDF('$baseUrl','$url')">
            <img src="web/img/comprendrelecalcul.gif" alt="" height="42" width="350" border="0">
        </a>
    </td>
    <td/>
    <td colspan="2">
        #if ($!mustDisplayContributionOption)
        #if ($!isVeterinary)
        <a href="$link.setAction('/enterWorkforceVeterinaire')?dispatch=consult">
            <img src="web/img/consultdeclaration.gif" alt="" height="21" width="350" border="0">
        </a>
        #else
        <a href="$link.setAction('/enterWorkforce')?dispatch=consult">
            <img src="web/img/consultdeclaration.gif" alt="" height="21" width="350" border="0">
        </a>
        #end
        #elseif ($!displayDownPaymentOption)
        #if ($!displayReceiptAndContribution)
        <a href="$link.setAction('/memberLinkAction')?whichMemberLink=supprimeracompte">...</a>
        #else
        #if ($!displayReceiptOnly)
        <a href="$link.setAction('/downPaymentTaxAmountAndVatAction')?dispatch=prepare">...</a>
        #else
        #if ($!displayNoReceiptNorContribution)
        <a href="$link.setAction('/enterWorkforceDownPayment')?dispatch=consult">...</a>
        #end
        #end
        #end
        #end
    </td>
</tr>

So the HTML tags are recognize and indented, but the Velocity tags aren't and their indentation is not respected.

0
Comment actions Permalink

I thought so. You're right, indentations based on both structures (HTML
& Velocity) are reasonable for such kind of templates.
Please, create JIRA ticket in http://www.jetbrains.net/jira

nodje wrote:

ok, let me give you an exemple, that should be more clear:

here a a piece of manually indented code:

>     #set ($url = $!request.session.getAttribute('headerForm').professionDocumentURL)
>     #set ($baseUrl = $!request.session.getAttribute('headerForm').documentBaseURL)
>     
>         
>             
>         
>     
>     
>     
>         #if ($!mustDisplayContributionOption)
>             #if ($!isVeterinary)
>                 
>                     
>                 
>             #else
>                 
>                     
>                 
>             #end
>         #elseif ($!displayDownPaymentOption)
>             #if ($!displayReceiptAndContribution)
>                 ...
>             #else
>                 #if ($!displayReceiptOnly)
>                     ...
>                 #else
>                     #if ($!displayNoReceiptNorContribution)
>                         ...
>                     #end
>                 #end
>             #end
>         #end
>     
> 
> ]]>

The same piece of code after Idea auto reformat:

>     #set ($url = $!request.session.getAttribute('headerForm').professionDocumentURL)
>     #set ($baseUrl = $!request.session.getAttribute('headerForm').documentBaseURL)
>     
>         
>             
>         
>     
>     
>     
>         #if ($!mustDisplayContributionOption)
>         #if ($!isVeterinary)
>         
>             
>         
>         #else
>         
>             
>         
>         #end
>         #elseif ($!displayDownPaymentOption)
>         #if ($!displayReceiptAndContribution)
>         ...
>         #else
>         #if ($!displayReceiptOnly)
>         ...
>         #else
>         #if ($!displayNoReceiptNorContribution)
>         ...
>         #end
>         #end
>         #end
>         #end
>     
> 
> ]]>

So the HTML tags are recognize and indented, but the Velocity tags aren't and their indentation is not respected.

---
Original message URL: http://www.jetbrains.net/devnet/message/5239742#5239742

0
Comment actions Permalink

I've created a usability problem ticket: http://www.jetbrains.net/jira/browse/IDEA-23255

As I've added in the comment, it'd be good to be able to exclude some known problematic files from the reformat function, especially for the very convenient commit time reformat (that you can tick in the commit dialog box). An annotation would be very convenient for that matter.
That would avoid painful mistakes !

0
Comment actions Permalink

nodje,
thanks for the ticket :)
About annotation: Do you mean something like this at beginning of a file?

    1. @preserve velocity formatting


nodje wrote:

I've created a usability problem ticket: http://www.jetbrains.net/jira/browse/IDEA-23255

As I've added in the comment, it'd be good to be able to exclude some known problematic files from the reformat function, especially for the very convenient commit time reformat (that you can tick in the commit dialog box). An annotation would be very convenient for that matter.
That would avoid painful mistakes !

---
Original message URL: http://www.jetbrains.net/devnet/message/5239807#5239807

0
Comment actions Permalink

I meant something more generic, in the line of @DoNotAutoformat.
Because it could be used by any sort of file - and there's many cases where you want to keep your formating because expressing rules is to complexe/not possible.

As for the Velocity one, it' be only useful if Velocity language formating in HTML template is not going to be supported.

cheers

0
Comment actions Permalink

Sorry to bring this up again, but I'm still badly in need for a @DoNotAutoformat annotation.

What do you think? For me, it seems to be the best way to keep autoformating everything on check in, without paying attention to the few files that can't be reformated for some reason.

Please let me know if there's a way to exclude some file from a global autoformat.

best
-nodje

0
Comment actions Permalink

Reopening the topic since ithasn't been addressed yet, to my knowledge:

I just realized Eclipse was providing something to turn the formatter off for specific snippet:

// @formatter:off
...
// @formatter:on


And you can configure the magic string if youlike something else.

Could we get that in IDEA too?

0
Comment actions Permalink

Hello,

No such feature is available at the moment. Feel free to track the progress of IDEA-56995.

Denis

0

Please sign in to leave a comment.