db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Fischer <fisc...@seitenbau.net>
Subject Re: Velocity Templates
Date Mon, 10 Jul 2006 08:16:57 GMT
Hi,

The spaces in front of the velocity commands exist because it makes the
templates themselves readable. I'd put more emphasis on keeping the
templates readable than the generated code, so I'd rather leave the spaces
where they are.

     Thomas

"Thoralf Rickert" <thoralf.rickert@cadooz.de> schrieb am 10.07.2006
09:43:18:

> Hi!
>
> I think there is an open discussion thread (in 2005) about the generated
> code style in the Base* classes but I can't find it. The "problem" is
> that the generated code looks a little bit ugly because of too many
> spaces. This is a velocity problem, because of leading spaces in front
> of velocity commands like #if and #end.
>
> We've the same problem in one of our projects where we use velocity
> templates to render XHTML pages. There I made a small patch in our
> VelocityTemplateLoader to generate better code.
>
> Here is an example of a template:
>  public void helloWorld()
>  {
>    #if($useLog)
>      log.debug("Hello World called");
>    #else
>      System.out.println("Hello World called");
>    #end
>  }
>
> These leading spaces makes the code "unattractive" and sometimes
> unreadable. The patch is to remove any leading spaces in front of any
> velocity command. It's a line-by-line replacement regex with "^\s#" to
> "#". The result that is send to the renderer looks like this.
>
>  public void helloWorld()
>  {
> #if($useLog)
>      log.debug("Hello World called");
> #else
>      System.out.println("Hello World called");
> #end
>  }
>
>
> The solution is simple but doesn't fix every problem. Of course this
> could generate other problems. For example the following code compiles
> well without the patch.
>
> But with the patch it creates a velocity compile error, because of
> missing output between #if and #else
>
>  public void helloWorld()
>  {
>    #if($useLog)
>    #else
>      System.out.println("Hello World called");
>    #end
>  }
>
> If you're interested in such a patch I would make it for the
> torque-generator.
>
> bye
> Thoralf
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-dev-help@db.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org


Mime
View raw message