Sha256: db93f29135bccfa38ada817e4460269920a8701fb579ad1fdf697b196c766b25

Contents?: true

Size: 939 Bytes

Versions: 7

Compression:

Stored size: 939 Bytes

Contents

# frozen_string_literal: true

module Satis
  module Menus
    class Item
      attr_reader :id, :link, :icon, :app, :menu, :link_attributes, :level, :type

      attr_writer :scope

      def initialize(id, link: nil, label: nil, icon: nil, link_attributes: {}, active: nil, scope: [], level: nil, type: :item, &block)
        @id = id
        @label = label
        @icon = icon
        @link = link
        @link_attributes = link_attributes
        @scope = scope
        @level = level
        @type = type
        @link_attributes = @link_attributes.merge(data: { action: 'click->satis-menu#toggle' }) if type == :toggle
        @menu = Menu.new(scope + ["#{id}_menu".to_sym], level: level + 1, &block) if block_given?
      end

      def label
        return @label if @label

        @label ||= I18n.t(id, scope: [:menu] + @scope, default: id.to_s.humanize)
      end

      def active?
        active
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
satis-1.0.75 lib/satis/menus/item.rb
satis-1.0.74 lib/satis/menus/item.rb
satis-1.0.70 lib/satis/menus/item.rb
satis-1.0.69 lib/satis/menus/item.rb
satis-1.0.68 lib/satis/menus/item.rb
satis-1.0.67 lib/satis/menus/item.rb
satis-1.0.66 lib/satis/menus/item.rb