for one-time generated thingies like HTML or Java classes, you
can easily post-process the Velocity output with a code formatter.
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
}
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
}
Your #setindent directive example would be hard for a parser to understand.
More standard would be #setindent(" "). 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
b) the the VelocityWhitespaceGobbleAll and an custom #setindent() directive
working together with a modified FileWriter
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}}
Just my 2c...
:) Christoph
Michael Giroux wrote:
> I've been reviewing the various discussions on whitespace. I was not able
> to determine if the current proposals cover my thoughts or not, so sorry if
> what follows has been covered already.
>
> For the most part, I want my templates to be readable and I use
> indenting to
> accomplish that.
>
> My template might appear as follows:
>
> 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 should produce something like:
> import com.myco.MyClass;
> public Class AnotherClass {
> Integer v_1 = 0;
> Integer v_2 = 0;
> // ignore static type s_0
> }
>
> Given that each line of the nested blocks within template is indented
> further, there would need to be some marker in the template to indicate
> where indentation should be set for subsequent lines.
>
> import com.myco.MyClass;
> public Class AnotherClass {
> #setindent ## a new setindent directive
> #foreach ($t in $types)
> #if ($t.name.contains("_")
> Integer $t.name = 0;
> #if ($t.type == "static")
> // ignore static type $t.name
> #end
> #end
> #end
> }
>
> In this example, (there are probably better ways) a #setindent directive
> would specify the starting location for all subsequent lines. Velocity
> would use the whitespace before the #setindent directive as the amount to
> indent any text that is emitted. In this case, all leading whitespace
> would
> be ignored, and indentation would be controlled by the #setIndent
> directives.
>
> As I said, if this has been covered already, I'm sorry for the duplicate.
>
> Michael
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]