Class: Lesmok::Tags::ErbInclude::ErbRenderer

Inherits:
Object
  • Object
show all
Defined in:
lib/lesmok/tags/erb_include.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(liquid_context, template_name) ⇒ ErbRenderer

Returns a new instance of ErbRenderer.



11
12
13
14
# File 'lib/lesmok/tags/erb_include.rb', line 11

def initialize(liquid_context, template_name)
  @context = liquid_context
  @template_name = template_name
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



10
11
12
# File 'lib/lesmok/tags/erb_include.rb', line 10

def context
  @context
end

Instance Method Details

#call(args = {}) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/lesmok/tags/erb_include.rb', line 31

def call(args = {})
  template_name = context[@template_name]
  default_args = {
    partial: template_name,
    template:  template_name,
    registers: context.registers,
    locals: context.scopes.last.with_indifferent_access, # TODO: Make this work?
    liquid_context: context,
  }
  render_args = default_args.merge(args)
  ctrl.send(:render, render_args)
end

#ctrlObject



23
24
25
# File 'lib/lesmok/tags/erb_include.rb', line 23

def ctrl
  context.registers[:controller]
end

#extract_varsObject



15
16
17
18
19
20
21
# File 'lib/lesmok/tags/erb_include.rb', line 15

def extract_vars
  # Not needed if we use action_view directly?
  ctrl.instance_variables.each do |key|
    val = ctrl.instance_variable_get(key)
    self.instance_variable_set(key, val)
  end if ctrl
end

#viewObject



27
28
29
# File 'lib/lesmok/tags/erb_include.rb', line 27

def view
  context.registers[:action_view]
end