debian-mirror-gitlab/lib/gitlab/color_schemes.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

77 lines
1.9 KiB
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
2015-09-25 12:07:36 +05:30
module Gitlab
# Module containing GitLab's syntax color scheme definitions and helper
# methods for accessing them.
module ColorSchemes
# Struct class representing a single Scheme
Scheme = Struct.new(:id, :name, :css_class)
2022-03-02 08:16:31 +05:30
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
2015-09-25 12:07:36 +05:30
# 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
def self.body_classes
2022-03-02 08:16:31 +05:30
available_schemes.collect(&:css_class).uniq.join(' ')
2015-09-25 12:07:36 +05:30
end
# Get a Scheme by its ID
#
# If the ID is invalid, returns the default Scheme.
#
# id - Integer ID
#
# Returns a Scheme
def self.by_id(id)
2022-03-02 08:16:31 +05:30
available_schemes.detect { |s| s.id == id } || default
2015-09-25 12:07:36 +05:30
end
# Returns the number of defined Schemes
def self.count
2022-03-02 08:16:31 +05:30
available_schemes.size
2015-09-25 12:07:36 +05:30
end
# Get the default Scheme
#
# Returns a Scheme
def self.default
by_id(1)
end
# Iterate through each Scheme
#
# Yields the Scheme object
def self.each(&block)
2022-03-02 08:16:31 +05:30
available_schemes.each(&block)
2015-09-25 12:07:36 +05:30
end
# Get the Scheme for the specified user, or the default
#
# user - User record
#
# Returns a Scheme
def self.for_user(user)
if user
by_id(user.color_scheme_id)
else
default
end
end
2020-03-13 15:44:24 +05:30
def self.valid_ids
2022-03-02 08:16:31 +05:30
available_schemes.map(&:id)
2020-03-13 15:44:24 +05:30
end
2015-09-25 12:07:36 +05:30
end
end