Commit 239d8ab3 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Refactor gitlab themes module to make it singleton

parent e9c09c92
...@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment