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
Tatuya Kamada
gitlab-ce
Commits
239d8ab3
Commit
239d8ab3
authored
Jul 19, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor gitlab themes module to make it singleton
parent
e9c09c92
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
7 deletions
+9
-7
lib/gitlab/themes.rb
lib/gitlab/themes.rb
+9
-7
No files found.
lib/gitlab/themes.rb
View file @
239d8ab3
...
@@ -2,6 +2,8 @@ module Gitlab
...
@@ -2,6 +2,8 @@ module Gitlab
# Module containing GitLab's application theme definitions and helper methods
# Module containing GitLab's application theme definitions and helper methods
# for accessing them.
# for accessing them.
module
Themes
module
Themes
extend
self
# Theme ID used when no `default_theme` configuration setting is provided.
# Theme ID used when no `default_theme` configuration setting is provided.
APPLICATION_DEFAULT
=
2
APPLICATION_DEFAULT
=
2
...
@@ -22,7 +24,7 @@ module Gitlab
...
@@ -22,7 +24,7 @@ module Gitlab
# classes that might be applied to the `body` element
# classes that might be applied to the `body` element
#
#
# Returns a String
# Returns a String
def
self
.
body_classes
def
body_classes
THEMES
.
collect
(
&
:css_class
).
uniq
.
join
(
' '
)
THEMES
.
collect
(
&
:css_class
).
uniq
.
join
(
' '
)
end
end
...
@@ -33,26 +35,26 @@ module Gitlab
...
@@ -33,26 +35,26 @@ module Gitlab
# id - Integer ID
# id - Integer ID
#
#
# Returns a Theme
# Returns a Theme
def
self
.
by_id
(
id
)
def
by_id
(
id
)
THEMES
.
detect
{
|
t
|
t
.
id
==
id
}
||
default
THEMES
.
detect
{
|
t
|
t
.
id
==
id
}
||
default
end
end
# Returns the number of defined Themes
# Returns the number of defined Themes
def
self
.
count
def
count
THEMES
.
size
THEMES
.
size
end
end
# Get the default Theme
# Get the default Theme
#
#
# Returns a Theme
# Returns a Theme
def
self
.
default
def
default
by_id
(
default_id
)
by_id
(
default_id
)
end
end
# Iterate through each Theme
# Iterate through each Theme
#
#
# Yields the Theme object
# Yields the Theme object
def
self
.
each
(
&
block
)
def
each
(
&
block
)
THEMES
.
each
(
&
block
)
THEMES
.
each
(
&
block
)
end
end
...
@@ -61,7 +63,7 @@ module Gitlab
...
@@ -61,7 +63,7 @@ module Gitlab
# user - User record
# user - User record
#
#
# Returns a Theme
# Returns a Theme
def
self
.
for_user
(
user
)
def
for_user
(
user
)
if
user
if
user
by_id
(
user
.
theme_id
)
by_id
(
user
.
theme_id
)
else
else
...
@@ -71,7 +73,7 @@ module Gitlab
...
@@ -71,7 +73,7 @@ module Gitlab
private
private
def
self
.
default_id
def
default_id
id
=
Gitlab
.
config
.
gitlab
.
default_theme
.
to_i
id
=
Gitlab
.
config
.
gitlab
.
default_theme
.
to_i
# Prevent an invalid configuration setting from causing an infinite loop
# Prevent an invalid configuration setting from causing an infinite loop
...
...
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