Skip to content

Commit

Permalink
[Haml] Fix some form_tag nuttiness.
Browse files Browse the repository at this point in the history
Closes gh-227
  • Loading branch information
nex3 committed Aug 8, 2010
1 parent 7a55155 commit b1c1319
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
3 changes: 3 additions & 0 deletions doc-src/HAML_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
18 changes: 11 additions & 7 deletions lib/haml/helpers/action_view_mods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,16 @@ def content_tag(*args)
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"
with_tabs(1) {oldproc.call(*args)}
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)
Expand All @@ -160,12 +161,13 @@ def form_tag_with_haml(url_for_options = {}, options = {}, *parameters_for_url,

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
Expand All @@ -191,7 +193,8 @@ def fragment_for_with_haml(*args, &block)
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"
Expand All @@ -218,7 +221,8 @@ def form_tag_with_haml(url_for_options = {}, options = {}, *parameters_for_url,

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
Expand All @@ -229,7 +233,7 @@ def form_for_with_haml(object_name, *args, &proc)
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
Expand Down
13 changes: 13 additions & 0 deletions test/haml/helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -176,6 +180,15 @@ def @base.protect_against_forgery?; false; end
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
Expand Down

0 comments on commit b1c1319

Please sign in to comment.