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

newline-handling problem in Sinatra's erb implementation #1228

Closed
RichMorin opened this issue Jan 2, 2017 · 3 comments
Closed

newline-handling problem in Sinatra's erb implementation #1228

RichMorin opened this issue Jan 2, 2017 · 3 comments

Comments

@RichMorin
Copy link

RichMorin commented Jan 2, 2017

The Embedded Ruby implementation for Sinatra (1.4.7) removes (some) newlines. Basically, if an interpolated string is on a line by itself (no text either before or after), the newline goes away. The Ruby (2.0.0p481) ERB library does not exhibit this problem.

See https://gist.github.com/RichMorin/055bb69484207885ab51e7cdd6ac44dd for details.

-r

P.S. I tried posting this to the mailing list, but (like a post I made a couple of weeks ago) it was held for review. Hello?

@mwpastore
Copy link
Member

mwpastore commented Jan 2, 2017

Sinatra uses Tilt behind the scenes to dispatch calls to its render helper (and associated erb, haml, etc. helpers) to different rendering engines. When Tilt invokes ERB, it sets trim_mode to <> by default, which "omits newlines for lines starting with <% and ending in %>." Your call to ERB sets trim_mode to nil (by dint of your not including it in the call), so it doesn't trim anything.

This is the source of the inconsistency in your results. To align the results, you can either:

  1. Set :trim to false in your call to erb (see here)
  2. Set trim_mode to <> in your call to ERB.new
  3. Use an alternate ERB implementation such as Erubis or Erubi

I'll defer the mailing list question to @zzak! I'm not sure if anyone is moderating it; last time I looked at it there had only been a handful of posts in the past year.

@RichMorin
Copy link
Author

Thanks for clarifying the situation and suggesting alternatives.

@zzak
Copy link
Member

zzak commented Jan 3, 2017

Here is fine, I'm not sure anyone really uses the Mailing List anymore.

We also have slack.

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

3 participants