Class: Gitlab::Ci::Badge::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/ci/badge/template.rb

Overview

Abstract template class for badges

Constant Summary collapse

MAX_KEY_TEXT_SIZE =
64
MAX_KEY_WIDTH =
512
DEFAULT_KEY_WIDTH =
62

Instance Method Summary collapse

Constructor Details

#initialize(badge) ⇒ Template

Returns a new instance of Template.



13
14
15
16
17
# File 'lib/gitlab/ci/badge/template.rb', line 13

def initialize(badge)
  @entity = badge.entity
  @key_text = badge.customization.dig(:key_text)
  @key_width = badge.customization.dig(:key_width)
end

Instance Method Details

#key_colorObject



47
48
49
# File 'lib/gitlab/ci/badge/template.rb', line 47

def key_color
  '#555'
end

#key_textObject



19
20
21
22
23
24
25
# File 'lib/gitlab/ci/badge/template.rb', line 19

def key_text
  if @key_text && @key_text.size <= MAX_KEY_TEXT_SIZE
    @key_text
  else
    @entity.to_s
  end
end

#key_text_anchorObject



51
52
53
# File 'lib/gitlab/ci/badge/template.rb', line 51

def key_text_anchor
  key_width / 2
end

#key_widthObject



31
32
33
34
35
36
37
# File 'lib/gitlab/ci/badge/template.rb', line 31

def key_width
  if @key_width && @key_width.between?(1, MAX_KEY_WIDTH)
    @key_width
  else
    DEFAULT_KEY_WIDTH
  end
end

#value_colorObject

Raises:

  • (NotImplementedError)


43
44
45
# File 'lib/gitlab/ci/badge/template.rb', line 43

def value_color
  raise NotImplementedError
end

#value_textObject

Raises:

  • (NotImplementedError)


27
28
29
# File 'lib/gitlab/ci/badge/template.rb', line 27

def value_text
  raise NotImplementedError
end

#value_text_anchorObject



55
56
57
# File 'lib/gitlab/ci/badge/template.rb', line 55

def value_text_anchor
  key_width + (value_width / 2)
end

#value_widthObject

Raises:

  • (NotImplementedError)


39
40
41
# File 'lib/gitlab/ci/badge/template.rb', line 39

def value_width
  raise NotImplementedError
end

#widthObject



59
60
61
# File 'lib/gitlab/ci/badge/template.rb', line 59

def width
  key_width + value_width
end