Native erb lacks -%>, where is Rails' erb?


#1

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


#2

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


#3

On Mon, 20 Feb 2006, Kent S. 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

#4

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


#5

I really like the % option, but it doesn’t seem to be something that’s
embraced in the community. Why is that?

Michael


#6

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 T. removed_email_address@domain.invalid 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
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails


Kent

http://www.datanoise.com


#7

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

#8

Perhaps, but I’m not really advocating doing anything more than:

% for list in @lists

list.name % end

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

Michael