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
|
||||
push_silent <<-END
|
||||
def _haml_render
|
||||
@haml_is_haml = true
|
||||
_hamlout = @haml_stack[-1]
|
||||
_erbout = _hamlout.buffer
|
||||
END
|
||||
|
@ -266,6 +267,7 @@ END
|
|||
# Close all the open tags
|
||||
@template_tabs.times { close }
|
||||
|
||||
push_silent "@haml_is_haml = false"
|
||||
push_silent "end"
|
||||
end
|
||||
|
||||
|
|
|
@ -313,7 +313,7 @@ module Haml
|
|||
# also works in other ActionView templates,
|
||||
# where it will always return false.
|
||||
def is_haml?
|
||||
@haml_stack ? @haml_stack.size > 0 : false
|
||||
@haml_is_haml
|
||||
end
|
||||
|
||||
include ActionViewExtensions if self.const_defined? "ActionViewExtensions"
|
||||
|
|
|
@ -10,6 +10,17 @@ end
|
|||
|
||||
if action_view_included
|
||||
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
|
||||
# to make them work more effectively with Haml.
|
||||
module Helpers
|
||||
|
@ -27,7 +38,8 @@ if action_view_included
|
|||
|
||||
module FormTagHelper
|
||||
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
|
||||
proc = bind_proc do |*args|
|
||||
concat "\n"
|
||||
|
@ -39,6 +51,9 @@ if action_view_included
|
|||
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
|
||||
alias_method_chain :form_tag, :haml
|
||||
end
|
||||
|
|
|
@ -101,6 +101,10 @@ class HelperTest < Test::Unit::TestCase
|
|||
|
||||
def test_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
|
||||
|
||||
def test_page_class
|
||||
|
|
Loading…
Reference in New Issue