is_haml? gives the right result (false) for non-Haml partials. This means that form_for and stuff like that in partials should work properly.

git-svn-id: svn://hamptoncatlin.com/haml/trunk@485 7063305b-7217-0410-af8c-cdc13e5119b9
This commit is contained in:
nex3 2007-04-05 19:09:07 +00:00
parent b4b6b83dc6
commit 16f2729279
4 changed files with 32 additions and 11 deletions

View File

@ -203,6 +203,7 @@ END
def do_precompile def do_precompile
push_silent <<-END push_silent <<-END
def _haml_render def _haml_render
@haml_is_haml = true
_hamlout = @haml_stack[-1] _hamlout = @haml_stack[-1]
_erbout = _hamlout.buffer _erbout = _hamlout.buffer
END END
@ -266,6 +267,7 @@ END
# Close all the open tags # Close all the open tags
@template_tabs.times { close } @template_tabs.times { close }
push_silent "@haml_is_haml = false"
push_silent "end" push_silent "end"
end end

View File

@ -313,7 +313,7 @@ module Haml
# also works in other ActionView templates, # also works in other ActionView templates,
# where it will always return false. # where it will always return false.
def is_haml? def is_haml?
@haml_stack ? @haml_stack.size > 0 : false @haml_is_haml
end end
include ActionViewExtensions if self.const_defined? "ActionViewExtensions" include ActionViewExtensions if self.const_defined? "ActionViewExtensions"

View File

@ -10,6 +10,17 @@ end
if action_view_included if action_view_included
module ActionView module ActionView
class Base # :nodoc:
def render_with_haml(*args)
was_haml = is_haml?
@haml_is_haml = false
res = render_without_haml(*args)
@haml_is_haml = was_haml
res
end
alias_method_chain :render, :haml
end
# This overrides various helpers in ActionView # This overrides various helpers in ActionView
# to make them work more effectively with Haml. # to make them work more effectively with Haml.
module Helpers module Helpers
@ -27,18 +38,22 @@ if action_view_included
module FormTagHelper module FormTagHelper
def form_tag_with_haml(url_for_options = {}, options = {}, *parameters_for_url, &proc) def form_tag_with_haml(url_for_options = {}, options = {}, *parameters_for_url, &proc)
if block_given? && is_haml? if is_haml?
oldproc = proc if block_given?
proc = bind_proc do |*args| oldproc = proc
concat "\n" proc = bind_proc do |*args|
tab_up concat "\n"
oldproc.call(*args) tab_up
tab_down oldproc.call(*args)
tab_down
end
end end
res = form_tag_without_haml(url_for_options, options, *parameters_for_url, &proc) + "\n"
concat "\n" if block_given? && is_haml?
res
else
form_tag_without_haml(url_for_options, options, *parameters_for_url, &proc)
end end
res = form_tag_without_haml(url_for_options, options, *parameters_for_url, &proc) + "\n"
concat "\n" if block_given? && is_haml?
res
end end
alias_method_chain :form_tag, :haml alias_method_chain :form_tag, :haml
end end

View File

@ -101,6 +101,10 @@ class HelperTest < Test::Unit::TestCase
def test_is_haml def test_is_haml
assert(!ActionView::Base.new.is_haml?) assert(!ActionView::Base.new.is_haml?)
assert_equal("true\n", render("= is_haml?"))
assert_equal("true\n", render("= is_haml?", :action_view))
assert_equal("false", @base.render(:inline => '<%= is_haml? %>'))
assert_equal("false\n", render("= render :inline => '<%= is_haml? %>'", :action_view))
end end
def test_page_class def test_page_class