Module: Represent::GridHelper

Defined in:
lib/represent/grid_helper.rb

Instance Method Summary collapse

Instance Method Details

#grid_for(array, options = {}, &block) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/represent/grid_helper.rb', line 3

def grid_for(array, options = {}, &block)
  return "" if array.empty?
  columns = options[:columns] || 3
  (array / columns).each do |row|
    yield row
  end
end

#row_for(array, options = {}, &block) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/represent/grid_helper.rb', line 11

def row_for(array, options = {}, &block)
  return "" if array.empty?
  array.each_with_index do |node, i|
    attributes = options.has_key?(:li_attributes) ? options[:li_attributes] : {}
    attributes[:class] ||= ""
    if i == 0 and options.has_key?(:first)
      attributes[:class] << "#{options[:first]}"
    elsif i == array.length - 1 and options.has_key?(:last)
      attributes[:class] << "#{options[:last]}"
    end
    haml_tag :li, attributes do
      if block_given?
        yield node, i
      else
        haml_concat node.title
      end
    end
  end
end