On 3/7/07, Daniel Berger <djberg96 / gmail.com> wrote:
> On Sep 27 2005, 7:55 am, "Phrogz" <g... / refinery.com> wrote:
> > Summary:
> > a) Is there a way to ask ERB to trim leading whitespace between the
> > start-of-line and a '<%'? (The equivalent of .gsub( /^\s+<%/, '<%' ) If
> > not, I suggest that one should exist.
>
> I second this.

Reading the source revealed this: There is '-' ('explicit trim') mode,
that allows this behaviour. You need to use <%- and -%> wherever you
want to have whitespace stripped (whitespace = spaces & tabs before,
newline after)

This mode is undocumented (anyone patch?).

> > b) What is up with the crazy syntax for the third param to ERB? Could
> > we perhaps come up with a cleaner, less-ambiguous way to specify
> > various parsing options? Hash options? One char per flag?
>
> And this one, too.

Mode can be specified either as a string ('-', '%-', '>', '%>', '<>',
'%<>') or a number (0 = '', 1 = '>', 2 = '<>'). Maybe there should be
or-flags like:

PERCENT_LINES | TRIM_NEWLINE_BEFORE | TRIM_NEWLINE_AFTER |
TRIM_WHITESPACE_BEFORE

with shortcuts like

PERCENT_AND_TRIM_NEWLINES ~ '%<>'

Maybe for a start a few constants naming the various modes would be nice

It shouldn't be that hard... look for prepare_trim_mode and then for
the various scanners.

-----------------------------------8<-----------------

require 'erb'

desired_template = <<ENDTEMPLATE
Hello
<%-
     4.times{
             -%>
             BLING
             <%-
         }
-%>
World
ENDTEMPLATE

ERB.new( desired_template, nil, '-' ).run