Class: Frontman::ErbRenderer

Inherits:
Renderer show all
Defined in:
lib/frontman/renderers/erb_renderer.rb

Instance Method Summary collapse

Methods inherited from Renderer

#render

Constructor Details

#initializeErbRenderer

Returns a new instance of ErbRenderer.



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

def initialize
  @buffer = {}
  super
end

Instance Method Details

#compile(layout) ⇒ Object



14
15
16
# File 'lib/frontman/renderers/erb_renderer.rb', line 14

def compile(layout)
  Erubis::Eruby.new(layout, bufvar: '@_erbout')
end

#load_buffer(context) ⇒ Object



42
43
44
# File 'lib/frontman/renderers/erb_renderer.rb', line 42

def load_buffer(context)
  context.instance_variable_get(:@_erbout)
end

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



18
19
20
21
22
23
24
# File 'lib/frontman/renderers/erb_renderer.rb', line 18

def render_content(compiled, content, scope, data)
  data.each do |key, value|
    scope.singleton_class.send(:define_method, key) { value }
  end

  compiled.result(scope.get_binding { content })
end

#restore_buffer(context) ⇒ Object



35
36
37
38
39
40
# File 'lib/frontman/renderers/erb_renderer.rb', line 35

def restore_buffer(context)
  return unless @buffer[context.buffer_hash]

  context.instance_variable_set(:@_erbout, @buffer[context.buffer_hash])
  @buffer.delete(context.buffer_hash)
end

#save_buffer(context) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/frontman/renderers/erb_renderer.rb', line 26

def save_buffer(context)
  buffer = context.instance_variable_get(:@_erbout)

  return unless buffer

  @buffer[context.buffer_hash] = buffer
  context.instance_variable_set(:@_erbout, '')
end