Module: Blocks::HamlCapture

Included in:
Builder
Defined in:
lib/blocks/helpers/haml_capture.rb

Instance Method Summary collapse

Instance Method Details

#captureObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/blocks/helpers/haml_capture.rb', line 28

def capture(*)
  old_haml_buffer = view.instance_variable_get(:@haml_buffer)
  if old_haml_buffer
    was_active = old_haml_buffer.active?
    old_haml_buffer.active = false
  else
    haml_buffer = Haml::Buffer.new(nil, Haml::Options.new.for_buffer)
    haml_buffer.active = false
    view.instance_variable_set(:@haml_buffer, haml_buffer)
  end
  super
ensure
  old_haml_buffer.active = was_active if old_haml_buffer
  view.instance_variable_set(:@haml_buffer, old_haml_buffer)
end

#initialize(view) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/blocks/helpers/haml_capture.rb', line 18

def initialize(view, *)
  super
  if defined?(::Haml) && !view.instance_variables.include?(:@haml_buffer)
    class << view
      include Haml::Helpers
    end
    view.init_haml_helpers
  end
end