summaryrefslogtreecommitdiff
path: root/lib/gitlab/badge/build/template.rb
blob: deba3b669b3af96421779373989e812a26d0fb6e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
module Gitlab
  module Badge
    class Build
      ##
      # Class that represents a build badge template.
      #
      # Template object will be passed to badge.svg.erb template.
      #
      class Template
        STATUS_COLOR = {
          success: '#4c1',
          failed: '#e05d44',
          running: '#dfb317',
          pending: '#dfb317',
          canceled: '#9f9f9f',
          skipped: '#9f9f9f',
          unknown: '#9f9f9f'
        }

        def initialize(status)
          @status = status
        end

        def key_text
          'build'
        end

        def value_text
          @status
        end

        def key_width
          38
        end

        def value_width
          54
        end

        def key_color
          '#555'
        end

        def value_color
          STATUS_COLOR[@status.to_sym] ||
            STATUS_COLOR[:unknown]
        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
end