diff options
Diffstat (limited to 'app/helpers/tab_helper.rb')
-rw-r--r-- | app/helpers/tab_helper.rb | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/app/helpers/tab_helper.rb b/app/helpers/tab_helper.rb index e53e35baac3..2efc3f27dc7 100644 --- a/app/helpers/tab_helper.rb +++ b/app/helpers/tab_helper.rb @@ -14,8 +14,7 @@ module TabHelper gl_tabs_classes = %w[nav gl-tabs-nav] html_options = html_options.merge( - class: [*html_options[:class], gl_tabs_classes].join(' '), - role: 'tablist' + class: [*html_options[:class], gl_tabs_classes].join(' ') ) content = capture(&block) if block_given? @@ -54,7 +53,7 @@ module TabHelper extra_tab_classes = html_options.delete(:tab_class) tab_class = %w[nav-item].push(*extra_tab_classes) - content_tag(:li, class: tab_class, role: 'presentation') do + content_tag(:li, class: tab_class) do if block_given? link_to(options, html_options, &block) else @@ -63,6 +62,19 @@ module TabHelper end end + # Creates a <gl-badge> for use inside tabs. + # + # html_options - The html_options hash (default: {}) + def gl_tab_counter_badge(count, html_options = {}) + gl_badge_tag( + count, + { size: :sm }, + html_options.merge( + class: ['gl-tab-counter-badge', *html_options[:class]] + ) + ) + end + # Navigation link helper # # Returns an `li` element with an 'active' class if the supplied @@ -150,7 +162,7 @@ module TabHelper action = options.delete(:action) route_matches_paths?(options.delete(:path)) || - route_matches_pages?(options.delete(:page)) || + route_matches_page_without_exclusion?(options.delete(:page), options.delete(:exclude_page)) || route_matches_controllers_and_or_actions?(controller, action) end @@ -175,6 +187,13 @@ module TabHelper end end + def route_matches_page_without_exclusion?(pages, exclude_page) + return false unless route_matches_pages?(pages) + return true unless exclude_page.present? + + !route_matches_pages?(exclude_page) + end + def route_matches_pages?(pages) Array(pages).compact.any? do |single_page| # We need to distinguish between Hash argument and other types of @@ -211,12 +230,3 @@ module TabHelper current_page?(options) end end - -def gl_tab_counter_badge(count, html_options = {}) - badge_classes = %w[badge badge-muted badge-pill gl-badge sm gl-tab-counter-badge] - content_tag(:span, - count, - class: [*html_options[:class], badge_classes].join(' '), - data: html_options[:data] - ) -end |