Sha256: 82adf2787146fa2ce3482601ac5ce78e39d16a21a0402bec563487e0c6981f20

Contents?: true

Size: 1.3 KB

Versions: 12

Compression:

Stored size: 1.3 KB

Contents

module Para
  module Breadcrumbs
    module Controller
      extend ActiveSupport::Concern
      include ActionController::Helpers

      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

12 entries across 12 versions & 1 rubygems

Version Path
para-0.12.4 lib/para/breadcrumbs/controller.rb
para-0.12.3 lib/para/breadcrumbs/controller.rb
para-0.12.2 lib/para/breadcrumbs/controller.rb
para-0.12.1 lib/para/breadcrumbs/controller.rb
para-0.12.0 lib/para/breadcrumbs/controller.rb
para-0.11.4 lib/para/breadcrumbs/controller.rb
para-0.11.3 lib/para/breadcrumbs/controller.rb
para-0.11.2 lib/para/breadcrumbs/controller.rb
para-0.11.1 lib/para/breadcrumbs/controller.rb
para-0.11.0 lib/para/breadcrumbs/controller.rb
para-0.10.0 lib/para/breadcrumbs/controller.rb
para-0.9.4 lib/para/breadcrumbs/controller.rb