Class: ActiveAdmin::Views::AttributesTable
- Defined in:
- lib/active_admin/views/components/attributes_table.rb
Instance Method Summary collapse
- #build(obj, *attrs) ⇒ Object
-
#build_colgroups ⇒ Object
protected
Build Colgroups.
- #content_for(record, attr) ⇒ Object protected
- #default_id_for_prefix ⇒ Object protected
- #empty_value ⇒ Object protected
- #header_content_for(attr) ⇒ Object protected
- #row(*args, &block) ⇒ Object
- #rows(*attrs) ⇒ Object
- #single_record? ⇒ Boolean protected
Instance Method Details
#build(obj, *attrs) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/active_admin/views/components/attributes_table.rb', line 8 def build(obj, *attrs) @collection = Array.wrap(obj) @resource_class = @collection.first.class = {} [:for] = @collection.first if single_record? super() @table = table build_colgroups rows(*attrs) end |
#build_colgroups ⇒ Object (protected)
Build Colgroups
Colgroups are only necessary for a collection of records; not a single record.
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/active_admin/views/components/attributes_table.rb', line 56 def build_colgroups return if single_record? reset_cycle(self.class.to_s) within @table do col # column for row headers @collection.each do |record| classes = Arbre::HTML::ClassList.new classes << cycle(:even, :odd, name: self.class.to_s) classes << dom_class_name_for(record) col(id: dom_id_for(record), class: classes) end end end |
#content_for(record, attr) ⇒ Object (protected)
82 83 84 85 86 87 |
# File 'lib/active_admin/views/components/attributes_table.rb', line 82 def content_for(record, attr) value = helpers.format_attribute record, attr value.blank? && current_arbre_element.children.to_s.empty? ? empty_value : value # Don't add the same Arbre twice, while still allowing format_attribute to call status_tag current_arbre_element << value unless current_arbre_element.children.include? value end |
#default_id_for_prefix ⇒ Object (protected)
48 49 50 |
# File 'lib/active_admin/views/components/attributes_table.rb', line 48 def default_id_for_prefix "attributes_table" end |
#empty_value ⇒ Object (protected)
78 79 80 |
# File 'lib/active_admin/views/components/attributes_table.rb', line 78 def empty_value span I18n.t("active_admin.empty"), class: "empty" end |
#header_content_for(attr) ⇒ Object (protected)
70 71 72 73 74 75 76 |
# File 'lib/active_admin/views/components/attributes_table.rb', line 70 def header_content_for(attr) if @resource_class.respond_to?(:human_attribute_name) @resource_class.human_attribute_name(attr, default: attr.to_s.titleize) else attr.to_s.titleize end end |
#row(*args, &block) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/active_admin/views/components/attributes_table.rb', line 23 def row(*args, &block) title = args[0] = args. classes = [:row] if [:class] classes << [:class] elsif title.present? classes << "row-#{title.to_s.parameterize(separator: "_")}" end [:class] = classes.join(" ") @table << tr() do th do header_content_for(title) end @collection.each do |record| td do content_for(record, block || title) end end end end |
#rows(*attrs) ⇒ Object
19 20 21 |
# File 'lib/active_admin/views/components/attributes_table.rb', line 19 def rows(*attrs) attrs.each { |attr| row(attr) } end |
#single_record? ⇒ Boolean (protected)
89 90 91 |
# File 'lib/active_admin/views/components/attributes_table.rb', line 89 def single_record? @single_record ||= @collection.size == 1 end |