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
c6fde03a
Commit
c6fde03a
authored
Feb 22, 2022
by
Stanislav Lashmanov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Dark Mode support to the image_tag helper
Changelog: added
parent
f94e4488
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
0 deletions
+31
-0
app/helpers/lazy_image_tag_helper.rb
app/helpers/lazy_image_tag_helper.rb
+3
-0
app/helpers/preferences_helper.rb
app/helpers/preferences_helper.rb
+4
-0
spec/helpers/preferences_helper_spec.rb
spec/helpers/preferences_helper_spec.rb
+24
-0
No files found.
app/helpers/lazy_image_tag_helper.rb
View file @
c6fde03a
# frozen_string_literal: true
module
LazyImageTagHelper
include
PreferencesHelper
def
placeholder_image
"data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="
end
# Override the default ActionView `image_tag` helper to support lazy-loading
def
image_tag
(
source
,
options
=
{})
source
=
options
[
:dark_variant
]
if
options
[
:dark_variant
]
&&
user_application_dark_mode?
options
=
options
.
symbolize_keys
unless
options
.
delete
(
:lazy
)
==
false
...
...
app/helpers/preferences_helper.rb
View file @
c6fde03a
...
...
@@ -62,6 +62,10 @@ module PreferencesHelper
@user_application_theme
||=
Gitlab
::
Themes
.
for_user
(
current_user
).
css_class
end
def
user_application_dark_mode?
user_application_theme
==
'gl-dark'
end
def
user_application_theme_css_filename
@user_application_theme_css_filename
||=
Gitlab
::
Themes
.
for_user
(
current_user
).
css_filename
end
...
...
spec/helpers/preferences_helper_spec.rb
View file @
c6fde03a
...
...
@@ -96,6 +96,30 @@ RSpec.describe PreferencesHelper do
end
end
describe
'#user_application_dark_mode?'
do
context
'with a user'
do
it
"returns true if user's selected dark theme"
do
stub_user
(
theme_id:
11
)
expect
(
helper
.
user_application_dark_mode?
).
to
eq
true
end
it
"returns false if user's selected any light theme"
do
stub_user
(
theme_id:
1
)
expect
(
helper
.
user_application_dark_mode?
).
to
eq
false
end
end
context
'without a user'
do
it
'returns false'
do
stub_user
expect
(
helper
.
user_application_dark_mode?
).
to
eq
false
end
end
end
describe
'#user_color_scheme'
do
context
'with a user'
do
it
"returns user's scheme's css_class"
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