Module: Gitlab::ColorSchemes

Defined in:
lib/gitlab/color_schemes.rb

Overview

Module containing GitLab's syntax color scheme definitions and helper methods for accessing them.

Defined Under Namespace

Classes: Scheme

Class Method Summary collapse

Class Method Details

.available_schemesObject


10
11
12
13
14
15
16
17
18
19
# File 'lib/gitlab/color_schemes.rb', line 10

def self.available_schemes
  [
    Scheme.new(1, s_('SynthaxHighlightingTheme|Light'),           'white'),
    Scheme.new(2, s_('SynthaxHighlightingTheme|Dark'),            'dark'),
    Scheme.new(3, s_('SynthaxHighlightingTheme|Solarized Light'), 'solarized-light'),
    Scheme.new(4, s_('SynthaxHighlightingTheme|Solarized Dark'),  'solarized-dark'),
    Scheme.new(5, s_('SynthaxHighlightingTheme|Monokai'),         'monokai'),
    Scheme.new(6, s_('SynthaxHighlightingTheme|None'),            'none')
  ]
end

.body_classesObject

Convenience method to get a space-separated String of all the color scheme classes that might be applied to a code block.

Returns a String


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

def self.body_classes
  available_schemes.collect(&:css_class).uniq.join(' ')
end

.by_id(id) ⇒ Object

Get a Scheme by its ID

If the ID is invalid, returns the default Scheme.

id - Integer ID

Returns a Scheme


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

def self.by_id(id)
  available_schemes.detect { |s| s.id == id } || default
end

.countObject

Returns the number of defined Schemes


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

def self.count
  available_schemes.size
end

.defaultObject

Get the default Scheme

Returns a Scheme


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

def self.default
  by_id(1)
end

.each(&block) ⇒ Object

Iterate through each Scheme

Yields the Scheme object


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

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

.for_user(user) ⇒ Object

Get the Scheme for the specified user, or the default

user - User record

Returns a Scheme


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

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

.valid_idsObject


72
73
74
# File 'lib/gitlab/color_schemes.rb', line 72

def self.valid_ids
  available_schemes.map(&:id)
end