Forum: Ruby on Rails Native erb lacks -%>, where is Rails' erb?

457cf540784a12ba2f30e06565a2c189?d=identicon&s=25 Hugh Sasse (Guest)
on 2006-02-20 13:25
(Received via mailing list)
Native ERB in ruby, and eruby, seem to lack the -%> feature for
suppressing trailing newlines.  Thus
erb -n script
gives errors.  Where is Rails ERB so I can invoke it directly?
        Thank you
        Hugh
3ccecc71b9fb0a3d7f00a0bef6f0a63a?d=identicon&s=25 Kent Sibilev (Guest)
on 2006-02-20 15:05
(Received via mailing list)
It's a standard library located in /usr/local/lib/ruby/1.8/erb.rb

In order to enable a trim mode -%> you have to instantiate ERB object
with trim mode parameter like

e = ERB.new(str, nil, '-')

--
Kent
---
http://www.datanoise.com
457cf540784a12ba2f30e06565a2c189?d=identicon&s=25 Hugh Sasse (Guest)
on 2006-02-20 15:50
(Received via mailing list)
On Mon, 20 Feb 2006, Kent Sibilev wrote:

> It's a standard library located in /usr/local/lib/ruby/1.8/erb.rb
>
> In order to enable a trim mode -%> you have to instantiate ERB object
> with trim mode parameter like
>
> e = ERB.new(str, nil, '-')

Ah, so I need erb -T - file

  -T [trim_mode]   specify trim_mode (0..2, -)

Thank you.   I couldn't find that before, but trim mode was the key.
>
> --
> Kent

        Hugh
B0d6fda6fabb8cda27b5e6dde2dc2ac3?d=identicon&s=25 Simo Addsw (gal)
on 2006-02-20 17:00
> In order to enable a trim mode -%> you have to instantiate ERB object
> with trim mode parameter like
>
> e = ERB.new(str, nil, '-')
>


Inside rails, I add the following line in my
config/custom_environment.rb

  ActionView::Base.erb_trim_mode='%<>-'

that enables all erb options

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

Simo
 AddSW
457cf540784a12ba2f30e06565a2c189?d=identicon&s=25 Hugh Sasse (Guest)
on 2006-02-20 17:13
(Received via mailing list)
On Mon, 20 Feb 2006, Simo Gal wrote:

> Inside rails, I add the following line in my
> config/custom_environment.rb
>
>   ActionView::Base.erb_trim_mode='%<>-'
>
> that enables all erb options
>
>     %  enables Ruby code processing for lines beginning with %
>     <> omit newline for lines starting with <% and ending in %>
>     >  omit newline for lines ending in %>

by which I think you meant:

      -  omit newline for lines ending in -%>

Thank you.  My problem was how to reproduce it outside rails, but this
is good to know too.
>
> Simo
>  AddSW
>
        Hugh
455ac2a64d06dc8461f4d258d7f7e980?d=identicon&s=25 Michael Trier (Guest)
on 2006-02-20 18:30
(Received via mailing list)
I really like the % option, but it doesn't seem to be something that's
embraced in the community.  Why is that?

Michael
3ccecc71b9fb0a3d7f00a0bef6f0a63a?d=identicon&s=25 Kent Sibilev (Guest)
on 2006-02-20 19:16
(Received via mailing list)
Maybe that because there is a recommendation to use helpers for cases
that require an even slightly more complicated logic in views.


On 2/20/06, Michael Trier <mtrier@gmail.com> wrote:
> I really like the % option, but it doesn't seem to be something that's
> embraced in the community.  Why is that?
>
> Michael
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>


--
Kent
---
http://www.datanoise.com
455ac2a64d06dc8461f4d258d7f7e980?d=identicon&s=25 Michael Trier (Guest)
on 2006-02-20 19:28
(Received via mailing list)
Perhaps, but I'm not really advocating doing anything more than:

% for list in @lists
<tr>list.name</tr>
% end

To me that's six characters with shift keys that I don't have to type.
:)

Michael
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.