Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Velocity Wiki" for 
change notification.

The following page has been changed by MichaelGiroux:
http://wiki.apache.org/jakarta-velocity/VelocityWhitespaceGobbleSetindentDirective

The comment on the change is:
Revise specification of #setindent based on mailing list suggestion

------------------------------------------------------------------------------
+ {{{
+ March 9, 2007 - revised description of proposed #setindent directive.
+ Based on comments in mailing list, the directive would specify an amount of 
indentation.
+ }}}
  For the most part, I want my templates to be readable and I use indenting to 
accomplish that.  The indenting of the template has nothing to do with the 
desired output.  For example, a simple template to generate a Java class might 
look like this:
  {{{ 
  import com.myco.MyClass;
@@ -33, +37 @@

  {{{ 
  import com.myco.MyClass;
  public Class AnotherClass {
+     #set ($indent = 4)
-     #setindent               ## a new setindent directive
+     #setindent($indent)               ## a new setindent directive
- #foreach ($t in $types)
+     #foreach ($t in $types)
-     #if ($t.name.contains("_")
+         #if ($t.name.contains("_")
-         Integer $t.name = 0;
+             Integer $t.name = 0;
-         #if ($t.type == "static")
+             #if ($t.type == "static")
-             // ignore static type $t.name
+                 // ignore static type $t.name
+             #end
+             void set${t.name}(Integer v) {
+             #set ($indent = $indent + 4)
+             #setindent($indent)
+                 // some code within the method block
+             #set ($indent = $indent - 4)
+             #setindent($indent)
+             }
          #end
      #end
- #end
  }
  }}} 
  
- In this example, a #setindent directive specifies the starting location for 
all subsequent lines.  Velocity would use the whitespace before the #setindent 
directive as the amount to indent any subsequent text that is emitted.
+ In this example, a #setindent directive specifies the amount of whitespace to 
inject at the start of each line of generated text and the template is managing 
a variable ($indent) to keep track of the indentation amount. This strategy 
assumes that all leading whitespace would be ignored, and indentation would be 
controlled exclusively by the #setindent() directives. 
  
- This strategy assumes that all leading whitespace would be ignored, and 
indentation would be controlled exclusively by the #setIndent directives. 
-  
+ This approach requires the template to manage an indentation variable 
($indent) and execute #setindent directives.  ''The template is pretty messy if 
there is not much text being generated.''  It would be nice if #setindent 
managed an internal variable and allowed the template to adjust the variable 
using absolute, increment and decrement values:
+ {{{
+ #setindent(4)  ## set indentation at 4 spaces
+ #setindent(+4) ## increment indentation by 4 spaces
+ #setindent(-4) ## decrement indentation by 4 spaces
+ }}}
+ 
+ This would result in a template like this:
+ {{{ 
+ import com.myco.MyClass;
+ public Class AnotherClass {
+     #setindent(4)               ## set indentation at 4 spaces
+     #foreach ($t in $types)
+         #if ($t.name.contains("_")
+             Integer $t.name = 0;
+             #if ($t.type == "static")
+                 // ignore static type $t.name
+             #end
+             void set${t.name}(Integer v) {
+                 #setindent(+4)   ## add 4 spaces to current indentation
+                 // some code within the method block
+                 #setindent(-4)   ## remove 4 spaces from current indentation
+             }
+         #end
+     #end
+ }
+ }}} 
+ 
+ 
  I realize that whitespace processing is much more complicated that 
indentation processing alone. This proposal only addresses how velocity could 
be enhanced to control indentation of generated text.  Other approaches can be 
reviewed at VelocityWhitespaceGobbling.
  

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

Reply via email to