1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00

Abstract the no-longer-using-Haml functionality into Haml::Helpers#non_haml.

This commit is contained in:
Nathan Weizenbaum 2008-04-24 10:23:01 -07:00
parent d4a1a35084
commit 83b6705b94
3 changed files with 24 additions and 5 deletions

View file

@ -41,6 +41,24 @@ module Haml
nil
end
# call-seq:
# non_haml { ... }
#
# Runs a block of code in a non-Haml context
# (i.e. #is_haml? will return false).
#
# This is mainly useful for rendering sub-templates such as partials in a non-Haml language,
# particularly where helpers may behave differently when run from Haml.
#
# Note that this is automatically applied to Rails partials.
def non_haml
old_buffer = @haml_buffer
@haml_buffer = nil
res = yield
@haml_buffer = old_buffer
res
end
# call-seq:
# find_and_preserve(input)
# find_and_preserve {...}

View file

@ -2,11 +2,8 @@ if defined?(ActionView) and not defined?(Merb::Plugins)
module ActionView
class Base # :nodoc:
def render_with_haml(*args, &block)
old_buffer = @haml_buffer
@haml_buffer = nil
res = render_without_haml(*args, &block)
@haml_buffer = old_buffer
res
return non_haml { render_without_haml(*args, &block) } if is_haml?
render_without_haml(*args, &block)
end
alias_method :render_without_haml, :render
alias_method :render, :render_with_haml

View file

@ -165,5 +165,9 @@ class HelperTest < Test::Unit::TestCase
assert_equal("<p attr='val'>\n Blah\n</p>\n", result)
end
def test_non_haml
assert_equal("false\n", render("= non_haml { is_haml? }"))
end
end