Sha256: 65a28814f43994c20c6d22680441dd3147dc2d081cde43de757defd4124a9b93

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

module Mvp
  module BootstrapHelper
    def col_groups_of(count, collection, opts={})
      return if collection.blank?

      html = []
      collection.in_groups_of(count).each do |groups|
        groups.compact.each do |obj|
          html << capture do
            content_tag :div, class: ["col-md-#{12/count.to_f.floor}", opts[:col_class]].compact.join(' ') do
              yield obj
            end
          end.html_safe
        end
      end
      concat html.join.html_safe
    end

    def row_groups_of(count, collection, opts={}, &block)
      return if collection.blank?

      html = []
      subsetsize = (collection.count/count.to_f)
      subsetsize.ceil.times do |i|
        subset = collection[count*i...((count*i)+count)]
        html << capture do
          content_tag :div, class: ["row",opts[:row_class]].compact.join(' ') do
            capture do
              col_groups_of(count, subset, opts, &block)
            end
          end
        end.html_safe
      end

      concat html.join.html_safe
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
minimum-viable-product-0.0.2 app/helpers/mvp/bootstrap_helper.rb