Class: Locomotive::Liquid::Tags::WithScope

Inherits:
Liquid::Block
  • Object
show all
Defined in:
lib/locomotive/liquid/tags/with_scope.rb

Overview

Filter a collection

Usage:

with_scope main_developer: ‘John Doe’, active: true %

{% for project in contents.projects %}
  {{ project.name }}
{% endfor %}

endwith_scope %

Constant Summary collapse

TagAttributes =
/(\w+|\w+\.\w+)\s*\:\s*(#{::Liquid::QuotedFragment})/

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, markup, tokens, context) ⇒ WithScope

Returns a new instance of WithScope.



20
21
22
23
24
25
26
# File 'lib/locomotive/liquid/tags/with_scope.rb', line 20

def initialize(tag_name, markup, tokens, context)
  @attributes = HashWithIndifferentAccess.new
  markup.scan(TagAttributes) do |key, value|
    @attributes[key] = value
  end
  super
end

Instance Method Details

#render(context) ⇒ Object



28
29
30
31
32
33
# File 'lib/locomotive/liquid/tags/with_scope.rb', line 28

def render(context)
  context.stack do
    context['with_scope'] = decode(@attributes.clone, context)
    render_all(@nodelist, context)
  end
end