diff options
author | Vasilii Iakliushin <viakliushin@gitlab.com> | 2020-11-17 15:53:23 +0300 |
---|---|---|
committer | Vasilii Iakliushin <viakliushin@gitlab.com> | 2020-11-17 15:53:23 +0300 |
commit | 23d527916bfdd5bebd4aa8bc0908101aaaa4c1c5 (patch) | |
tree | 08c735d7812e584fa6ee45d96591f0f39160cee7 /lib/gitlab | |
parent | dc11f0a1278fca878968ebdd0e3bdedb6d71c694 (diff) | |
parent | 2948b293efd2929944eaabfefcdd0f8c4465a06c (diff) |
Merge branch '879_disable_inactive_sections' into 'master'
Do not render inactive navigation sidebar sections
See merge request gitlab-org/gitlab-docs!1291
Diffstat (limited to 'lib/gitlab')
-rw-r--r-- | lib/gitlab/navigation.rb | 20 | ||||
-rw-r--r-- | lib/gitlab/navigation/section.rb | 7 |
2 files changed, 27 insertions, 0 deletions
diff --git a/lib/gitlab/navigation.rb b/lib/gitlab/navigation.rb index 052cdad5..ae5dbe9c 100644 --- a/lib/gitlab/navigation.rb +++ b/lib/gitlab/navigation.rb @@ -1,8 +1,14 @@ +require_relative '../helpers/generic' + module Gitlab class Navigation + include Nanoc::Helpers::Generic + def initialize(items, item) @items = items @item = item + + disable_inactive_sections! end def nav_items @@ -35,6 +41,20 @@ module Gitlab attr_reader :items, :item + def disable_inactive_sections! + return unless is_omnibus? + + children.each do |section| + section.disable! unless has_active_element?([section]) + end + end + + def has_active_element?(collection) + return false unless collection + + collection.any? { |element| show_element?(element) || has_active_element?(element.children) } + end + def dir @dir ||= item.identifier.to_s[%r{(?<=/)[^/]+}] end diff --git a/lib/gitlab/navigation/section.rb b/lib/gitlab/navigation/section.rb index 8b761fb8..82b19d3e 100644 --- a/lib/gitlab/navigation/section.rb +++ b/lib/gitlab/navigation/section.rb @@ -3,6 +3,13 @@ module Gitlab class Section def initialize(section) @section = section + @enabled = true + end + + attr_reader :enabled + + def disable! + @enabled = false end def title |