Indentation issue w/ nested ERB #188

Open
barunio opened this Issue Nov 19, 2013 · 4 comments

4 participants

@barunio

Indentation doesn't work properly for me when dealing with nested elements under multi-line erb statements. Specifically, I want to produce something like this:

<%= form_for my_object, 
             class: 'css_classname_here',
             remote: true do |form| %>

  <%= form.field :text_field, :blah %>

<% end %>

But instead, this happens:

<%= form_for my_object, 
             class: 'css_classname_here',
             remote: true do |form| %>

             |<--cursor gets indented to here

Even when manually fixing the indentation, a variety of actions can cause it to re-indent to the wrong place.

Vim's built-in indenting behavior displays the same behavior, but it would be great if vim-ruby was smarter about this.

@graywh

The latest version of vim-ruby indents your example like this:

<%= form_for my_object, 
  class: 'css_classname_here',
  remote: true do |form| %>

  <%= form.field :text_field, :blah %>

<% end %>

I think your issue is caused by adding additional indent to line 2, which propagates to all following lines.

@barunio

@graywh That makes sense as a cause, but indenting just by two spaces on the second line (as in your example) doesn't work well in terms of readability in an ERB file. It would be great if there was a way for the indentation script to find the opening <% and indent based on that, even if there are additional spaces on successive lines of the ERB statement. Is that feasible?

@fuadsaud

yeah, I kind of second @barunio. It would be good if that second line could be indented after the ruby code beginning, not the <%.

@bpinto

It's perfect the way it is. Don't listen to them! 👻

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