Keep track of non-Haml-ness via a Buffer flag.
This commit is contained in:
parent
ccb23dc087
commit
f48294c4ed
|
@ -23,6 +23,9 @@ module Haml
|
||||||
# It's nil at the top level (see #toplevel?).
|
# It's nil at the top level (see #toplevel?).
|
||||||
attr_accessor :upper
|
attr_accessor :upper
|
||||||
|
|
||||||
|
# See #active?
|
||||||
|
attr_writer :active
|
||||||
|
|
||||||
# True if the format is XHTML
|
# True if the format is XHTML
|
||||||
def xhtml?
|
def xhtml?
|
||||||
not html?
|
not html?
|
||||||
|
@ -49,6 +52,13 @@ module Haml
|
||||||
upper.nil?
|
upper.nil?
|
||||||
end
|
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.
|
# Gets the current tabulation of the document.
|
||||||
def tabulation
|
def tabulation
|
||||||
@real_tabs + @tabulation
|
@real_tabs + @tabulation
|
||||||
|
@ -62,6 +72,7 @@ module Haml
|
||||||
|
|
||||||
# Creates a new buffer.
|
# Creates a new buffer.
|
||||||
def initialize(upper = nil, options = {})
|
def initialize(upper = nil, options = {})
|
||||||
|
@active = true
|
||||||
@upper = upper
|
@upper = upper
|
||||||
@options = {
|
@options = {
|
||||||
:attr_wrapper => "'",
|
:attr_wrapper => "'",
|
||||||
|
|
|
@ -52,10 +52,10 @@ module Haml
|
||||||
#
|
#
|
||||||
# Note that this is automatically applied to Rails partials.
|
# Note that this is automatically applied to Rails partials.
|
||||||
def non_haml
|
def non_haml
|
||||||
old_buffer = @haml_buffer
|
was_active = @haml_buffer.active?
|
||||||
@haml_buffer = nil
|
@haml_buffer.active = false
|
||||||
res = yield
|
res = yield
|
||||||
@haml_buffer = old_buffer
|
@haml_buffer.active = was_active
|
||||||
res
|
res
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -364,7 +364,7 @@ END
|
||||||
# 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?
|
||||||
not @haml_buffer.nil?
|
!@haml_buffer.nil? && @haml_buffer.active?
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
Loading…
Reference in New Issue