Sha256: be229a1026f242b81afd406d0ec678540ff8fb3ec9ff340abbff70b2ade5bc3b

Contents?: true

Size: 1.06 KB

Versions: 50

Compression:

Stored size: 1.06 KB

Contents

module ActiveAdmin
  module ViewHelpers
    module DisplayHelper

      def display_name_method_for(resource)
        @@display_name_methods_cache ||= {}
        @@display_name_methods_cache[resource.class] ||= 
          active_admin_application.display_name_methods.find{|method| resource.respond_to? method }
      end

      # Tries to display an object with as friendly of output
      # as possible.
      def display_name(resource)
        resource.send(display_name_method_for(resource))
      end

      # Return a pretty string for any object
      # Date Time are formatted via #localize with :format => :long
      # ActiveRecord objects are formatted via #auto_link
      # We attempt to #display_name of any other objects
      def pretty_format(object)
        case object
        when String
          object
        when Arbre::Element
          object
        when Date, Time
          localize(object, :format => :long)
        when ActiveRecord::Base
          auto_link(object)
        else
          display_name(object)
        end
      end

    end
  end
end

Version data entries

50 entries across 50 versions & 2 rubygems

Version Path
lalala-4.0.0.dev.141 vendor/deps/active_admin/lib/active_admin/view_helpers/display_helper.rb
lalala-4.0.0.dev.136 vendor/deps/active_admin/lib/active_admin/view_helpers/display_helper.rb
lalala-4.0.0.dev.135 vendor/deps/active_admin/lib/active_admin/view_helpers/display_helper.rb
lalala-4.0.0.dev.134 vendor/deps/active_admin/lib/active_admin/view_helpers/display_helper.rb
lalala-4.0.0.dev.133 vendor/deps/active_admin/lib/active_admin/view_helpers/display_helper.rb
lalala-4.0.0.dev.132 vendor/deps/active_admin/lib/active_admin/view_helpers/display_helper.rb
lalala-4.0.0.dev.131 vendor/deps/active_admin/lib/active_admin/view_helpers/display_helper.rb
lalala-4.0.0.dev.129 vendor/deps/active_admin/lib/active_admin/view_helpers/display_helper.rb
lalala-4.0.0.dev.128 vendor/deps/active_admin/lib/active_admin/view_helpers/display_helper.rb
lalala-4.0.0.dev.126 vendor/deps/active_admin/lib/active_admin/view_helpers/display_helper.rb
lalala-4.0.0.dev.125 vendor/deps/active_admin/lib/active_admin/view_helpers/display_helper.rb
lalala-4.0.0.dev.124 vendor/deps/active_admin/lib/active_admin/view_helpers/display_helper.rb
lalala-4.0.0.dev.123 vendor/deps/active_admin/lib/active_admin/view_helpers/display_helper.rb
lalala-4.0.0.dev.118 vendor/deps/active_admin/lib/active_admin/view_helpers/display_helper.rb
lalala-4.0.0.dev.116 vendor/deps/active_admin/lib/active_admin/view_helpers/display_helper.rb
lalala-4.0.0.dev.114 vendor/deps/active_admin/lib/active_admin/view_helpers/display_helper.rb
lalala-4.0.0.dev.113 vendor/deps/active_admin/lib/active_admin/view_helpers/display_helper.rb
lalala-4.0.0.dev.111 vendor/deps/active_admin/lib/active_admin/view_helpers/display_helper.rb
lalala-4.0.0.dev.109 vendor/deps/active_admin/lib/active_admin/view_helpers/display_helper.rb
lalala-4.0.0.dev.107 vendor/deps/active_admin/lib/active_admin/view_helpers/display_helper.rb