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'),
  Scheme.new(6, 'None',            'none')
].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


23
24
25
# File 'lib/gitlab/color_schemes.rb', line 23

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


34
35
36
# File 'lib/gitlab/color_schemes.rb', line 34

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

.countObject

Returns the number of defined Schemes


39
40
41
# File 'lib/gitlab/color_schemes.rb', line 39

def self.count
  SCHEMES.size
end

.defaultObject

Get the default Scheme

Returns a Scheme


46
47
48
# File 'lib/gitlab/color_schemes.rb', line 46

def self.default
  by_id(1)
end

.each(&block) ⇒ Object

Iterate through each Scheme

Yields the Scheme object


53
54
55
# File 'lib/gitlab/color_schemes.rb', line 53

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


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

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

.valid_idsObject


70
71
72
# File 'lib/gitlab/color_schemes.rb', line 70

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