Sha256: bce90a6f3b7192b6073b0aa8ee86902b9edb3f1ec1f87910daa0c8ccad1be0bc

Contents?: true

Size: 1.26 KB

Versions: 37

Compression:

Stored size: 1.26 KB

Contents

module Para
  module Breadcrumbs
    module Controller
      extend ActiveSupport::Concern

      included do
        class_attribute :_class_level_breadcrumbs

        before_action :build_breadcrumbs_manager

        helper_method :add_breadcrumb, :breadcrumbs
        helper ViewHelper
      end

      def add_breadcrumb(*args)
        breadcrumbs.add(*args)
      end

      def breadcrumbs
        build_breadcrumbs_manager
      end

      private

      def build_breadcrumbs_manager
        Para.store['para.breadcrumbs'] ||=
          Breadcrumbs::Manager.new(self).tap do |manager|
            if _class_level_breadcrumbs
              _class_level_breadcrumbs.each { |args| manager.add(*args) }
            end
          end
      end

      module ClassMethods
        def add_breadcrumb(*args)
          self._class_level_breadcrumbs ||= []
          self._class_level_breadcrumbs += [args]
        end
      end

      module ViewHelper
        # Render the breadcrumbs view depending wether it is in the admin or
        # in front, allowing the front view to be overriden in app
        #
        def render_breadcrumbs
          prefix = controller.admin? ? 'para/admin/' : ''
          render partial: "#{ prefix }shared/breadcrumbs"
        end
      end
    end
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
para-0.9.3.3 lib/para/breadcrumbs/controller.rb
para-0.9.3.2 lib/para/breadcrumbs/controller.rb
para-0.9.3.1 lib/para/breadcrumbs/controller.rb
para-0.9.2 lib/para/breadcrumbs/controller.rb
para-0.9.0 lib/para/breadcrumbs/controller.rb
para-0.8.15 lib/para/breadcrumbs/controller.rb
para-0.8.14 lib/para/breadcrumbs/controller.rb
para-0.8.13 lib/para/breadcrumbs/controller.rb
para-0.8.12 lib/para/breadcrumbs/controller.rb
para-0.8.11 lib/para/breadcrumbs/controller.rb
para-0.8.10 lib/para/breadcrumbs/controller.rb
para-0.8.9 lib/para/breadcrumbs/controller.rb
para-0.8.8 lib/para/breadcrumbs/controller.rb
para-0.8.7 lib/para/breadcrumbs/controller.rb
para-0.8.5 lib/para/breadcrumbs/controller.rb
para-0.8.3.3 lib/para/breadcrumbs/controller.rb
para-0.8.3.2 lib/para/breadcrumbs/controller.rb
para-0.8.3.1 lib/para/breadcrumbs/controller.rb
para-0.8.3 lib/para/breadcrumbs/controller.rb
para-0.8.2.3 lib/para/breadcrumbs/controller.rb