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
# File 'lib/gitlab/ci/badge/template.rb', line 13

def initialize(badge)
  @entity = badge.entity
  @status = badge.status
end

Instance Method Details

#key_colorObject


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

def key_color
  '#555'
end

#key_textObject


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

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

#key_text_anchorObject


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

def key_text_anchor
  key_width / 2
end

#key_widthObject


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

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)

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

def value_color
  raise NotImplementedError
end

#value_textObject

Raises:

  • (NotImplementedError)

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

def value_text
  raise NotImplementedError
end

#value_text_anchorObject


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

def value_text_anchor
  key_width + (value_width / 2)
end

#value_widthObject

Raises:

  • (NotImplementedError)

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

def value_width
  raise NotImplementedError
end

#widthObject


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

def width
  key_width + value_width
end