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
|