Refactor gitlab themes module to make it singleton
This commit is contained in:
parent
e9c09c92a7
commit
239d8ab30c
|
|
@ -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
|
||||||
# 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
|
||||||
# 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
|
||||||
# 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
|
||||||
|
|
||||||
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
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue