class Handlebars::Helpers::EachHelper
Public Class Methods
apply(context, items, block, else_block)
click to toggle source
# File lib/ruby-handlebars/helpers/each_helper.rb, line 10 def self.apply(context, items, block, else_block) self.apply_as(context, items, :this, block, else_block) end
apply_as(context, items, name, block, else_block)
click to toggle source
# File lib/ruby-handlebars/helpers/each_helper.rb, line 14 def self.apply_as(context, items, name, block, else_block) if (items.nil? || items.empty?) if else_block result = else_block.fn(context) end else context.with_temporary_context(name => nil, :@index => 0, :@first => false, :@last => false) do result = items.each_with_index.map do |item, index| context.add_items(name => item, :@index => index, :@first => (index == 0), :@last => (index == items.length - 1)) block.fn(context) end.join('') end end result end
registry_name()
click to toggle source
# File lib/ruby-handlebars/helpers/each_helper.rb, line 6 def self.registry_name 'each' end