Class: Handlebars::Helpers::EachHelper

Inherits:
DefaultHelper show all
Defined in:
lib/ruby-handlebars/helpers/each_helper.rb

Class Method Summary collapse

Methods inherited from DefaultHelper

register

Class Method Details

.apply(context, items, block, else_block) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/ruby-handlebars/helpers/each_helper.rb', line 10

def self.apply(context, items, block, else_block)
  if (items.nil? || items.empty?)
    if else_block
      result = else_block.fn(context)
    end
  else
    context.with_temporary_context(:this => nil, :@index => 0, :@first => false, :@last => false) do
      result = items.each_with_index.map do |item, index|
        context.add_items(:this => item, :@index => index, :@first => (index == 0), :@last => (index == items.length - 1))
        block.fn(context)
      end.join('')
    end
  end
  result
end

.registry_nameObject



6
7
8
# File 'lib/ruby-handlebars/helpers/each_helper.rb', line 6

def self.registry_name
  'each'
end