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

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

Overview

Filter a collection

Usage:

with_scope main_developer: ‘John Doe’, providers.in: [‘acme’], started_at.le: today, active: true %

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

endwith_scope %

Constant Summary collapse

OPERATORS =
%w(all exists gt gte in lt lte ne nin size near within)
SYMBOL_OPERATORS_REGEXP =
/(\w+\.(#{OPERATORS.join('|')})){1}\s*\:/

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, arguments_string, tokens, context = {}) ⇒ WithScope

Returns a new instance of WithScope.



25
26
27
28
29
30
# File 'lib/locomotive/liquid/tags/with_scope.rb', line 25

def initialize(tag_name, arguments_string, tokens, context = {})
  # convert symbol operators into valid ruby code
  arguments_string.gsub!(SYMBOL_OPERATORS_REGEXP, ':"\1" =>')

  super(tag_name, arguments_string, tokens, context)
end

Instance Method Details

#display(options = {}, &block) ⇒ Object



32
33
34
35
36
37
# File 'lib/locomotive/liquid/tags/with_scope.rb', line 32

def display(options = {}, &block)
  current_context.stack do
    current_context['with_scope'] = self.decode(options)
    yield
  end
end