mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
Replace @haml_stack with a linked list of buffers.
This is done via the new Buffer#upper property.
This commit is contained in:
parent
40a18ff882
commit
6c0473e38e
4 changed files with 21 additions and 11 deletions
|
@ -18,6 +18,11 @@ module Haml
|
|||
# The options hash passed in from Haml::Engine.
|
||||
attr_accessor :options
|
||||
|
||||
# The Buffer for the enclosing Haml document.
|
||||
# This is set for partials and similar sorts of nested templates.
|
||||
# It's nil at the top level (see #toplevel?).
|
||||
attr_accessor :upper
|
||||
|
||||
# True if the format is XHTML
|
||||
def xhtml?
|
||||
not html?
|
||||
|
@ -38,6 +43,12 @@ module Haml
|
|||
@options[:format] == :html5
|
||||
end
|
||||
|
||||
# True if this buffer is a top-level template,
|
||||
# as opposed to a nested partial.
|
||||
def toplevel?
|
||||
upper.nil?
|
||||
end
|
||||
|
||||
# Gets the current tabulation of the document.
|
||||
def tabulation
|
||||
@real_tabs + @tabulation
|
||||
|
@ -50,7 +61,8 @@ module Haml
|
|||
end
|
||||
|
||||
# Creates a new buffer.
|
||||
def initialize(options = {})
|
||||
def initialize(upper = nil, options = {})
|
||||
@upper = upper
|
||||
@options = {
|
||||
:attr_wrapper => "'",
|
||||
:ugly => false,
|
||||
|
|
|
@ -147,7 +147,7 @@ END
|
|||
# they won't work.
|
||||
def render(scope = Object.new, locals = {}, &block)
|
||||
locals = (@options[:locals] || {}).merge(locals)
|
||||
buffer = Haml::Buffer.new(options_for_buffer)
|
||||
buffer = Haml::Buffer.new(scope.instance_variable_get('@haml_buffer'), options_for_buffer)
|
||||
|
||||
if scope.is_a?(Binding) || scope.is_a?(Proc)
|
||||
scope_object = eval("self", scope)
|
||||
|
@ -161,8 +161,7 @@ END
|
|||
|
||||
scope_object.instance_eval do
|
||||
extend Haml::Helpers
|
||||
@haml_stack ||= Array.new
|
||||
@haml_stack.push(buffer)
|
||||
@haml_buffer = buffer
|
||||
@haml_is_haml = true
|
||||
end
|
||||
|
||||
|
@ -170,7 +169,7 @@ END
|
|||
|
||||
# Get rid of the current buffer
|
||||
scope_object.instance_eval do
|
||||
@haml_stack.pop
|
||||
@haml_buffer = buffer.upper
|
||||
@haml_is_haml = false
|
||||
end
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ module Haml
|
|||
#
|
||||
def init_haml_helpers
|
||||
@haml_is_haml = true
|
||||
@haml_stack = [Haml::Buffer.new(Haml::Engine.new('').send(:options_for_buffer))]
|
||||
@haml_buffer = Haml::Buffer.new(@haml_buffer, Haml::Engine.new('').send(:options_for_buffer))
|
||||
nil
|
||||
end
|
||||
|
||||
|
@ -345,7 +345,7 @@ END
|
|||
|
||||
# Gets a reference to the current Haml::Buffer object.
|
||||
def haml_buffer
|
||||
@haml_stack[-1]
|
||||
@haml_buffer
|
||||
end
|
||||
|
||||
# Gives a proc the same local "_hamlout" and "_erbout" variables
|
||||
|
|
|
@ -97,15 +97,14 @@ module Haml
|
|||
def precompiled_with_ambles(local_names)
|
||||
preamble = <<END.gsub("\n", ";")
|
||||
extend Haml::Helpers
|
||||
@haml_stack ||= Array.new
|
||||
@haml_stack.push(Haml::Buffer.new(#{options_for_buffer.inspect}))
|
||||
_hamlout = @haml_buffer = Haml::Buffer.new(@haml_buffer, #{options_for_buffer.inspect})
|
||||
@haml_is_haml = true
|
||||
_hamlout = @haml_stack[-1]
|
||||
_erbout = _hamlout.buffer
|
||||
END
|
||||
postamble = <<END.gsub("\n", ";")
|
||||
@haml_is_haml = false
|
||||
@haml_stack.pop.buffer
|
||||
@haml_buffer = @haml_buffer.upper
|
||||
_erbout
|
||||
END
|
||||
preamble + locals_code(local_names) + @precompiled + postamble
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue