Keep track of non-Haml-ness via a Buffer flag.

This commit is contained in:
Nathan Weizenbaum 2008-04-24 12:03:54 -07:00
parent ccb23dc087
commit f48294c4ed
2 changed files with 15 additions and 4 deletions

View File

@ -23,6 +23,9 @@ module Haml
# It's nil at the top level (see #toplevel?).
attr_accessor :upper
# See #active?
attr_writer :active
# True if the format is XHTML
def xhtml?
not html?
@ -49,6 +52,13 @@ module Haml
upper.nil?
end
# True if this buffer is currently being used to render a Haml template.
# However, this returns false if a subtemplate is being rendered,
# even if it's a subtemplate of this buffer's template.
def active?
@active
end
# Gets the current tabulation of the document.
def tabulation
@real_tabs + @tabulation
@ -62,6 +72,7 @@ module Haml
# Creates a new buffer.
def initialize(upper = nil, options = {})
@active = true
@upper = upper
@options = {
:attr_wrapper => "'",

View File

@ -52,10 +52,10 @@ module Haml
#
# Note that this is automatically applied to Rails partials.
def non_haml
old_buffer = @haml_buffer
@haml_buffer = nil
was_active = @haml_buffer.active?
@haml_buffer.active = false
res = yield
@haml_buffer = old_buffer
@haml_buffer.active = was_active
res
end
@ -364,7 +364,7 @@ END
# also works in other ActionView templates,
# where it will always return false.
def is_haml?
not @haml_buffer.nil?
!@haml_buffer.nil? && @haml_buffer.active?
end
private