Sha256: e67de328a9322fa9069f4d4d5a849d0db1a573e31079842067feeb179375652f

Contents?: true

Size: 1.51 KB

Versions: 9

Compression:

Stored size: 1.51 KB

Contents

# frozen_string_literal: true

module Katalyst
  module Navigation
    module FrontendHelper
      mattr_accessor :navigation_builder

      attr_internal :default_navigation_builder

      # Render a navigation menu. Caches based on the published version's id.
      #
      # @param(menu: Katalyst::Navigation::Menu)
      # @return Structured HTML containing top level + nested navigation links
      def navigation_menu_with(menu:, **)
        builder = navigation_builder(**)
        menu    = navigation_menu_for(menu) if menu.is_a?(Symbol)

        return if menu.blank?

        cache menu do
          concat builder.render(menu.published_tree) if menu.published_version.present?
        end
      end

      # Render items without a wrapper list, useful for inline rendering of items
      #
      # @param(items: [Katalyst::Navigation::Item])
      # @return Structured HTML containing top level + nested navigation links
      def navigation_items_with(items:, **)
        builder = navigation_builder(**)

        capture do
          items.each do |item|
            concat builder.render_item(item)
          end
        end
      end

      private

      def navigation_builder(**options)
        builder = options.delete(:builder) || default_navigation_builder_class
        builder.new(self, **options)
      end

      def default_navigation_builder_class
        builder = default_navigation_builder || Frontend::Builder
        builder.respond_to?(:constantize) ? builder.constantize : builder
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
katalyst-navigation-1.8.4 app/helpers/katalyst/navigation/frontend_helper.rb
katalyst-navigation-1.8.3 app/helpers/katalyst/navigation/frontend_helper.rb
katalyst-navigation-1.8.2 app/helpers/katalyst/navigation/frontend_helper.rb
katalyst-navigation-1.8.1 app/helpers/katalyst/navigation/frontend_helper.rb
katalyst-navigation-1.8.0 app/helpers/katalyst/navigation/frontend_helper.rb
katalyst-navigation-1.6.0 app/helpers/katalyst/navigation/frontend_helper.rb
katalyst-navigation-1.5.2 app/helpers/katalyst/navigation/frontend_helper.rb
katalyst-navigation-1.5.1 app/helpers/katalyst/navigation/frontend_helper.rb
katalyst-navigation-1.5.0 app/helpers/katalyst/navigation/frontend_helper.rb