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:
parent
b4b6b83dc6
commit
16f2729279
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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"
|
||||||
|
|
|
@ -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,7 +38,8 @@ 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?
|
||||||
|
if block_given?
|
||||||
oldproc = proc
|
oldproc = proc
|
||||||
proc = bind_proc do |*args|
|
proc = bind_proc do |*args|
|
||||||
concat "\n"
|
concat "\n"
|
||||||
|
@ -39,6 +51,9 @@ if action_view_included
|
||||||
res = form_tag_without_haml(url_for_options, options, *parameters_for_url, &proc) + "\n"
|
res = form_tag_without_haml(url_for_options, options, *parameters_for_url, &proc) + "\n"
|
||||||
concat "\n" if block_given? && is_haml?
|
concat "\n" if block_given? && is_haml?
|
||||||
res
|
res
|
||||||
|
else
|
||||||
|
form_tag_without_haml(url_for_options, options, *parameters_for_url, &proc)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
alias_method_chain :form_tag, :haml
|
alias_method_chain :form_tag, :haml
|
||||||
end
|
end
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue