FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

indentation doesn't work well with HEREDOC strings in erb · Issue #361 · vim-ruby/vim-ruby · GitHub

Repository navigation

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

Description

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>

Activity

  1. graywolf commented on Nov 9, 2017

    Author
    • 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?
  2. AndrewRadev commented on Nov 19, 2017

    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.

  3. graywolf commented on Jan 31, 2018

    Author

    I'll just switch to

    <%=
    	foo <<~EOF
    	EOF
    %>
    

    thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL