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

Constant Summary collapse

SCHEMES =
[
  Scheme.new(1, 'White',           'white'),
  Scheme.new(2, 'Dark',            'dark'),
  Scheme.new(3, 'Solarized Light', 'solarized-light'),
  Scheme.new(4, 'Solarized Dark',  'solarized-dark'),
  Scheme.new(5, 'Monokai',         'monokai')
].freeze

Class Method Summary collapse

Class Method Details

.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


20
21
22
# File 'lib/gitlab/color_schemes.rb', line 20

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


31
32
33
# File 'lib/gitlab/color_schemes.rb', line 31

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

.countObject

Returns the number of defined Schemes


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

def self.count
  SCHEMES.size
end

.defaultObject

Get the default Scheme

Returns a Scheme


43
44
45
# File 'lib/gitlab/color_schemes.rb', line 43

def self.default
  by_id(1)
end

.each(&block) ⇒ Object

Iterate through each Scheme

Yields the Scheme object


50
51
52
# File 'lib/gitlab/color_schemes.rb', line 50

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

.for_user(user) ⇒ Object

Get the Scheme for the specified user, or the default

user - User record

Returns a Scheme


59
60
61
62
63
64
65
# File 'lib/gitlab/color_schemes.rb', line 59

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