Class: Handlebars::Helpers::EachHelper
- Inherits:
-
DefaultHelper
- Object
- DefaultHelper
- Handlebars::Helpers::EachHelper
- Defined in:
- lib/ruby-handlebars/helpers/each_helper.rb
Class Method Summary collapse
- .apply(context, items, block, else_block) ⇒ Object
- .apply_as(context, items, name, block, else_block) ⇒ Object
- .registry_name ⇒ Object
Methods inherited from DefaultHelper
Class Method Details
.apply(context, items, block, else_block) ⇒ Object
10 11 12 |
# 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) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# 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 ⇒ Object
6 7 8 |
# File 'lib/ruby-handlebars/helpers/each_helper.rb', line 6 def self.registry_name 'each' end |