Class: Frontman::HamlRenderer

Inherits:
Renderer
  • Object
show all
Defined in:
lib/frontman/renderers/haml_renderer.rb

Instance Method Summary collapse

Methods inherited from Renderer

#render

Constructor Details

#initializeHamlRenderer

Returns a new instance of HamlRenderer.



9
10
11
12
13
# File 'lib/frontman/renderers/haml_renderer.rb', line 9

def initialize
  Haml::Options.defaults[:format] = :html5
  @buffer = {}
  super
end

Instance Method Details

#compile(layout) ⇒ Object



15
16
17
# File 'lib/frontman/renderers/haml_renderer.rb', line 15

def compile(layout)
  Haml::Engine.new(layout)
end

#load_buffer(context) ⇒ Object



23
24
25
26
27
# File 'lib/frontman/renderers/haml_renderer.rb', line 23

def load_buffer(context)
  haml_locals = context.instance_variable_get(:@_haml_locals)

  haml_locals[:_hamlout].buffer if haml_locals
end

#render_content(compiled, content, scope, _data) ⇒ Object



19
20
21
# File 'lib/frontman/renderers/haml_renderer.rb', line 19

def render_content(compiled, content, scope, _data)
  compiled.render(scope.get_binding) { content }
end

#restore_buffer(context) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'lib/frontman/renderers/haml_renderer.rb', line 40

def restore_buffer(context)
  haml_locals = context.instance_variable_get(:@_haml_locals)

  return unless haml_locals

  haml_locals[:_hamlout].buffer = @buffer[context.buffer_hash]
  context.instance_variable_set(:@_haml_locals, haml_locals)
  @buffer.delete(context.buffer_hash)
end

#save_buffer(context) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/frontman/renderers/haml_renderer.rb', line 29

def save_buffer(context)
  haml_locals = context.instance_variable_get(:@_haml_locals)

  return unless haml_locals

  @buffer[context.buffer_hash] = haml_locals[:_hamlout].buffer
  # empty the buffer so we can capture everything from the new render
  haml_locals[:_hamlout].buffer = ''
  context.instance_variable_set(:@_haml_locals, haml_locals)
end