There was a thread on the Rails main which spawned this idea and I wanted to
mention it here in the sacred grounds of rails-core to see what the thoughts
were. I''m trying to gauge the perceived probability of this being a
worth-while patch.
This is currently a bit of rails code that I have repeated many times in
many applications.
<% for @row in @rows -%>
<%= start_form_tag %>
<%= text_field :row, :name %>
<%= hidden_field(:row, :id) %>
<%= end_form_tag %>
<% end -%>
Its a bit much with the <% and %>. It might be worth making a helper for
this code in an application, but then again, its probably not. Its hard to
read and repetitious.
Therefore, I am proposing the addition of this method in the parser.
def o(input)
_erabout << input + "\n"
end
Which would produce this in the most basic use.
<% o "hello" %>
<%= "hello %> #these two lines are equal
#Taking it a bit further
<% for user in @users
o user.name + "</br>"
end %>
#Now, to show how this could really increase code readability... here is a
re-write of the code earliest in this post.
<% for @row in @rows
o start_form_tag
o text_field(:row, :name)
o hidden_field(:row, :id)
o end_form_tag
end %>
Now, I am afraid of anyone of the temptation that will come to ex-PHP coders
who will want to start doing
<%
o "<img src=''hello.img''>"
o "<table>"
o myvar
%>
However, I believe this is a feature that, when used properly, could really
improve ERb readability. I would not suggest making this a
"recommended" way
to output information, but just a useful helper for creating excellent
looking ERb code.
Thoughts?
-hampton catlin
PS: I know this must seem trivial after the "Oracle Debacle of 2006".
_______________________________________________
Rails-core mailing list
Rails-core@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-core
On Thu, Apr 06, 2006 at 09:10:29PM -0400, Hampton wrote: [...]> #Now, to show how this could really increase code readability... here is a > re-write of the code earliest in this post. > > <% for @row in @rows > o start_form_tag > o text_field(:row, :name) > o hidden_field(:row, :id) > o end_form_tag > end %>No comment on whether this is a good idea in general. However, it would seem to me to make more sense to maintain the syntactic indicator that you''re inside a tag, and have it be this instead: <% for @row in @rows % start_form_tag % text_field(:row, :name) % hidden_field(:row, :id) % end_form_tag end %> -- - Adam ** Expert Technical Project and Business Management **** System Performance Analysis and Architecture ****** [ http://www.adamfields.com ] [ http://www.aquick.org/blog ] ............ Blog [ http://www.adamfields.com/resume.html ].. Experience [ http://www.flickr.com/photos/fields ] ... Photos [ http://www.aquicki.com/wiki ].............Wiki
> > #Now, to show how this could really increase code readability... here is a > > re-write of the code earliest in this post. > > > > <% for @row in @rows > > o start_form_tag > > o text_field(:row, :name) > > o hidden_field(:row, :id) > > o end_form_tag > > end %> > > No comment on whether this is a good idea in general. > > However, it would seem to me to make more sense to maintain the > syntactic indicator that you''re inside a tag, and have it be this > instead: > > <% for @row in @rows > % start_form_tag > % text_field(:row, :name) > % hidden_field(:row, :id) > % end_form_tag > end %>This is why we have Builder and default .rxml templates. If you have a big block of code you''d rather not mix with HTML, then make a partial that uses Builder. rhtml and rxml can be mixed and matched as you please. -- David Heinemeier Hansson http://www.loudthinking.com -- Broadcasting Brain http://www.basecamphq.com -- Online project management http://www.backpackit.com -- Personal information manager http://www.rubyonrails.com -- Web-application framework
I''m more referring to those instances when a full partial with Builder is a bit overkill but then again, line-by-line ERb is a little inelegant and awkward. I just feel that some system like this (and, I like Adam''s implementation better) would have low overhead and possibly enable more beautiful code in these "edge-cases". However, looks like this method will end up in my /lib ;) Thanks for the quick feedback. -hampton. On 4/6/06, David Heinemeier Hansson <david.heinemeier@gmail.com> wrote:> > > > #Now, to show how this could really increase code readability... here > is a > > > re-write of the code earliest in this post. > > > > > > <% for @row in @rows > > > o start_form_tag > > > o text_field(:row, :name) > > > o hidden_field(:row, :id) > > > o end_form_tag > > > end %> > > > > No comment on whether this is a good idea in general. > > > > However, it would seem to me to make more sense to maintain the > > syntactic indicator that you''re inside a tag, and have it be this > > instead: > > > > <% for @row in @rows > > % start_form_tag > > % text_field(:row, :name) > > % hidden_field(:row, :id) > > % end_form_tag > > end %> > > This is why we have Builder and default .rxml templates. If you have a > big block of code you''d rather not mix with HTML, then make a partial > that uses Builder. rhtml and rxml can be mixed and matched as you > please. > -- > David Heinemeier Hansson > http://www.loudthinking.com -- Broadcasting Brain > http://www.basecamphq.com -- Online project management > http://www.backpackit.com -- Personal information manager > http://www.rubyonrails.com -- Web-application framework > _______________________________________________ > Rails-core mailing list > Rails-core@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-core >_______________________________________________ Rails-core mailing list Rails-core@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails-core