1

I have a problem in Sinatra with ERB templating engine. Partials are rendered with wrong indention.

There is no custom helpers, or sinatra-partial gem, just vanilla Sinatra. Also have 'sinatra-contrib' installed, if it makes any difference.

Editor is Sublime Text, and all files use spaces for indention. Sublime Text has ensure_newline_at_eof_on_save setting enabled (I tried to disable it, but it gives no difference).

Views structure

views
   |- layouts
       |- application.erb
   |- main
       |- index.erb
   |- partials
       |- header.erb

layouts/application.erb

<html>
  <body>
    <%= yield %>
  </body>
</html>

main/index.erb

<article>
  <%= erb :'partials/header', layout: false %>
</article>

partials/header.erb

<header>
  <h1>Newsletter</h1>
</header>

Renders HTML

<html>
  <body>
    <article>

  <header>
  <h1>Newsletter</h1>
</header>

</article>

  </body>
</html>
Ilya Cherevkov
  • 1,743
  • 2
  • 17
  • 47
  • Why does it matter? Does the page look wrong? Is the HTML malformed? – Tom Lord Dec 04 '18 at 23:44
  • @TomLord Everything works as expected, except indention is not pretty. I guess I'll have to live with that – Ilya Cherevkov Dec 05 '18 at 08:07
  • Does it even matter that the indentation isn't pretty? When you inspect anything in the browser, it auto-prettifies the HTML whitespace for you regardless. – Tom Lord Dec 05 '18 at 09:34
  • 2
    I've had similar problems with ERB in the past and found no way to properly fix it, [as have others](https://stackoverflow.com/q/53167613/335847). – ian Dec 07 '18 at 13:02
  • @TomLord, maybe i'm missing something, but my browsers don't auto-pretiffy anything – Ilya Cherevkov Dec 18 '18 at 10:37
  • 1
    @icherevkov Right click --> Inspect. Don't "view page source". – Tom Lord Dec 18 '18 at 16:25
  • @TomLord yes, thanks. I never payed attention inspector actually prettifies html. although, my inner perfectionist is not satisfied – Ilya Cherevkov Jan 10 '19 at 09:25

0 Answers0