Commit dbb9d6a7 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Extract base abstract template for badges

parent 796efcc7
...@@ -6,7 +6,7 @@ module Gitlab ...@@ -6,7 +6,7 @@ module Gitlab
# #
# Template object will be passed to badge.svg.erb template. # Template object will be passed to badge.svg.erb template.
# #
class Template class Template < Badge::Template
STATUS_COLOR = { STATUS_COLOR = {
success: '#4c1', success: '#4c1',
failed: '#e05d44', failed: '#e05d44',
...@@ -38,25 +38,9 @@ module Gitlab ...@@ -38,25 +38,9 @@ module Gitlab
54 54
end end
def key_color
'#555'
end
def value_color def value_color
STATUS_COLOR[@status.to_sym] || STATUS_COLOR[:unknown] STATUS_COLOR[@status.to_sym] || 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 end
end end
......
...@@ -6,7 +6,7 @@ module Gitlab ...@@ -6,7 +6,7 @@ module Gitlab
# #
# Template object will be passed to badge.svg.erb template. # Template object will be passed to badge.svg.erb template.
# #
class Template class Template < Badge::Template
STATUS_COLOR = { STATUS_COLOR = {
good: '#4c1', good: '#4c1',
acceptable: '#b0c', acceptable: '#b0c',
...@@ -36,13 +36,8 @@ module Gitlab ...@@ -36,13 +36,8 @@ module Gitlab
@status ? 32 : 58 @status ? 32 : 58
end end
def key_color
'#555'
end
def value_color def value_color
case @status case @status
when nil then STATUS_COLOR[:unknown]
when 95..100 then STATUS_COLOR[:good] when 95..100 then STATUS_COLOR[:good]
when 90..95 then STATUS_COLOR[:acceptable] when 90..95 then STATUS_COLOR[:acceptable]
when 75..90 then STATUS_COLOR[:medium] when 75..90 then STATUS_COLOR[:medium]
...@@ -51,18 +46,6 @@ module Gitlab ...@@ -51,18 +46,6 @@ module Gitlab
STATUS_COLOR[:unknown] STATUS_COLOR[:unknown]
end end
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 end
end end
......
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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment