Sha256: 947cb632ff07287c265d143b376077c058afcb9ed518f936c0c35f4180f3d0fe

Contents?: true

Size: 1.25 KB

Versions: 3

Compression:

Stored size: 1.25 KB

Contents

module ThinkFeelDoDashboard
  # Ensure font awesome icon helpers are available.
  module ApplicationHelper
    TOP_LEVEL_CONTROLLERS = %w( arms groups participants users reports ).freeze

    # Render navigational information in the form of breadcrumbs
    def breadcrumbs
      return unless show_breadcrumbs?

      content_for(
        :breadcrumbs,
        content_tag(:ol, class: "breadcrumb") do
          concat(content_tag(:li, link_to("Home", root_path)))

          if can_view_resource_index?
            concat(
              content_tag(
                :li, controller_link
              )
            )
          end
        end
      )
    end

    def social_features?
      if Rails.application.config.respond_to?(:include_social_features)
        Rails.application.config.include_social_features
      end
    end

    private

    def show_breadcrumbs?
      TOP_LEVEL_CONTROLLERS.include?(controller_name)
    end

    def can_view_resource_index?
      begin
        klass = controller_name.singularize.capitalize.constantize
      rescue NameError
        klass = nil
      end

      !klass.is_a?(Class) || can?(:index, klass)
    end

    def controller_link
      link_to(controller_name.capitalize, url_for(controller: controller_name))
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
think_feel_do_dashboard-1.2.0.beta1 app/helpers/think_feel_do_dashboard/application_helper.rb
think_feel_do_dashboard-1.1.21 app/helpers/think_feel_do_dashboard/application_helper.rb
think_feel_do_dashboard-1.1.20 app/helpers/think_feel_do_dashboard/application_helper.rb