Hi,

Michael Giroux wrote:
> On 3/9/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> 
>> Anyhow with the proposed VelocityWhitespaceGobbleStructuredTemplates
>> you could achieve your desired output with either:
>>
>> import com.myco.MyClass;
>> public Class AnotherClass {
>> #foreach( $t in $types )
>>   #if( $t.name.contains("_") )
>>       #text( "   Integer $t.name = 0;" )
>>       #if( $t.type == "static" )
>>            #text( "   // ignore static type $t.name" )
>>       #end
>>   #end
>> #end
>> }
> 
> But this requires that all output is encapsulated in #text() which pretty
> much eliminates the ability to copy/past text from other sources such as
> working java programs.

Yes and no - you can intermix the above with the below; thus
leaving your source lines untouched!

> 
>> or embedding the directives with a alternate indentation level to
>> optically make it stand out from the schmoo:
>>
>> import com.myco.MyClass;
>> public Class AnotherClass {
>>   #foreach( $t in $types )
>>      #if( $t.name.contains("_") )
>>    Integer $t.name = 0;
>>          #if ($t.type == "static")
>>    // ignore static type $t.name
>>          #end
>>      #end
>>   #end
>> }
> 
> 
> This obscures the indenting of the template, making it difficult to
> maintain, at least for those of us who work better with nicely formatted
> files.
> 

The "#"-syntax makes it easy for the eye to locate the directives. And
achived your "nicely formatted files" goal just the same

> 
>> Your #setindent directive example would be hard for a parser to understand.
>> More standard would be #setindent("   ").
> 
> 
> 
> Or perhaps #setindent(4) ## numeric value indicates amount of indent which
> allows something like
> #set ($indent = $indent +4)
> #setindent($indent)
> 

The updated wiki page with #setindent([+-]<number>) syntax is much better!

> 
> 
>> But creating complex Java code
>> with many indented blocks would clutter the template with these directives
>> and not contribute to readability compared to the two above example 
>> approaches.
>> I would therefore vote against the proposal of the *SetindentDirective, which
>> could be also done using:
>> a) code formatter as Jalopy
> 
> 
> The same argument can be made for XML and HTML files, so why are we
> discussing whitespace at all?  What about the case where the template is
> generating sample Java code to be included in a <code>...</code> block
> in an
> HTML document to be sent to a browser.  There is no chance to run this
> through Jalopy.

;) I stated my previous post with "for one-time generated thingies ..."

I the case of good looking (managable) templates and dynamically generated
well structured output we need better whitespace handling and support.

> 
> We currently use both Jalopy and/or the Eclipse JDT code formatter to
> reformat files that are generated for application code, but these have
> problems from time to time and Jalopy aborts without formatting.  It is
> easier to view the generated file if it has some reasonable indentation.
> 
> 
> 
>> b) the the VelocityWhitespaceGobbleAll and an custom #setindent()
>> directive
>>   working together with a modified FileWriter
> 
> 
> 
> When you say "custom #setindent()" does this say that it is not a standard
> part of Velocity?  I think this should be standard.

It is quite easy to add custom directives per configuration...

> 
>> Currently I use the ugly workaround in my macros:
>>
>> #macro( ClassMacro $indent $name $types )
>> ${indent}public Class $name {
>> #**#foreach( $t in $types )##
>> #*  *#if( $t.name.contains("_") )##
>> ${indent}  Integer $t.name = 0;
>> #*    *#if ($t.type == "static")##
>> ${indent}  // ignore static type $t.name
>> #*    *#end##
>> #*  *#end##
>> #**#end##
>> ${indent}}
> 
> 
> As you say, "ugly".  Hopefully VelocityWhitespaceGobbleAll  would eliminate
> the nead for the velocity comments #*  *# at beginning of every line.  It
> would be nice if these tricks were not needed, but the ${indent} would be
> tolerable if all the leading whitespace could be discarded and there was an
> easy way to populate $indent with desired number of blanks.
> 
> import com.myco.MyClass;
> public Class AnotherClass {
> $set ($indent = $leadingBlanks.substring(0,$indentAmount))
> #foreach( $t in $types )
>     #if( $t.name.contains("_") )
>         ${indent} Integer $t.name = 0;
>         #if ($t.type == "static")
>             ${indent} // ignore static type $t.name
>         #end
>     #end
> #end
> }
> 
> I think this might be equivalent to your suggestion to combine
> VelocityWhitespaceGobbleAll  with a new #setindent(amount) directive. 
> If Velocity is discarding all leading whitespace, and then injecting the
> amount specified by #setindent() a lot of the formatting issue would e 
> resolved
> and in a lot of cases there would be no need for post processing the generated
> output.

Exaclty, but then you are near to my example with the #text(...) thingies ;)

That is why I suggested to combine this with a custom FileWriter that does this!

> 
> Michael
> 

You can see the reason for all of the proposed patters:
a) VelocityWhitespaceGobbleAsUsual
b) VelocityWhitespaceGobbleAll
c) VelocityWhitespaceGobbleNone
d) VelocityWhitespaceGobbleStructuredTemplates
Yours can be painlessly achieved with b) plus #setindent(...) and a FileWriter
fitting perfectly your application. OTOH d) would also do the job ;)

Cheers,
Christoph


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to