Extract base abstract template for badges

This commit is contained in:
Grzegorz Bizon 2016-08-11 15:01:14 +02:00
parent 796efcc704
commit dbb9d6a726
3 changed files with 51 additions and 35 deletions

View file

@ -6,7 +6,7 @@ module Gitlab
#
# Template object will be passed to badge.svg.erb template.
#
class Template
class Template < Badge::Template
STATUS_COLOR = {
success: '#4c1',
failed: '#e05d44',
@ -38,25 +38,9 @@ module Gitlab
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

View file

@ -6,7 +6,7 @@ module Gitlab
#
# Template object will be passed to badge.svg.erb template.
#
class Template
class Template < Badge::Template
STATUS_COLOR = {
good: '#4c1',
acceptable: '#b0c',
@ -36,13 +36,8 @@ module Gitlab
@status ? 32 : 58
end
def key_color
'#555'
end
def value_color
case @status
when nil then STATUS_COLOR[:unknown]
when 95..100 then STATUS_COLOR[:good]
when 90..95 then STATUS_COLOR[:acceptable]
when 75..90 then STATUS_COLOR[:medium]
@ -51,18 +46,6 @@ module Gitlab
STATUS_COLOR[:unknown]
end
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

View file

@ -0,0 +1,49 @@
module Gitlab
module Badge
##
# Abstract template class for badges
#
class Template
def initialize(badge)
@entity = badge.entity
@status = badge.status
end
def key_text
raise NotImplementedError
end
def value_text
raise NotImplementedError
end
def key_width
raise NotImplementedError
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