diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-12-25 20:51:07 +0200 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-12-25 20:51:07 +0200 |
commit | d2bd5e833fdcf5bbb039936a3f71eaf7ff829063 (patch) | |
tree | a5074c96bccfc2b2308f2ce8134cddc71057c7b9 /app | |
parent | f9ece12e872e9bf748f4daebfba88c341d4046f5 (diff) | |
download | gitlab-ce-d2bd5e833fdcf5bbb039936a3f71eaf7ff829063.tar.gz |
Fix nav_link support for several path options
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'app')
-rw-r--r-- | app/helpers/tab_helper.rb | 52 | ||||
-rw-r--r-- | app/views/layouts/nav/_profile.html.haml | 3 |
2 files changed, 35 insertions, 20 deletions
diff --git a/app/helpers/tab_helper.rb b/app/helpers/tab_helper.rb index bc43e078568..639fc98c222 100644 --- a/app/helpers/tab_helper.rb +++ b/app/helpers/tab_helper.rb @@ -28,6 +28,10 @@ module TabHelper # nav_link(controller: [:tree, :refs]) { "Hello" } # # => '<li class="active">Hello</li>' # + # # Several paths + # nav_link(path: ['tree#show', 'profile#show']) { "Hello" } + # # => '<li class="active">Hello</li>' + # # # Shorthand path # nav_link(path: 'tree#show') { "Hello" } # # => '<li class="active">Hello</li>' @@ -38,25 +42,7 @@ module TabHelper # # Returns a list item element String def nav_link(options = {}, &block) - if path = options.delete(:path) - if path.respond_to?(:each) - c = path.map { |p| p.split('#').first } - a = path.map { |p| p.split('#').last } - else - c, a, _ = path.split('#') - end - else - c = options.delete(:controller) - a = options.delete(:action) - end - - if c && a - # When given both options, make sure BOTH are active - klass = current_controller?(*c) && current_action?(*a) ? 'active' : '' - else - # Otherwise check EITHER option - klass = current_controller?(*c) || current_action?(*a) ? 'active' : '' - end + klass = active_nav_link?(options) ? 'active' : '' # Add our custom class into the html_options, which may or may not exist # and which may or may not already have a :class key @@ -72,6 +58,34 @@ module TabHelper end end + def active_nav_link?(options) + if path = options.delete(:path) + unless path.respond_to?(:each) + path = [path] + end + + path.any? do |single_path| + current_path?(single_path) + end + else + c = options.delete(:controller) + a = options.delete(:action) + + if c && a + # When given both options, make sure BOTH are true + current_controller?(*c) && current_action?(*a) + else + # Otherwise check EITHER option + current_controller?(*c) || current_action?(*a) + end + end + end + + def current_path?(path) + c, a, _ = path.split('#') + current_controller?(c) && current_action?(a) + end + def project_tab_class return "active" if current_page?(controller: "/projects", action: :edit, id: @project) diff --git a/app/views/layouts/nav/_profile.html.haml b/app/views/layouts/nav/_profile.html.haml index 2821e5c0668..36b48a5d02d 100644 --- a/app/views/layouts/nav/_profile.html.haml +++ b/app/views/layouts/nav/_profile.html.haml @@ -11,7 +11,8 @@ = nav_link(path: ['profiles#applications', 'applications#edit', 'applications#show', 'applications#new']) do = link_to applications_profile_path do %i.fa.fa-cloud - Applications + %span + Applications = nav_link(controller: :emails) do = link_to profile_emails_path do %i.fa.fa-envelope-o |