[Templates] Chomping without joining lines
[prev]
[thread]
[next]
[Date index for 2004/12/15]
I am using TT2 for generating Apache configuration files. (This is done
offline, ie before running Apache, not under mod_perl.)
I can't figure out a simple way to use any of TT2's flavors of chomp in
this context, since unlike in TT2's main target, HTML, it is not OK to
join lines. For example:
User apache Group apache
is just not the same as:
User apache
Group apache
I believe it's possible in Apache to have such joinings lead to
configuration lines that are effectively hidden without giving a syntax
error, so it is very important that the solution be simple and reliable.
It's conceivable that there is a pattern of chomp options and the usage
of such flags as -%] to make this work, but I think it would likely be
far too delicate.
My workaround has been to turn off all chomp options, avoid all '-%]'
flags in directives, and have the front-end driver program pass the
final output through a filter:
sub ttchomp_ref {
my $text = shift ;
my @lines = split (/\n/, $$text) ;
my $joined = join ("\n", grep (/\S/ && !/^\s*#-/ , @lines) ) ;
return \$joined ;
}
If I want a little spacing in the output, I need to code an explicit
"#" line. This method has a little added value of providing for a
TT-level comment (here indicated by "#-" as first white space) that
is removed from the final output, as well as preserving indentation.
Is there a better way of doing this?
Are there plans for adding any flavors of chomp that are less aggressive
about removing newlines?
Thanks,
-Len
_______________________________________________
templates mailing list
templates@xxxxxxxxxxxxxxxx.xxx
http://lists.template-toolkit.org/mailman/listinfo/templates
 |
[Templates] Chomping without joining lines
Len Weisberg 18:11 on 15 Dec 2004
|