[Haml] Have form_for and sometimes form_tag return ErrorReturns.

This commit is contained in:
Nathan Weizenbaum 2010-02-28 20:30:39 -08:00
parent ce7fe5a469
commit 9f739121b9
3 changed files with 30 additions and 1 deletions

View File

@ -96,6 +96,13 @@ of the many and varied [Haml implementations](http://en.wikipedia.org/wiki/Haml#
Haml now supports a {file:HAML_REFERENCE.md#css-filter `:css` filter}
that surrounds the filtered text with `<style>` and CDATA tags.
### Rails Support
* When `form_for` is used with `=`, or `form_tag` is used with `=` and a block,
they will now raise errors explaining that they should be used with `-`.
This is similar to how {Haml::Helpers#haml\_concat} behaves,
and will hopefully clear up some difficult bugs for some users.
### `html2haml` Improvements
* Ruby blocks within ERB are now supported.

View File

@ -146,7 +146,10 @@ module ActionView
concat haml_indent
end
res = form_tag_without_haml(url_for_options, options, *parameters_for_url, &proc) + "\n"
concat "\n" if block_given?
if block_given?
concat "\n"
return Haml::Helpers::ErrorReturn.new("form_tag")
end
res
else
form_tag_without_haml(url_for_options, options, *parameters_for_url, &proc)
@ -170,6 +173,7 @@ module ActionView
end
form_for_without_haml(object_name, *args, &proc)
concat "\n" if block_given? && is_haml?
Haml::Helpers::ErrorReturn.new("form_for") if is_haml?
end
alias_method :form_for_without_haml, :form_for
alias_method :form_for, :form_for_with_haml

View File

@ -184,6 +184,24 @@ class TemplateTest < Test::Unit::TestCase
assert_equal("2\n", render("= 1+1"))
end
def test_form_for_error_return
assert_raise(Haml::Error) { render(<<HAML) }
= form_for :article, @article, :url => '' do |f|
Title:
= f.text_field :title
Body:
= f.text_field :body
HAML
end
def test_form_tag_error_return
assert_raise(Haml::Error) { render(<<HAML) }
= form_tag '' do
Title:
Body:
HAML
end
def test_haml_options
old_options = Haml::Template.options.dup
Haml::Template.options[:suppress_eval] = true