Sha256: 77a63e5c35c63e769888a569331b4c841a9159620ead505b6a96ae21e0c0460d

Contents?: true

Size: 1.88 KB

Versions: 6

Compression:

Stored size: 1.88 KB

Contents

# frozen_string_literal: true

module Spree
  class BackendConfiguration < Preferences::Configuration
    # An item which should be drawn in the admin menu
    class MenuItem
      attr_reader :icon, :label, :partial, :condition, :sections, :match_path

      attr_accessor :position

      # @param sections [Array<Symbol>] The sections which are contained within
      #   this admin menu section.
      # @param icon [String] The icon to draw for this menu item
      # @param condition [Proc] A proc which returns true if this menu item
      #   should be drawn. If nil, it will be replaced with a proc which always
      #   returns true.
      # @param label [Symbol] The translation key for a label to use for this
      #   menu item.
      # @param partial [String] A partial to draw within this menu item for use
      #   in declaring a submenu
      # @param url [String] A url where this link should send the user to
      # @param position [Integer] The position in which the menu item should render
      #   nil will cause the item to render last
      # @param match_path [String, Regexp, callable] (nil) If the {url} to determine the active tab is ambigous
      #   you can pass a String, Regexp or callable to identify this menu item. The callable
      #   accepts a request object and returns a Boolean value.
      def initialize(
        sections,
        icon,
        condition: nil,
        label: nil,
        partial: nil,
        url: nil,
        position: nil,
        match_path: nil
      )

        @condition = condition || -> { true }
        @sections = sections
        @icon = icon
        @label = label || sections.first
        @partial = partial
        @url = url
        @position = position
        @match_path = match_path
      end

      def url
        if @url.respond_to?(:call)
          @url.call
        else
          @url
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
solidus_backend-4.1.5 lib/spree/backend_configuration/menu_item.rb
solidus_backend-4.1.4 lib/spree/backend_configuration/menu_item.rb
solidus_backend-4.1.3 lib/spree/backend_configuration/menu_item.rb
solidus_backend-4.1.2 lib/spree/backend_configuration/menu_item.rb
solidus_backend-4.1.1 lib/spree/backend_configuration/menu_item.rb
solidus_backend-4.1.0 lib/spree/backend_configuration/menu_item.rb