Sha256: 387fccd33476fb1c3590adeefe2de139db6a05d33b2e5b4b73bc22bba88f0ba8

Contents?: true

Size: 1.46 KB

Versions: 5

Compression:

Stored size: 1.46 KB

Contents

module CmAdmin
  module ViewHelpers
    module PageInfoHelper
      def page_title
        @action.title || @model.title || "#{@model.ar_model.name} | #{@action.name&.titleize} | Admin"
      end

      def action_title
        if @model.current_action.page_title
          title = @model.current_action.page_title
        else
          title = "#{@model.name}"
          case action_name
          when 'index'
            title + " list record"
          when 'show'
            title + " detail"
          when 'new'
            title + " create record"
          when 'edit'
            title + " edit record"
          end
        end
      end

      def action_description
        if @model.current_action.page_description
          title = @model.current_action.page_description
        else
          title = "#{@model.name}"
          case action_name
          when 'index'
            title + " list record"
          when 'show'
            title + " detail"
          when 'new'
            title + " new record"
          when 'edit'
            title + " edit record"
          end
        end
      end

      def page_url(action_name=@action.name, ar_object=nil)
        base_path = CmAdmin::Engine.mount_path + '/' + @model.name.downcase.pluralize
        case action_name
        when 'index'
          base_path
        when 'new'
          base_path + '/new'
        when 'edit'
          base_path + "/#{ar_object.id}" + '/edit'
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
cm-admin-0.4.4 lib/cm_admin/view_helpers/page_info_helper.rb
cm-admin-0.4.3 lib/cm_admin/view_helpers/page_info_helper.rb
cm-admin-0.4.2 lib/cm_admin/view_helpers/page_info_helper.rb
cm-admin-0.4.1 lib/cm_admin/view_helpers/page_info_helper.rb
cm-admin-0.4.0 lib/cm_admin/view_helpers/page_info_helper.rb