Welcome to mirror list, hosted at ThFree Co, Russian Federation.

top_nav_menu_builder.rb « nav « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: dca3432a6a101f40ef1497e9386fd43923966759 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# frozen_string_literal: true

module Gitlab
  module Nav
    class TopNavMenuBuilder
      def initialize
        @primary = []
        @secondary = []
        @last_header_added = nil
      end

      def add_primary_menu_item(header: nil, **args)
        if header && (header != @last_header_added)
          add_menu_header(dest: @primary, title: header)
          @last_header_added = header
        end

        add_menu_item(dest: @primary, **args)
      end

      def add_secondary_menu_item(**args)
        add_menu_item(dest: @secondary, **args)
      end

      def build
        {
          primary: @primary,
          secondary: @secondary
        }
      end

      private

      def add_menu_item(dest:, **args)
        item = ::Gitlab::Nav::TopNavMenuItem.build(**args)

        dest.push(item)
      end

      def add_menu_header(dest:, **args)
        header = ::Gitlab::Nav::TopNavMenuHeader.build(**args)

        dest.push(header)
      end
    end
  end
end