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
iv
gitlab-ce
Commits
2e911721
Commit
2e911721
authored
Jan 24, 2016
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update text_color_for_bg helper to support RGB triplet color codes
Closes #12677
parent
07ee8393
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
1 deletion
+10
-1
app/helpers/labels_helper.rb
app/helpers/labels_helper.rb
+5
-1
spec/helpers/labels_helper_spec.rb
spec/helpers/labels_helper_spec.rb
+5
-0
No files found.
app/helpers/labels_helper.rb
View file @
2e911721
...
...
@@ -83,7 +83,11 @@ module LabelsHelper
end
def
text_color_for_bg
(
bg_color
)
r
,
g
,
b
=
bg_color
.
slice
(
1
,
7
).
scan
(
/.{2}/
).
map
(
&
:hex
)
if
bg_color
.
length
==
4
r
,
g
,
b
=
bg_color
[
1
,
4
].
scan
(
/./
).
map
{
|
v
|
(
v
*
2
).
hex
}
else
r
,
g
,
b
=
bg_color
[
1
,
7
].
scan
(
/.{2}/
).
map
(
&
:hex
)
end
if
(
r
+
g
+
b
)
>
500
'#333333'
...
...
spec/helpers/labels_helper_spec.rb
View file @
2e911721
...
...
@@ -66,5 +66,10 @@ describe LabelsHelper do
it
'uses dark text on light backgrounds'
do
expect
(
text_color_for_bg
(
'#EEEEEE'
)).
to
eq
(
'#333333'
)
end
it
'supports RGB triplets'
do
expect
(
text_color_for_bg
(
'#FFF'
)).
to
eq
'#333333'
expect
(
text_color_for_bg
(
'#000'
)).
to
eq
'#FFFFFF'
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