Sha256: c109575b84b42d2f423f8e4bf79945e5122e3fa78dacc3c85cd3db7f749b2e05

Contents?: true

Size: 1.09 KB

Versions: 12

Compression:

Stored size: 1.09 KB

Contents

module ActiveAdmin
  module Views

    class Columns < ActiveAdmin::Component
      builder_method :columns

      def column(*args, &block)
        insert_tag Column, *args, &block
      end

      # Override add child to set widths
      def add_child(*)
        super
        calculate_columns!
      end

      protected

      def margin_size
        2
      end

      def calculate_columns!
        # Calculate our columns sizes and margins
        count = children.size
        margins_width = margin_size * (count - 1)
        column_width = (100.00 - margins_width) / count

        # Convert to an integer if its not a float
        column_width = column_width.to_i == column_width ? column_width.to_i : column_width

        children.each_with_index do |col, i|
          col.set_attribute :style, "width: #{column_width}%;"
          col.attr(:style) << " margin-right: #{margin_size}%;" unless i == (count - 1)
        end
      end

      def to_html
        super.to_s + "<div style=\"clear:both;\"></div>".html_safe
      end

    end

    class Column < ActiveAdmin::Component
    end
  end
end

Version data entries

12 entries across 12 versions & 4 rubygems

Version Path
andrewroth_activeadmin-0.3.4.3 lib/active_admin/views/components/columns.rb
andrewroth_activeadmin-0.3.4.2 lib/active_admin/views/components/columns.rb
andrewroth_activeadmin-0.3.4.1 lib/active_admin/views/components/columns.rb
andrewroth_activeadmin-0.3.4 lib/active_admin/views/components/columns.rb
activeadmin-0.3.4 lib/active_admin/views/components/columns.rb
activeadmin-0.3.3 lib/active_admin/views/components/columns.rb
activeadmin-0.3.2 lib/active_admin/views/components/columns.rb
activeadmin-0.3.1 lib/active_admin/views/components/columns.rb
activeadmin-0.3.0 lib/active_admin/views/components/columns.rb
nsm-activeadmin-0.2.2 lib/active_admin/views/components/columns.rb
saulolso-activeadmin-0.2.2.1 lib/active_admin/views/components/columns.rb
saulolso-activeadmin-0.2.2 lib/active_admin/views/components/columns.rb