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.59 vendor/deps/active_admin/lib/active_admin/view_helpers/display_helper.rb
lalala-4.0.0.dev.58 vendor/deps/active_admin/lib/active_admin/view_helpers/display_helper.rb
lalala-4.0.0.dev.57 vendor/deps/active_admin/lib/active_admin/view_helpers/display_helper.rb
lalala-4.0.0.dev.56 vendor/deps/active_admin/lib/active_admin/view_helpers/display_helper.rb
lalala-4.0.0.dev.50 vendor/deps/active_admin/lib/active_admin/view_helpers/display_helper.rb
lalala-4.0.0.dev.46 vendor/deps/active_admin/lib/active_admin/view_helpers/display_helper.rb
activeadmin-0.5.1 lib/active_admin/view_helpers/display_helper.rb
activeadmin-0.5.0 lib/active_admin/view_helpers/display_helper.rb
activeadmin-0.5.0.pre1 lib/active_admin/view_helpers/display_helper.rb
activeadmin-0.5.0.pre lib/active_admin/view_helpers/display_helper.rb