Sha256: 0dd54994e38b7d15f3d60b21e9875c15b1d9c5bebb16a55658e4af556b252da6

Contents?: true

Size: 1.88 KB

Versions: 3

Compression:

Stored size: 1.88 KB

Contents

module Controller
  module BreadcrumbsConcern
    extend ActiveSupport::Concern

    included do
      helper_method :breadcrumbs
    end

    def breadcrumbs
      @breadcrumbs ||= breadcrumbs!
    end

    def breadcrumbs!
      [].tap do |breadcrumbs|
        breadcrumbs << { label: t('controller.breadcrumbs_concern.home'), url: send("itsf_backend_#{I18n.locale}").root_path, link_html_options: {}, li_html_options: {}}
     
        if respond_to?(:current_engine, true) && current_engine.present?
          breadcrumbs << { label: t("classes.#{current_engine.name.underscore}"), url: send("#{current_engine.engine_name}_#{I18n.locale}").root_path, link_html_options: {}, li_html_options: {} }
        end
        
        if respond_to?(:resource_class, true)
          breadcrumbs << { label: resource_class.model_name.human(count: :other), url: url_for(action: :index), link_html_options: {}, li_html_options: {} }
        end
        if @resource.present? && @resource.persisted?
          breadcrumbs << { label: @resource.try_all(*Itsf::Backend.resource_title_methods), url: url_for(@resource), link_html_options: {}, li_html_options: {} }
        end
        
        if respond_to?(:service_class, true)
          breadcrumbs << { label: t("classes.#{service_class.name.underscore}"), url: url_for(action: :index), link_html_options: {}, li_html_options: {} }
        end

        if %w(new create edit update invoke call).include?(action_name)
          breadcrumbs << { label: t("controller.breadcrumbs_concern.#{action_name}"), url: '#', link_html_options: {}, li_html_options: {} }
        end
        
        if params[:page].present?
          breadcrumbs << { label: t('controller.breadcrumbs_concern.page', page_number: params[:page]), url: '#', link_html_options: {}, li_html_options: {} }
        end
        
        breadcrumbs.last[:li_html_options][:class] = 'active'
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
itsf_backend-4.2.2 app/controllers/concerns/controller/breadcrumbs_concern.rb
itsf_backend-4.2.1 app/controllers/concerns/controller/breadcrumbs_concern.rb
itsf_backend-4.2.0 app/controllers/concerns/controller/breadcrumbs_concern.rb