diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-08-11 16:01:14 +0300 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-08-15 15:39:46 +0300 |
commit | dbb9d6a726285bdf59cc789aac584e712ea1280c (patch) | |
tree | 6278d3384533d543662990a3fc7359fb728bbb23 | |
parent | 796efcc704558119c1e5cb298d45a4f592662cb7 (diff) |
Extract base abstract template for badges
-rw-r--r-- | lib/gitlab/badge/build/template.rb | 18 | ||||
-rw-r--r-- | lib/gitlab/badge/coverage/template.rb | 19 | ||||
-rw-r--r-- | lib/gitlab/badge/template.rb | 49 |
3 files changed, 51 insertions, 35 deletions
diff --git a/lib/gitlab/badge/build/template.rb b/lib/gitlab/badge/build/template.rb index f52589ff736..2b95ddfcb53 100644 --- a/lib/gitlab/badge/build/template.rb +++ b/lib/gitlab/badge/build/template.rb @@ -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 diff --git a/lib/gitlab/badge/coverage/template.rb b/lib/gitlab/badge/coverage/template.rb index 6f9a38b07dc..49a10d3e8e1 100644 --- a/lib/gitlab/badge/coverage/template.rb +++ b/lib/gitlab/badge/coverage/template.rb @@ -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 diff --git a/lib/gitlab/badge/template.rb b/lib/gitlab/badge/template.rb new file mode 100644 index 00000000000..bfeb0052642 --- /dev/null +++ b/lib/gitlab/badge/template.rb @@ -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 |