debian-mirror-gitlab/lib/gitlab/ci/badge/template.rb

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

65 lines
1.2 KiB
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
2021-03-11 19:13:27 +05:30
module Gitlab::Ci
2016-09-13 17:45:13 +05:30
module Badge
##
# Abstract template class for badges
#
class Template
2020-11-24 15:15:51 +05:30
MAX_KEY_TEXT_SIZE = 64
MAX_KEY_WIDTH = 512
2021-09-04 01:27:46 +05:30
DEFAULT_KEY_WIDTH = 62
2020-06-23 00:09:42 +05:30
2016-09-13 17:45:13 +05:30
def initialize(badge)
@entity = badge.entity
2022-07-16 23:28:13 +05:30
@key_text = badge.customization.dig(:key_text)
@key_width = badge.customization.dig(:key_width)
2016-09-13 17:45:13 +05:30
end
def key_text
2021-09-04 01:27:46 +05:30
if @key_text && @key_text.size <= MAX_KEY_TEXT_SIZE
@key_text
else
@entity.to_s
end
2016-09-13 17:45:13 +05:30
end
def value_text
raise NotImplementedError
end
def key_width
2021-09-04 01:27:46 +05:30
if @key_width && @key_width.between?(1, MAX_KEY_WIDTH)
@key_width
else
DEFAULT_KEY_WIDTH
end
2016-09-13 17:45:13 +05:30
end
def value_width
raise NotImplementedError
end
def value_color
raise NotImplementedError
end
def key_color
'#555'
end
def key_text_anchor
key_width / 2
end
def value_text_anchor
key_width + (value_width / 2)
end
def width
key_width + value_width
end
end
end
end