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

indentation doesn't work well with HEREDOC strings in erb #361

Open
graywolf opened this issue Nov 9, 2017 · 3 comments
Open

indentation doesn't work well with HEREDOC strings in erb #361

graywolf opened this issue Nov 9, 2017 · 3 comments
Labels

Comments

@graywolf
Copy link

graywolf commented Nov 9, 2017

When writing eruby file and using HEREDOC syntax, the indentation doesn't work that well. This is what vim produces when using default indentation:

<!DOCTYPE html>
<html>
  <head>
    </title>Foo</title>
  </head>
  <body>
    <%= foo <<~EOF
    EOF
  %>
  </body>

The ending %> is off by one level to the left. I believe it should be like this:

</html>
<!DOCTYPE html>
<html>
  <head>
    </title>Foo</title>
  </head>
  <body>
    <%= foo <<~EOF
    EOF
    %>
  </body>
</html>
@graywolf
Copy link
Author

graywolf commented Nov 9, 2017

  • bracket matching doesn't also work; when on the > in %>, tha highlighted bracket is on second < in <<~EOF while it should be on < in <%=. Is this plugin also responsible for it?

@AndrewRadev
Copy link
Member

The indenting thing is a tricky issue. In general, there are two styles that eruby is mostly able to handle:

<div>
  <%= foo = {
    bar: 'baz'
  } %>
</div>

<div>
  <%=
    foo = {
      bar: 'baz'
    }
  %>
</div>

The mixture of the two doesn't work for a lot of other things:

<div>
  <%= foo = {
    bar: 'baz'
  }
%>
</div>

In the heredoc case, unfortunately, the first format is syntactically invalid, because heredocs expect the end delimiter to be on its own line. Honestly, I wouldn't use a heredoc in ERB for that reason alone, it seems pretty fiddly regarding whitespace. You could use the %{ } delimiter, and that seems to work well with the closing ERB delimiter:

<div>
  <%= foo = %{
    String content
  } %>
</div>

You could also use the second kind of indenting, like this:

<div>
  <%=
    foo <<~EOF
      Bla
    EOF
  %>
</div>

I understand that, ideally, putting a closing delimiter at the right indent level should work regardless. It's a difficult problem to fix, though, and I really don't think anybody right now would have the time and energy to put into fixing it. I'll leave this issue open, because it's valid, but I'd recommend you try out a different indentation style.

As for the highlighting, it seems to me like it's built-in and not really customizable.

@graywolf
Copy link
Author

I'll just switch to

<%=
	foo <<~EOF
	EOF
%>

thanks :)

@dkearns dkearns added the indent label Dec 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants