Class: Liquid::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/nested_liquid.rb

Overview

nodoc

Instance Method Summary collapse

Instance Method Details

#liquid_variableObject



11
# File 'lib/nested_liquid.rb', line 11

alias_method :liquid_variable, :variable

#render_nested_liquid(liquid_template, context) ⇒ Object

Recursively renders the liquid calls with the same context until all liquid tags have been rendered



14
15
16
17
18
19
20
21
# File 'lib/nested_liquid.rb', line 14

def render_nested_liquid(liquid_template, context)
  parsed_template = Liquid::Template.parse(liquid_template)
  output = parsed_template.render(context)
  # output.scan(/^#{VariableStart}(.*)#{VariableEnd}$/) do |o|
    # return render_nested_liquid(o, context)
  # end
  output
end

#variable(markup) ⇒ Object

Determine if we’re able to call the method. If not we pass the call back to Liquid’s standard method

This is dependant on the Liquid.allowed_namespaces being set



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/nested_liquid.rb', line 26

def variable(markup)
  parts = markup.scan(VariableParser)
  first_part = parts.shift

  if Liquid.allowed_namespaces.to_a.include? parts[0]
    #Liquid 2.2 uses environments
    if @environments
      @environments.each do |environment|
        return render_nested_liquid(environment[first_part].send(parts[0]).send(parts[1]), self) if environment.has_key? first_part
      end
    else
      # Liquid < 2.2 uses scopes
      @scopes.each do |scope|
        return render_nested_liquid(scope[first_part].send(parts[0]).send(parts[1]), self) if scope.has_key? first_part
      end
    end
  else
    # If the namespace isn't allowed send the call back to the default Liquid::Context#variable we aliased as liquid_variable above
    liquid_variable(markup)
  end

end