Forum: Ruby ERB trim mode

Posted by Ramon de C Valle (rcvalle)
on 2013-01-09 17:37
Attachment: smime.p7s (4,36 KB)
(Received via mailing list)
Hi,

ERB documentation for Ruby 1.8.7 and Ruby 1.9.3 shows the following
modifiers for trim_mode:

%  enables Ruby code processing for lines beginning with %
<> omit newline for lines starting with <% and ending in %>
>  omit newline for lines ending in %>

However, I've seen in several discussions the '-' modifier. Looking at
ERB source, it seems it has different behavior for '>' and '-'. What is
the difference and what does the '-' modifier do?

Is a trim_mode of '%<>>' valid or '<>' and '>' are mutually exclusive?
If I understood correctly, the following listing from ERB source
indicates that '<>', '>', and '-' are mutually exclusive, and valid
trim_modes are the combination of the '%' with just one of the other
modifiers.

    def prepare_trim_mode(mode)
      case mode
      when 1
  return [false, '>']
      when 2
  return [false, '<>']
      when 0
  return [false, nil]
      when String
  perc = mode.include?('%')
  if mode.include?('-')
    return [perc, '-']
  elsif mode.include?('<>')
    return [perc, '<>']
  elsif mode.include?('>')
    return [perc, '>']
  else
    [perc, nil]
  end
      else
  return [false, nil]
      end
    end


Thanks,
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.