Parent

Methods

Liquid::Include

Constants

Syntax

Public Class Methods

new(tag_name, markup, tokens) click to toggle source
# File lib/liquid/tags/include.rb, line 5
def initialize(tag_name, markup, tokens)      
  if markup =~ Syntax

    @template_name = $1        
    @variable_name = $3
    @attributes    = {}

    markup.scan(TagAttributes) do |key, value|
      @attributes[key] = value
    end

  else
    raise SyntaxError.new("Error in tag 'include' - Valid syntax: include '[template]' (with|for) [object|collection]")
  end

  super
end

Public Instance Methods

parse(tokens) click to toggle source
# File lib/liquid/tags/include.rb, line 23
def parse(tokens)
end
render(context) click to toggle source
# File lib/liquid/tags/include.rb, line 26
def render(context)
  source = _read_template_from_file_system(context)
  partial = Liquid::Template.parse(source)
  variable = context[@variable_name || @template_name[1..-2]]
  
  context.stack do
    @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
        partial.render(context)
      end
    else
      context[@template_name[1..-2]] = variable
      partial.render(context)
    end
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.