Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
d2bd5e83
Commit
d2bd5e83
authored
Dec 25, 2014
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix nav_link support for several path options
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
f9ece12e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
20 deletions
+35
-20
app/helpers/tab_helper.rb
app/helpers/tab_helper.rb
+33
-19
app/views/layouts/nav/_profile.html.haml
app/views/layouts/nav/_profile.html.haml
+2
-1
No files found.
app/helpers/tab_helper.rb
View file @
d2bd5e83
...
@@ -28,6 +28,10 @@ module TabHelper
...
@@ -28,6 +28,10 @@ module TabHelper
# nav_link(controller: [:tree, :refs]) { "Hello" }
# nav_link(controller: [:tree, :refs]) { "Hello" }
# # => '<li class="active">Hello</li>'
# # => '<li class="active">Hello</li>'
#
#
# # Several paths
# nav_link(path: ['tree#show', 'profile#show']) { "Hello" }
# # => '<li class="active">Hello</li>'
#
# # Shorthand path
# # Shorthand path
# nav_link(path: 'tree#show') { "Hello" }
# nav_link(path: 'tree#show') { "Hello" }
# # => '<li class="active">Hello</li>'
# # => '<li class="active">Hello</li>'
...
@@ -38,25 +42,7 @@ module TabHelper
...
@@ -38,25 +42,7 @@ module TabHelper
#
#
# Returns a list item element String
# Returns a list item element String
def
nav_link
(
options
=
{},
&
block
)
def
nav_link
(
options
=
{},
&
block
)
if
path
=
options
.
delete
(
:path
)
klass
=
active_nav_link?
(
options
)
?
'active'
:
''
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
# Add our custom class into the html_options, which may or may not exist
# 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
# and which may or may not already have a :class key
...
@@ -72,6 +58,34 @@ module TabHelper
...
@@ -72,6 +58,34 @@ module TabHelper
end
end
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
def
project_tab_class
return
"active"
if
current_page?
(
controller:
"/projects"
,
action: :edit
,
id:
@project
)
return
"active"
if
current_page?
(
controller:
"/projects"
,
action: :edit
,
id:
@project
)
...
...
app/views/layouts/nav/_profile.html.haml
View file @
d2bd5e83
...
@@ -11,6 +11,7 @@
...
@@ -11,6 +11,7 @@
=
nav_link
(
path:
[
'profiles#applications'
,
'applications#edit'
,
'applications#show'
,
'applications#new'
])
do
=
nav_link
(
path:
[
'profiles#applications'
,
'applications#edit'
,
'applications#show'
,
'applications#new'
])
do
=
link_to
applications_profile_path
do
=
link_to
applications_profile_path
do
%i
.fa.fa-cloud
%i
.fa.fa-cloud
%span
Applications
Applications
=
nav_link
(
controller: :emails
)
do
=
nav_link
(
controller: :emails
)
do
=
link_to
profile_emails_path
do
=
link_to
profile_emails_path
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment