Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2015-06-05 22:50:36 +0300
committerRobert Speicher <rspeicher@gmail.com>2015-06-14 00:58:16 +0300
commit844d72716e2175dcd5e39b4d1eecb9e3560aa0b9 (patch)
tree0df35c04333f7fb8dd970f0c984251952525663a /lib
parent658b42b1fa79c77b1acef67a645b36a2928a71bd (diff)
Add Gitlab::Themes module; remove Gitlab::Theme
Now we can simply loop through all themes, among other things. This also removes the `dark_theme` / `light_theme` classes and the `theme_type` helper, since they weren't used anywhere.
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/theme.rb50
-rw-r--r--lib/gitlab/themes.rb67
2 files changed, 67 insertions, 50 deletions
diff --git a/lib/gitlab/theme.rb b/lib/gitlab/theme.rb
deleted file mode 100644
index e5a1f1b44d9..00000000000
--- a/lib/gitlab/theme.rb
+++ /dev/null
@@ -1,50 +0,0 @@
-module Gitlab
- class Theme
- BASIC = 1 unless const_defined?(:BASIC)
- MARS = 2 unless const_defined?(:MARS)
- MODERN = 3 unless const_defined?(:MODERN)
- GRAY = 4 unless const_defined?(:GRAY)
- COLOR = 5 unless const_defined?(:COLOR)
- BLUE = 6 unless const_defined?(:BLUE)
-
- def self.classes
- @classes ||= {
- BASIC => 'ui_basic',
- MARS => 'ui_mars',
- MODERN => 'ui_modern',
- GRAY => 'ui_gray',
- COLOR => 'ui_color',
- BLUE => 'ui_blue'
- }
- end
-
- def self.css_class_by_id(id)
- id ||= Gitlab.config.gitlab.default_theme
- classes[id]
- end
-
- def self.types
- @types ||= {
- BASIC => 'light_theme',
- MARS => 'dark_theme',
- MODERN => 'dark_theme',
- GRAY => 'dark_theme',
- COLOR => 'dark_theme',
- BLUE => 'light_theme'
- }
- end
-
- def self.type_css_class_by_id(id)
- id ||= Gitlab.config.gitlab.default_theme
- types[id]
- end
-
- # Convenience method to get a space-separated String of all the theme
- # classes that might be applied to the `body` element
- #
- # Returns a String
- def self.body_classes
- (classes.values + types.values).uniq.join(' ')
- end
- end
-end
diff --git a/lib/gitlab/themes.rb b/lib/gitlab/themes.rb
new file mode 100644
index 00000000000..5209df92795
--- /dev/null
+++ b/lib/gitlab/themes.rb
@@ -0,0 +1,67 @@
+module Gitlab
+ # Module containing GitLab's application theme definitions and helper methods
+ # for accessing them.
+ module Themes
+ # Theme ID used when no `default_theme` configuration setting is provided.
+ APPLICATION_DEFAULT = 2
+
+ # Struct class representing a single Theme
+ Theme = Struct.new(:id, :name, :css_class)
+
+ # All available Themes
+ THEMES = [
+ Theme.new(1, 'Graphite', 'ui_graphite'),
+ Theme.new(2, 'Charcoal', 'ui_charcoal'),
+ Theme.new(3, 'Green', 'ui_green'),
+ Theme.new(4, 'Gray', 'ui_gray'),
+ Theme.new(5, 'Violet', 'ui_violet'),
+ Theme.new(6, 'Blue', 'ui_blue')
+ ].freeze
+
+ # Convenience method to get a space-separated String of all the theme
+ # classes that might be applied to the `body` element
+ #
+ # Returns a String
+ def self.body_classes
+ THEMES.collect(&:css_class).uniq.join(' ')
+ end
+
+ # Get a Theme by its ID
+ #
+ # If the ID is invalid, returns the default Theme.
+ #
+ # id - Integer ID
+ #
+ # Returns a Theme
+ def self.by_id(id)
+ THEMES.detect { |t| t.id == id } || default
+ end
+
+ # Get the default Theme
+ #
+ # Returns a Theme
+ def self.default
+ by_id(default_id)
+ end
+
+ # Iterate through each Theme
+ #
+ # Yields the Theme object
+ def self.each(&block)
+ THEMES.each(&block)
+ end
+
+ private
+
+ def self.default_id
+ id = Gitlab.config.gitlab.default_theme.to_i
+
+ # Prevent an invalid configuration setting from causing an infinite loop
+ if id < THEMES.first.id || id > THEMES.last.id
+ APPLICATION_DEFAULT
+ else
+ id
+ end
+ end
+ end
+end