Skip to content

Commit dbb9d6a

Browse files
committed
Extract base abstract template for badges
1 parent 796efcc commit dbb9d6a

File tree

3 files changed

+51
-35
lines changed

3 files changed

+51
-35
lines changed

lib/gitlab/badge/build/template.rb

+1-17
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module Build
66
#
77
# Template object will be passed to badge.svg.erb template.
88
#
9-
class Template
9+
class Template < Badge::Template
1010
STATUS_COLOR = {
1111
success: '#4c1',
1212
failed: '#e05d44',
@@ -38,25 +38,9 @@ def value_width
3838
54
3939
end
4040

41-
def key_color
42-
'#555'
43-
end
44-
4541
def value_color
4642
STATUS_COLOR[@status.to_sym] || STATUS_COLOR[:unknown]
4743
end
48-
49-
def key_text_anchor
50-
key_width / 2
51-
end
52-
53-
def value_text_anchor
54-
key_width + (value_width / 2)
55-
end
56-
57-
def width
58-
key_width + value_width
59-
end
6044
end
6145
end
6246
end

lib/gitlab/badge/coverage/template.rb

+1-18
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module Coverage
66
#
77
# Template object will be passed to badge.svg.erb template.
88
#
9-
class Template
9+
class Template < Badge::Template
1010
STATUS_COLOR = {
1111
good: '#4c1',
1212
acceptable: '#b0c',
@@ -36,13 +36,8 @@ def value_width
3636
@status ? 32 : 58
3737
end
3838

39-
def key_color
40-
'#555'
41-
end
42-
4339
def value_color
4440
case @status
45-
when nil then STATUS_COLOR[:unknown]
4641
when 95..100 then STATUS_COLOR[:good]
4742
when 90..95 then STATUS_COLOR[:acceptable]
4843
when 75..90 then STATUS_COLOR[:medium]
@@ -51,18 +46,6 @@ def value_color
5146
STATUS_COLOR[:unknown]
5247
end
5348
end
54-
55-
def key_text_anchor
56-
key_width / 2
57-
end
58-
59-
def value_text_anchor
60-
key_width + (value_width / 2)
61-
end
62-
63-
def width
64-
key_width + value_width
65-
end
6649
end
6750
end
6851
end

lib/gitlab/badge/template.rb

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
module Gitlab
2+
module Badge
3+
##
4+
# Abstract template class for badges
5+
#
6+
class Template
7+
def initialize(badge)
8+
@entity = badge.entity
9+
@status = badge.status
10+
end
11+
12+
def key_text
13+
raise NotImplementedError
14+
end
15+
16+
def value_text
17+
raise NotImplementedError
18+
end
19+
20+
def key_width
21+
raise NotImplementedError
22+
end
23+
24+
def value_width
25+
raise NotImplementedError
26+
end
27+
28+
def value_color
29+
raise NotImplementedError
30+
end
31+
32+
def key_color
33+
'#555'
34+
end
35+
36+
def key_text_anchor
37+
key_width / 2
38+
end
39+
40+
def value_text_anchor
41+
key_width + (value_width / 2)
42+
end
43+
44+
def width
45+
key_width + value_width
46+
end
47+
end
48+
end
49+
end

0 commit comments

Comments
 (0)