Sha256: 3efe88978305c319c40a31b6ed573c0f8ba015abca39113ca8b964353bcc2492

Contents?: true

Size: 1.6 KB

Versions: 4

Compression:

Stored size: 1.6 KB

Contents

module ActiveAdmin
  class Resource
    module Naming

      # An underscored safe representation internally for this resource
      def underscored_resource_name
        @underscored_resource_name ||= if @options[:as]
          @options[:as].gsub(' ', '').underscore.singularize
        else
          resource.name.gsub('::','').underscore
        end
      end

      # A camelized safe representation for this resource
      def camelized_resource_name
        underscored_resource_name.camelize
      end

      # Returns the name to call this resource.
      # By default will use resource.model_name.human
      def resource_name
        @resource_name ||= if @options[:as] || !resource.respond_to?(:model_name)
          underscored_resource_name.titleize
        else
          resource.model_name.human.titleize
        end
      end

      # Returns the plural version of this resource
      def plural_resource_name
        @plural_resource_name ||= if @options[:as] || !resource.respond_to?(:model_name)
          resource_name.pluralize
        else
          # Check if we have a translation available otherwise pluralize
          begin
            I18n.translate!("activerecord.models.#{resource.model_name.underscore}")
            resource.model_name.human(:count => 3)
          rescue I18n::MissingTranslationData
            resource_name.pluralize
          end
        end
      end
      
      # Returns the plural and underscored version of this resource. Useful for element id's.
      def plural_underscored_resource_name
        plural_resource_name.underscore.gsub(/\s/, '_')
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
andrewroth_activeadmin-0.3.4 lib/active_admin/resource/naming.rb
activeadmin-0.3.4 lib/active_admin/resource/naming.rb
activeadmin-0.3.3 lib/active_admin/resource/naming.rb
activeadmin-0.3.2 lib/active_admin/resource/naming.rb