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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
a4d6ef58
Commit
a4d6ef58
authored
Nov 11, 2021
by
Jan Provaznik
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'kp-update-tab-helpers' into 'master'
Update GlTab helpers See merge request gitlab-org/gitlab!74181
parents
57405567
09d95dca
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
3 deletions
+19
-3
app/helpers/tab_helper.rb
app/helpers/tab_helper.rb
+4
-2
spec/helpers/tab_helper_spec.rb
spec/helpers/tab_helper_spec.rb
+15
-1
No files found.
app/helpers/tab_helper.rb
View file @
a4d6ef58
...
@@ -33,7 +33,6 @@ module TabHelper
...
@@ -33,7 +33,6 @@ module TabHelper
# :item_active - Overrides the default state focing the "active" css classes (optional).
# :item_active - Overrides the default state focing the "active" css classes (optional).
#
#
def
gl_tab_link_to
(
name
=
nil
,
options
=
{},
html_options
=
{},
&
block
)
def
gl_tab_link_to
(
name
=
nil
,
options
=
{},
html_options
=
{},
&
block
)
tab_class
=
'nav-item'
link_classes
=
%w[nav-link gl-tab-nav-item]
link_classes
=
%w[nav-link gl-tab-nav-item]
active_link_classes
=
%w[active gl-tab-nav-item-active gl-tab-nav-item-active-indigo]
active_link_classes
=
%w[active gl-tab-nav-item-active gl-tab-nav-item-active-indigo]
...
@@ -52,6 +51,8 @@ module TabHelper
...
@@ -52,6 +51,8 @@ module TabHelper
end
end
html_options
=
html_options
.
except
(
:item_active
)
html_options
=
html_options
.
except
(
:item_active
)
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
,
role:
'presentation'
)
do
if
block_given?
if
block_given?
...
@@ -215,6 +216,7 @@ def gl_tab_counter_badge(count, html_options = {})
...
@@ -215,6 +216,7 @@ def gl_tab_counter_badge(count, html_options = {})
badge_classes
=
%w[badge badge-muted badge-pill gl-badge sm gl-tab-counter-badge]
badge_classes
=
%w[badge badge-muted badge-pill gl-badge sm gl-tab-counter-badge]
content_tag
(
:span
,
content_tag
(
:span
,
count
,
count
,
class:
[
*
html_options
[
:class
],
badge_classes
].
join
(
' '
)
class:
[
*
html_options
[
:class
],
badge_classes
].
join
(
' '
),
data:
html_options
[
:data
]
)
)
end
end
spec/helpers/tab_helper_spec.rb
View file @
a4d6ef58
...
@@ -36,7 +36,15 @@ RSpec.describe TabHelper do
...
@@ -36,7 +36,15 @@ RSpec.describe TabHelper do
expect
(
gl_tab_link_to
(
'/url'
)
{
'block content'
}).
to
match
(
/block content/
)
expect
(
gl_tab_link_to
(
'/url'
)
{
'block content'
}).
to
match
(
/block content/
)
end
end
it
'creates a tab with custom classes'
do
it
'creates a tab with custom classes for enclosing list item without content block provided'
do
expect
(
gl_tab_link_to
(
'Link'
,
'/url'
,
{
tab_class:
'my-class'
})).
to
match
(
/<li class=".*my-class.*"/
)
end
it
'creates a tab with custom classes for enclosing list item with content block provided'
do
expect
(
gl_tab_link_to
(
'/url'
,
{
tab_class:
'my-class'
})
{
'Link'
}).
to
match
(
/<li class=".*my-class.*"/
)
end
it
'creates a tab with custom classes for anchor element'
do
expect
(
gl_tab_link_to
(
'Link'
,
'/url'
,
{
class:
'my-class'
})).
to
match
(
/<a class=".*my-class.*"/
)
expect
(
gl_tab_link_to
(
'Link'
,
'/url'
,
{
class:
'my-class'
})).
to
match
(
/<a class=".*my-class.*"/
)
end
end
...
@@ -161,5 +169,11 @@ RSpec.describe TabHelper do
...
@@ -161,5 +169,11 @@ RSpec.describe TabHelper do
expect
(
gl_tab_counter_badge
(
1
,
{
class:
'js-test'
})).
to
eq
(
'<span class="js-test badge badge-muted badge-pill gl-badge sm gl-tab-counter-badge">1</span>'
)
expect
(
gl_tab_counter_badge
(
1
,
{
class:
'js-test'
})).
to
eq
(
'<span class="js-test badge badge-muted badge-pill gl-badge sm gl-tab-counter-badge">1</span>'
)
end
end
end
end
context
'with data attributes'
do
it
'creates a tab counter badge with the data attributes'
do
expect
(
gl_tab_counter_badge
(
1
,
{
data:
{
some_attribute:
'foo'
}
})).
to
eq
(
'<span class="badge badge-muted badge-pill gl-badge sm gl-tab-counter-badge" data-some-attribute="foo">1</span>'
)
end
end
end
end
end
end
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