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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-01-24 15:09:01 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-01-24 15:09:01 +0300
commit2c2dd5e36c4ed5f09f488be288882d98f9124d12 (patch)
treead4c478bb1c588387a881b26a7db7c3237b9d4f3 /app/helpers/tab_helper.rb
parent2ff184ad761fbfbe25a3d827c8f704349963a8d2 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/helpers/tab_helper.rb')
-rw-r--r--app/helpers/tab_helper.rb11
1 files changed, 11 insertions, 0 deletions
diff --git a/app/helpers/tab_helper.rb b/app/helpers/tab_helper.rb
index 58edb327be0..0f156003a01 100644
--- a/app/helpers/tab_helper.rb
+++ b/app/helpers/tab_helper.rb
@@ -12,6 +12,7 @@ module TabHelper
# :action - One or more action names to check (optional).
# :path - A shorthand path, such as 'dashboard#index', to check (optional).
# :html_options - Extra options to be passed to the list element (optional).
+ # :unless - Callable object to skip rendering the 'active' class on `li` element (optional).
# block - An optional block that will become the contents of the returned
# `li` element.
#
@@ -56,6 +57,14 @@ module TabHelper
# nav_link(path: 'admin/appearances#show') { "Hello"}
# # => '<li class="active">Hello</li>'
#
+ # # Shorthand path + unless
+ # # Add `active` class when TreeController is requested, except the `index` action.
+ # nav_link(controller: 'tree', unless: -> { action_name?('index') }) { "Hello" }
+ # # => '<li class="active">Hello</li>'
+ #
+ # # When `TreeController#index` is requested
+ # # => '<li>Hello</li>'
+ #
# Returns a list item element String
def nav_link(options = {}, &block)
klass = active_nav_link?(options) ? 'active' : ''
@@ -73,6 +82,8 @@ module TabHelper
end
def active_nav_link?(options)
+ return false if options[:unless]&.call
+
if path = options.delete(:path)
unless path.respond_to?(:each)
path = [path]