Module: Gitlab::Themes
Overview
Module containing GitLab’s application theme definitions and helper methods for accessing them.
Defined Under Namespace
Classes: Theme
Constant Summary collapse
- APPLICATION_DEFAULT =
Theme ID used when no ‘default_theme` configuration setting is provided.
3
Class Method Summary collapse
Instance Method Summary collapse
-
#available_themes ⇒ Object
All available Themes.
-
#body_classes ⇒ Object
Convenience method to get a space-separated String of all the theme classes that might be applied to the ‘body` element.
-
#by_id(id) ⇒ Object
Get a Theme by its ID.
-
#count ⇒ Object
Returns the number of defined Themes.
-
#default ⇒ Object
Get the default Theme.
-
#each(&block) ⇒ Object
Iterate through each Theme.
-
#for_user(user) ⇒ Object
Get the Theme for the specified user, or the default.
Class Method Details
.valid_ids ⇒ Object
83 84 85 |
# File 'lib/gitlab/themes.rb', line 83 def self.valid_ids available_themes.map(&:id) end |
Instance Method Details
#available_themes ⇒ Object
All available Themes
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/gitlab/themes.rb', line 16 def available_themes [ Theme.new(1, s_('NavigationTheme|Indigo'), 'ui-indigo', 'theme_indigo', '#222261'), Theme.new(6, s_('NavigationTheme|Light Indigo'), 'ui-light-indigo', 'theme_light_indigo', '#41419f'), Theme.new(4, s_('NavigationTheme|Blue'), 'ui-blue', 'theme_blue', '#0b2640'), Theme.new(7, s_('NavigationTheme|Light Blue'), 'ui-light-blue', 'theme_light_blue', '#145aa1'), Theme.new(5, s_('NavigationTheme|Green'), 'ui-green', 'theme_green', '#0e4328'), Theme.new(8, s_('NavigationTheme|Light Green'), 'ui-light-green', 'theme_light_green', '#1b653f'), Theme.new(9, s_('NavigationTheme|Red'), 'ui-red', 'theme_red', '#580d02'), Theme.new(10, s_('NavigationTheme|Light Red'), 'ui-light-red', 'theme_light_red', '#a02e1c'), Theme.new(2, s_('NavigationTheme|Gray'), 'ui-gray', 'theme_gray', '#333238'), Theme.new(3, s_('NavigationTheme|Light Gray'), 'ui-light-gray', 'theme_light_gray', '#ececef'), Theme.new(11, s_('NavigationTheme|Dark Mode (alpha)'), 'gl-dark', nil, '#1f1e24') ] end |
#body_classes ⇒ Object
Convenience method to get a space-separated String of all the theme classes that might be applied to the ‘body` element
Returns a String
36 37 38 |
# File 'lib/gitlab/themes.rb', line 36 def body_classes available_themes.collect(&:css_class).uniq.join(' ') end |
#by_id(id) ⇒ Object
Get a Theme by its ID
If the ID is invalid, returns the default Theme.
id - Integer ID
Returns a Theme
47 48 49 |
# File 'lib/gitlab/themes.rb', line 47 def by_id(id) available_themes.detect { |t| t.id == id } || default end |
#count ⇒ Object
Returns the number of defined Themes
52 53 54 |
# File 'lib/gitlab/themes.rb', line 52 def count available_themes.size end |
#default ⇒ Object
Get the default Theme
Returns a Theme
59 60 61 |
# File 'lib/gitlab/themes.rb', line 59 def default by_id(default_id) end |
#each(&block) ⇒ Object
Iterate through each Theme
Yields the Theme object
66 67 68 |
# File 'lib/gitlab/themes.rb', line 66 def each(&block) available_themes.each(&block) end |
#for_user(user) ⇒ Object
Get the Theme for the specified user, or the default
user - User record
Returns a Theme
75 76 77 78 79 80 81 |
# File 'lib/gitlab/themes.rb', line 75 def for_user(user) if user by_id(user.theme_id) else default end end |