Sha256: 31f51cfa49027e322b0361d6f6e7cadacadad064da68a4f55625ed4fac1b0ee7

Contents?: true

Size: 1.59 KB

Versions: 7

Compression:

Stored size: 1.59 KB

Contents

module ActiveAdmin
  module Views

    class AttributesTable < ActiveAdmin::Component
      builder_method :attributes_table_for

      attr_reader :resource

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

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

      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

      protected

      def default_id_for_prefix
        'attributes_table'
      end

      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

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

      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

      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
    end

  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
activeadmin-0.6.6 lib/active_admin/views/components/attributes_table.rb
activeadmin-0.6.5 lib/active_admin/views/components/attributes_table.rb
activeadmin-0.6.4 lib/active_admin/views/components/attributes_table.rb
activeadmin-0.6.3 lib/active_admin/views/components/attributes_table.rb
activeadmin-0.6.2 lib/active_admin/views/components/attributes_table.rb
activeadmin-0.6.1 lib/active_admin/views/components/attributes_table.rb
aa-rails4-0.6.0 lib/active_admin/views/components/attributes_table.rb