Class: ActiveAdmin::Views::Columns

Inherits:
Component
  • Object
show all
Defined in:
lib/active_admin/views/components/columns.rb

Instance Method Summary collapse

Methods inherited from Component

#default_class_name, #initialize, #tag_name

Constructor Details

This class inherits a constructor from ActiveAdmin::Component

Instance Method Details

#add_childObject

Override add child to set widths



12
13
14
15
# File 'lib/active_admin/views/components/columns.rb', line 12

def add_child(*)
  super
  calculate_columns!
end

#calculate_columns!Object (protected)



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/active_admin/views/components/columns.rb', line 27

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

#column(*args, &block) ⇒ Object



7
8
9
# File 'lib/active_admin/views/components/columns.rb', line 7

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

#margin_sizeObject (protected)



23
24
25
# File 'lib/active_admin/views/components/columns.rb', line 23

def margin_size
  2
end

#to_sObject



17
18
19
# File 'lib/active_admin/views/components/columns.rb', line 17

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