Class: ActiveAdmin::Views::AttributesTable

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#resourceObject (readonly)

Returns the value of attribute resource.



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

def resource
  @resource
end

Instance Method Details

#build(record, *attrs) ⇒ Object



9
10
11
12
13
14
# File 'lib/active_admin/views/components/attributes_table.rb', line 9

def build(record, *attrs)
  @record = record
  super(:for => @record)
  @table = table
  rows(*attrs)
end

#content_for(attr) ⇒ Object (protected)



52
53
54
55
56
# File 'lib/active_admin/views/components/attributes_table.rb', line 52

def content_for(attr)
  previous = current_arbre_element.to_s
  value    = pretty_format find_attr_value attr
  value.blank? && previous == current_arbre_element.to_s ? empty_value : value
end

#default_id_for_prefixObject (protected)



36
37
38
# File 'lib/active_admin/views/components/attributes_table.rb', line 36

def default_id_for_prefix
  'attributes_table'
end

#empty_valueObject (protected)



48
49
50
# File 'lib/active_admin/views/components/attributes_table.rb', line 48

def empty_value
  span I18n.t('active_admin.empty'), :class => "empty"
end

#find_attr_value(attr) ⇒ Object (protected)



58
59
60
61
62
63
64
65
66
# File 'lib/active_admin/views/components/attributes_table.rb', line 58

def find_attr_value(attr)
  if attr.is_a?(Proc)
    attr.call(@record)
  elsif attr.to_s[/\A(.+)_id\z/] && @record.respond_to?($1.to_sym)
    @record.send($1.to_sym)
  else
    @record.send(attr.to_sym)
  end
end

#header_content_for(attr) ⇒ Object (protected)



40
41
42
43
44
45
46
# File 'lib/active_admin/views/components/attributes_table.rb', line 40

def header_content_for(attr)
  if @record.class.respond_to?(:human_attribute_name)
    @record.class.human_attribute_name(attr, :default => attr.to_s.titleize)
  else
    attr.to_s.titleize
  end
end

#row(*args, &block) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/active_admin/views/components/attributes_table.rb', line 20

def row(*args, &block)
  title   = args[0]
  options = args.extract_options!
  options[:class] ||= :row
  @table << tr(options) do
    th do
      header_content_for(title)
    end
    td do
      content_for(block || title)
    end
  end
end

#rows(*attrs) ⇒ Object



16
17
18
# File 'lib/active_admin/views/components/attributes_table.rb', line 16

def rows(*attrs)
  attrs.each {|attr| row(attr) }
end