Sha256: 7d853cabb5ee97adb6707d912552a51141b420b2799d2a0418cc98cde6e8f556

Contents?: true

Size: 1.05 KB

Versions: 3

Compression:

Stored size: 1.05 KB

Contents

module ActiveAdmin
  module ViewHelpers
    module DisplayHelper

      def display_name_method_for(resource)
        @@display_name_methods_cache ||= {}
        @@display_name_methods_cache[resource.class] ||= 
          ActiveAdmin.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

3 entries across 3 versions & 1 rubygems

Version Path
activeadmin-0.2.2 lib/active_admin/view_helpers/display_helper.rb
activeadmin-0.2.1 lib/active_admin/view_helpers/display_helper.rb
activeadmin-0.2.0 lib/active_admin/view_helpers/display_helper.rb