Sha256: aa8d17f1e251e296bc6c69464dbc11ce0a55e488b13b9e4696f3907e0e514492

Contents?: true

Size: 888 Bytes

Versions: 2

Compression:

Stored size: 888 Bytes

Contents

module Insightful
  module GridHelper
    def grid_for(array, options = {}, &block)
      return "" if array.empty?
      columns = options[:columns] || 3
      (array / columns).each do |row|
        yield row
      end
    end
  
    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
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
insightful-0.0.1.6 lib/insightful/grid_helper.rb
insightful-0.0.1.5 lib/insightful/grid_helper.rb