Class: ChiliProject::Liquid::Tags::Include

Inherits:
Liquid::Include
  • Object
show all
Defined in:
lib/chili_project/liquid/tags/include.rb

Instance Method Summary collapse

Instance Method Details

#render(context) ⇒ Object

This method follows the basic flow of the default include in liquid We just add some additional flexibility. This method can be removed once github.com/Shopify/liquid/pull/78 got accepted


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/chili_project/liquid/tags/include.rb', line 21

def render(context)
  context.stack do
    template = _read_template_from_file_system(context)
    partial = Liquid::Template.parse _template_source(template)
    variable = context[@variable_name || @template_name[1..-2]]

    @attributes.each do |key, value|
      context[key] = context[value]
    end

    if variable.is_a?(Array)
      variable.collect do |variable|
        context[@template_name[1..-2]] = variable
        _render_partial(partial, template, context)
      end
    else
      context[@template_name[1..-2]] = variable
      _render_partial(partial, template, context)
    end
  end
end