Re: Leading/trailing newlines

"C.J. Adams-Collier" <[email protected]> Sun, 23 Sep 2007 08:02:31 -0700
Newsgroups gmane.comp.web.mason.devel
Message-ID <[email protected]>
If I'm picking up what you're laying down, this would happen for each
comp() call.  This would be too expensive.  The filter would need to
be applied once, most likely at compile time.

sorry for the terse.  baby in left hand

oh, and write tests

On 9/23/07, Alex Robinson <[email protected]> wrote:
> Prompted by CJ's mention of stripping out redundant whitespace I
> thought I'd revisit the subject.
>
> I note the two tickets on the todo list (405, 459).
>
> I'd like to suggest a potential solution.
>
> If line 1219 of Request.pm (1.37) was changed like so:
>
> -my $stack_buffer = $comp->{has_filter} ? \$filter_buffer : $top_buffer;
> +my $stack_buffer =\$filter_buffer;
>
> this would then allow something like this (assuming the existence of
> a configuration parameter filter_newlines) to be added after line 1280
>
> >>>
> else {
>          if ($self->{interp}->{filter_newlines}) {
>                  $filter_buffer =~ s/^\n+//;
>                  $filter_buffer =~ s/\n+$//;
>          }
>          $$top_buffer .= $filter_buffer;
>      }
> <<<
>
> which would soak up all leading and trailing whitespace on components
> without explicit filters which would take precedence. So to not
> remove the space would simply require adding an empty filter block
>
>
> Although that would perhaps do, I'd like to suggest that the
> configuration parameter shouldn't be a simple on/off toggle, but
> allow the following options (with 'none' the default for backwards
> compatibility)
>
>     filter_newlines => none | one | all
>
> And allow for component flags block to have the same parameter with
> the same possible values to allow for overriding on a component by
> component basis.
>
> This would allow for something like:
>
> >>>
> my $filter_newlines = $comp->{flags}->{filter_newlines} ||
> $self->{interp}->{filter_newlines};
>
> if ($filter_newlines and $filter_newlines ne 'none') {
>      my $lines_to_filter = $filter_newlines eq 'all' ? '' : '1';
>      $filter_buffer =~ s/^\n{1,$lines_to_filter}//;
>      $filter_buffer =~ s/\n{1,$lines_to_filter}$//;
> }
>
> $$top_buffer .= $filter_buffer;
> <<<
>
> If done this way, this could be done in addition to any filter the
> component actually has. Or again, the filter could be used to
> override the auto stripping entirely.
>
>
>
> Thoughts?
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2005.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> Mason-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/mason-devel
>


-- 
moo.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/