Class: Liquid::Tags::WithScope
- Inherits:
-
Block
- Object
- Block
- Liquid::Tags::WithScope
- Defined in:
- app/liquid/blocks/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
-
#initialize(tag_name, markup, tokens) ⇒ WithScope
constructor
A new instance of WithScope.
- #render(context) ⇒ Object
Constructor Details
#initialize(tag_name, markup, tokens) ⇒ WithScope
Returns a new instance of WithScope.
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/liquid/blocks/with_scope.rb', line 19 def initialize(tag_name, markup, tokens) @attributes = HashWithIndifferentAccess.new markup.scan(TagAttributes) do |key, value| @attributes[key] = value unless key.eql?('render_tag') end if markup =~ /render_tag:([_a-z0-9]+)/ @style = $1 end super end |
Instance Method Details
#render(context) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'app/liquid/blocks/with_scope.rb', line 33 def render(context) context.stack do result = render_all(@nodelist, context).join end context.stack do context['with_scope'] = decode(@attributes.clone, context) render_all(@nodelist, context) end end |