[Haml] Fix some form_tag nuttiness.

Closes gh-227
This commit is contained in:
Nathan Weizenbaum 2010-08-08 00:47:10 -07:00
parent 7a55155a04
commit b1c1319ec7
3 changed files with 27 additions and 7 deletions

View File

@ -11,6 +11,9 @@
* Fix parsing of `if` and `case` statements whose values were assigned to variables.
This is still bad style, though.
* Fix `form_for` and `form_tag` when they're passed a block that
returns a string in a helper.
## 3.0.15
[Tagged on GitHub](http://github.com/nex3/haml/commit/3.0.15).

View File

@ -140,7 +140,8 @@ module ActionView
module FormTagHelper
def form_tag_with_haml(url_for_options = {}, options = {}, *parameters_for_url, &proc)
if is_haml?
if block_given?
wrap_block = block_given? && block_is_haml?(proc)
if wrap_block
oldproc = proc
proc = haml_bind_proc do |*args|
concat "\n"
@ -148,7 +149,7 @@ module ActionView
end
end
res = form_tag_without_haml(url_for_options, options, *parameters_for_url, &proc) + "\n"
res << "\n" if block_given?
res << "\n" if wrap_block
res
else
form_tag_without_haml(url_for_options, options, *parameters_for_url, &proc)
@ -160,12 +161,13 @@ module ActionView
module FormHelper
def form_for_with_haml(object_name, *args, &proc)
if block_given? && is_haml?
wrap_block = block_given? && is_haml? && block_is_haml?(proc)
if wrap_block
oldproc = proc
proc = proc {|*args| with_tabs(1) {oldproc.call(*args)}}
end
res = form_for_without_haml(object_name, *args, &proc)
res << "\n" if block_given? && is_haml?
res << "\n" if wrap_block
res
end
alias_method :form_for_without_haml, :form_for
@ -191,7 +193,8 @@ module ActionView
module FormTagHelper
def form_tag_with_haml(url_for_options = {}, options = {}, *parameters_for_url, &proc)
if is_haml?
if block_given?
wrap_block = block_given? && block_is_haml?(proc)
if wrap_block
oldproc = proc
proc = haml_bind_proc do |*args|
concat "\n"
@ -218,7 +221,8 @@ module ActionView
module FormHelper
def form_for_with_haml(object_name, *args, &proc)
if block_given? && is_haml?
wrap_block = block_given? && is_haml? && block_is_haml?(proc)
if wrap_block
oldproc = proc
proc = haml_bind_proc do |*args|
tab_up
@ -229,7 +233,7 @@ module ActionView
concat haml_indent
end
form_for_without_haml(object_name, *args, &proc)
concat "\n" if block_given? && is_haml?
concat "\n" if wrap_block
Haml::Helpers::ErrorReturn.new("form_for") if is_haml?
end
alias_method :form_for_without_haml, :form_for

View File

@ -5,6 +5,10 @@ class ActionView::Base
def nested_tag
content_tag(:span) {content_tag(:div) {"something"}}
end
def wacky_form
form_tag("/foo") {"bar"}
end
end
module Haml::Helpers
@ -176,6 +180,15 @@ HTML
HAML
end
def test_form_tag_in_helper_with_string_block
def @base.protect_against_forgery?; false; end
assert_equal(<<HTML, render(<<HAML, :action_view))
<form #{rails_form_attr}action="/foo" method="post">#{rails_form_opener}bar</form>
HTML
#{rails_block_helper_char} wacky_form
HAML
end
def test_haml_tag_name_attribute_with_id
assert_equal("<p id='some_id'></p>\n", render("- haml_tag 'p#some_id'"))
end