This project is archived and is in readonly mode.
content_tag should accept block using variable
-
wildchild
Nice proposal! Where is a patch?
-
ronin-23439 (at lighthouseapp)
I would have submitted one but I'm not sure how to do it without breaking compatibility with the standard use in the view.
-
Clemens Kofler
I don't like this idea at all. If you feel that you have to do something complex like modifying the output multiple times, you should consider refactoring it out into a helper method.
-
Glenn Powell
Clemens, I don't really understand what the problem is with this proposal. I don't see why this:
content_tag(:p) do |content| content << fetch_value content << fetch_value(2) content << another_value endwould be any worse than what you have to do now which is:
content_tag(:p) do content = "" content << fetch_value content << fetch_value(2) content << another_value content endAnd I believe the point was that this whole call should in fact be in a helper method, as stated in the original post, but that it would be nicer to have the content variable passed to the content_tag block.
-
Clemens Kofler
Glenn, I see your point but I still think the only way to keep it really clean is a helper method - and while I do care about style in the helper, I don't care that much that the two examples you gave would really make a difference for me. I didn't like the whole "view helpers now accept blocks" thing in the first place because IMO it clutters up the view (like when you use the block style with link_to), so I may be biased here ...
-
Tom Lea
- Tag changed from content_tag, enhancement, helper, view to content_tag, enhancement, helper, patch, view
What about...
content_tag(:p) do returning("") do |content| content << fetch_value content << fetch_value(2) content << another_value end end...as a middle ground?
Either way, I've attached a patch to do what you describe... but I don't think it's quite what's needed yet.
Issue:
content += "fish" will simply loose the initial object reference. This would be a bit of a suprise for some users.
Fix:
Use a subclass of String that aliases += to << or similar.
Enhancement:
Allow something as follows:
content_tag(:div) do |div| my_text.each_line do |line| div.content_tag(:p, line) end endbut if we allow this, we would also want to allow:
content_tag(:div) do |div| div.form_for(:magic) do |f| ... end endSo we would end up having to proxy calls to all helpers... eugh!
-
DHH
- State changed from new to wontfix
I think this is probably too clever for its own good when it has to work in the view too.
