Module: Gitlab::Themes

Defined in:
lib/gitlab/themes.rb

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.

2
THEMES =

All available 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

Class Method Summary collapse

Class Method Details

.body_classesObject

Convenience method to get a space-separated String of all the theme classes that might be applied to the `body` element

Returns a String


25
26
27
# File 'lib/gitlab/themes.rb', line 25

def self.body_classes
  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


36
37
38
# File 'lib/gitlab/themes.rb', line 36

def self.by_id(id)
  THEMES.detect { |t| t.id == id } || default
end

.countObject

Returns the number of defined Themes


41
42
43
# File 'lib/gitlab/themes.rb', line 41

def self.count
  THEMES.size
end

.defaultObject

Get the default Theme

Returns a Theme


48
49
50
# File 'lib/gitlab/themes.rb', line 48

def self.default
  by_id(default_id)
end

.each(&block) ⇒ Object

Iterate through each Theme

Yields the Theme object


55
56
57
# File 'lib/gitlab/themes.rb', line 55

def self.each(&block)
  THEMES.each(&block)
end

.for_user(user) ⇒ Object

Get the Theme for the specified user, or the default

user - User record

Returns a Theme


64
65
66
67
68
69
70
# File 'lib/gitlab/themes.rb', line 64

def self.for_user(user)
  if user
    by_id(user.theme_id)
  else
    default
  end
end