Class: Sablon::Processor::Document::EachLoopHandler

Inherits:
FieldHandler
  • Object
show all
Defined in:
lib/sablon/processor/document/field_handlers.rb

Overview

Handles each loops in the template

Instance Method Summary collapse

Methods inherited from FieldHandler

#handles?

Constructor Details

#initializeEachLoopHandler

Returns a new instance of EachLoopHandler.



46
47
48
# File 'lib/sablon/processor/document/field_handlers.rb', line 46

def initialize
  super(/([^ ]+):each\(([^ ]+)\)/)
end

Instance Method Details

#build_statement(constructor, field, _options = {}) ⇒ Object



50
51
52
53
54
# File 'lib/sablon/processor/document/field_handlers.rb', line 50

def build_statement(constructor, field, _options = {})
  expr_name, item_name = field.expression.match(@pattern).to_a[1..2]
  block = constructor.consume_block("#{expr_name}:endEach")
  Statement::Loop.new(Expression.parse(expr_name), item_name, block)
end