Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERB leading newline / whitespace supression with hyphen does not work as documented. #16766

Closed
cirosantilli opened this issue Sep 2, 2014 · 3 comments

Comments

@cirosantilli
Copy link
Contributor

The docs for 4.1.5 say http://api.rubyonrails.org/classes/ActionView/Base.html:

<%- and -%> suppress leading and trailing whitespace, including the trailing newline

However I have tested with things like:

a
<%- true %>b

a
<%- true -%>b

and the leading newline does not get removed. Am I doing something wrong, or is it a documentation bug?

My tests:

I have the same behavior for pure Ruby 2.1 ERB, which I think Rails is using with trim_options = '-'. But it seems that Rails does some preprocessing (pure Ruby does not remove trailing spaces: only the newline), so I'm not sure it it's relevant.

@rafaelfranca
Copy link
Member

It only remove the line it is present if it is empty. Also this is a behaviour of erubis not Rails

@cirosantilli
Copy link
Contributor Author

OK finally I understand: erubis removes the line of <%- only if it's the only thing on that line:

a\n <%- true %> \nb

becomes:

a\nb

@rafaelfranca can I make a PR to say on the docs http://api.rubyonrails.org/classes/ActionView/Base.html that Rails uses erubis and link to it's doc so that people can find out precisely how the templates work? Otherwise it is too hard to find out.

@rafaelfranca
Copy link
Member

Sure! Feel free to open a PR updating the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants