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

Inherits:
Solid::Block
  • Object
show all
Defined in:
lib/locomotive/steam/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*\:/o
REGEX_OPTIONS =
{
  'i' => Regexp::IGNORECASE,
  'm' => Regexp::MULTILINE,
  'x' => Regexp::EXTENDED
}

Instance Method Summary collapse

Constructor Details

#initialize(name, markup, options) ⇒ WithScope

Returns a new instance of WithScope.



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

def initialize(name, markup, options)
  # convert symbol operators into valid ruby code
  markup.gsub!(SYMBOL_OPERATORS_REGEXP, ':"\1" =>')

  super(name, markup, options)
end

Instance Method Details

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



39
40
41
42
43
44
45
# File 'lib/locomotive/steam/liquid/tags/with_scope.rb', line 39

def display(options = {}, &block)
  current_context.stack do
    current_context['with_scope'] = self.decode(options)
    current_context['with_scope_content_type'] = false # for now, no content type is assigned to this with_scope
    yield
  end
end