Sha256: 39b97401feb6ef7a7ef212744dcbe1a19b115832a0e527b02cf56d1e4eaef302

Contents?: true

Size: 1.06 KB

Versions: 18

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::HTML::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

18 entries across 18 versions & 4 rubygems

Version Path
activeadmin-0.4.4 lib/active_admin/view_helpers/display_helper.rb
activeadmin-0.4.3 lib/active_admin/view_helpers/display_helper.rb
activeadmin-0.4.2 lib/active_admin/view_helpers/display_helper.rb
activeadmin-0.4.1 lib/active_admin/view_helpers/display_helper.rb
activeadmin-0.4.0 lib/active_admin/view_helpers/display_helper.rb
andrewroth_activeadmin-0.3.4.4 lib/active_admin/view_helpers/display_helper.rb
andrewroth_activeadmin-0.3.4.3 lib/active_admin/view_helpers/display_helper.rb
andrewroth_activeadmin-0.3.4.2 lib/active_admin/view_helpers/display_helper.rb
andrewroth_activeadmin-0.3.4.1 lib/active_admin/view_helpers/display_helper.rb
andrewroth_activeadmin-0.3.4 lib/active_admin/view_helpers/display_helper.rb
activeadmin-0.3.4 lib/active_admin/view_helpers/display_helper.rb
activeadmin-0.3.3 lib/active_admin/view_helpers/display_helper.rb
activeadmin-0.3.2 lib/active_admin/view_helpers/display_helper.rb
activeadmin-0.3.1 lib/active_admin/view_helpers/display_helper.rb
activeadmin-0.3.0 lib/active_admin/view_helpers/display_helper.rb
nsm-activeadmin-0.2.2 lib/active_admin/view_helpers/display_helper.rb
saulolso-activeadmin-0.2.2.1 lib/active_admin/view_helpers/display_helper.rb
saulolso-activeadmin-0.2.2 lib/active_admin/view_helpers/display_helper.rb