Class: Liquid::CustomBlocks::KeyIterator
- Inherits:
-
Block
- Object
- Block
- Liquid::CustomBlocks::KeyIterator
- Defined in:
- lib/liquid/custom_blocks/key_iterator.rb
Instance Method Summary collapse
-
#initialize(tag_name, markup, tokens) ⇒ KeyIterator
constructor
A new instance of KeyIterator.
- #render(context) ⇒ Object
Constructor Details
#initialize(tag_name, markup, tokens) ⇒ KeyIterator
Returns a new instance of KeyIterator.
8 9 10 11 |
# File 'lib/liquid/custom_blocks/key_iterator.rb', line 8 def initialize(tag_name, markup, tokens) super @context_name, @var_name = markup.split(",").map(&:strip) end |
Instance Method Details
#render(context) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/liquid/custom_blocks/key_iterator.rb', line 13 def render(context) collection = context[@context_name] items = enumerable_items(collection) result = +"" items.each.with_index do |item, index| context["index"] = index context[@var_name] = item result << super end result end |