Paul Makepeace wrote:
I came up with a solution, but would rather something that's already in
core.

  $template->context->define_filter( scrunch => sub {
    my $data = $_[0];
    s/(?<=[^\w\s])\s+//g, s/\s+(?=[^\w\s])//g for $data;
    $data;
  });

Is there a way to have TT apply this filter to its whole output?

You could put the TT output into a variable like so:

my $process_result = $template->process($filename, \%vars, \$result);

Then just do your regular expression:
$result =~ foo;

The ideal solution would probably be a patch to handle this. It looks like there are CHOMP_ALL, 
CHOMP_COLLAPSE, and CHOMP_NONE constants for the POST_CHOMP and PRE_CHOMP config options, so it 
might be good to just add another one, "CHOMP_ALL_EVEN_AFTER_NEWLINE". (I'm sure there'd 
be a better name.) Or maybe a new config option "CHOMPS_GO_OVER_NEWLINES" might be better.

http://www.template-toolkit.org/docs/plain/Manual/Config.html references the current CHOMP constants. (None of which do what you want, since they only remove whitespace up to a newline rather than all whitespace.)
-- Josh

_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates

Reply via email to