I’d like to unindent a block of ERB specifically to combat the extra
spacing being added to content inside by the browser. Is
there such a feature in ERB?
I shall denote indentation with underscores in the pseudo code example
below.
Thanks in advance,
Khoan.
myview.erb:
__<%= render 'form' %>
_form.erb:
<% form_for … do %>
__<%= render ‘unindented’ %>
<% end %>
I don’t think so, have you tried it and checked the html (View > Page
Source or similar in the browser). The line
__<%= render ‘unindented’ %>
says output underlines then render unindented. There is no way that
you can remove the underlines before the <%= render %>. However why
not just put, at the start of the line
<%= render ‘unindented’ %>
However I do not understand why it matters. None of this will give
you extra space inside the textarea.
Colin, i’m just clarifying what the OP meant. He replaced the tabs/spaces
with underscores so it would be easy to picture.
He wanted to remove the indentation for the textarea tag so it would be
in
line with the html tag when you look at the
html source.
To the OP, I don’t think there’s an erb option that would give you what
you
want.
Colin, i’m just clarifying what the OP meant. He replaced the tabs/spaces
with underscores so it would be easy to picture.
He wanted to remove the indentation for the textarea tag so it would be in
line with the html tag when you look at the
html source.
To the OP, I don’t think there’s an erb option that would give you what you
want.
I Knew that, I also was showing underscores for spaces. The point is
that only spaces that the op includes in the erb will be copied
through to the html.
To solve the indentation problem, don’t indent the tags in your
templates. You may have to experiment, but the result should be what
you want.
With ERB I’ve found that I can have either nicely aligned templates,
or somewhat nicely aligned HTML output. I write “somewhat” because it
never seems to be quite right, and the whole thing seems ugly and
awkward (surprising in Rails-land).
If anyone has a solution for this problem (besides Haml), please
respond.
The other common issue is empty lines between code blocks. With Erubis
you can fix this by changing closing tags from “%>” to “-%>”.
I’m using Rails 3. Erubis is using some XML::Builder with indent set
to 2.
I suspect Haml won’t be of help either, since it’ll delegate to Erubis
at some point.
the <%- only unindents a block to align with its closests <%= render
parent. Can’t go further than that.
I don’t understand why you are worried about additional whitespace in
the html. It should not make any difference to what is displayed.
Can you show an exact example of the problem html and explain why it
matters?
The app is using formtastic to generate the textarea. I’ve watered it
down to the barebone code provided in the first post.
If we can unindent the <%= render ‘unindent’ %> to align with ,
then we have a winner. So far I fathom that this is not possible. Work
around would be to apply some js solution on the to keep
the formatting we want.