I'd like to unindent a block of ERB specifically to combat the extra
spacing being added to content inside <textarea> 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:
<html ...>
__<%= render 'form' %>
</html>
_form.erb:
<% form_for ... do %>
__<%= render 'unindented' %>
<% end %>
_unindented.erb:
<textarea><%= 'this is unindented' %></textarea>
which would output something along the line of:
<html ...>
__<form ...>
____<textarea>this is unindented</textarea>
__</form>
</html>
I want something to this effect:
<html ...>
__<form ...>
<textarea>this is unindented</textarea>
__</form>
</html>
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.
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
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.
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 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.
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?
<% form_for ... do %>
__<%- safe_concat '<textarea>this is unindented</textarea> %>
<% end %>
which would output:
<html ...>
__<form ...>
__<textarea>this is unindented</textarea>
__</form>
</html>
The question is why that matters to you. On screen or print it should
look exactly the same as
<html ...>
<form ...>
<textarea>this is unindented</textarea>
</form>
</html>
OK, that is not the problem you originally asked. From your first
message you have
<textarea><%= 'this is unindented' %></textarea>
which is not the above situation at all.
Can you show me the erb you are using to generate the problem code you
are now showing?
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 <html>,
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 <textarea> to keep
the formatting we want.