Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-08-11 15:46:47 +0300
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-08-15 15:39:46 +0300
commit796efcc704558119c1e5cb298d45a4f592662cb7 (patch)
tree2536fb103fd5e2504377dc7c1a264381cdf9ee65 /lib/gitlab/badge
parentcc244160c5e2ecda2818348cb6b909f1dcb96e44 (diff)
Add template class for coverage report badge
Diffstat (limited to 'lib/gitlab/badge')
-rw-r--r--lib/gitlab/badge/coverage/template.rb69
1 files changed, 69 insertions, 0 deletions
diff --git a/lib/gitlab/badge/coverage/template.rb b/lib/gitlab/badge/coverage/template.rb
new file mode 100644
index 00000000000..6f9a38b07dc
--- /dev/null
+++ b/lib/gitlab/badge/coverage/template.rb
@@ -0,0 +1,69 @@
+module Gitlab
+ module Badge
+ module Coverage
+ ##
+ # Class that represents a coverage badge template.
+ #
+ # Template object will be passed to badge.svg.erb template.
+ #
+ class Template
+ STATUS_COLOR = {
+ good: '#4c1',
+ acceptable: '#b0c',
+ medium: '#dfb317',
+ low: '#e05d44',
+ unknown: '#9f9f9f'
+ }
+
+ def initialize(badge)
+ @entity = badge.entity
+ @status = badge.status
+ end
+
+ def key_text
+ @entity.to_s
+ end
+
+ def value_text
+ @status ? "#{@status}%" : 'unknown'
+ end
+
+ def key_width
+ 62
+ end
+
+ def value_width
+ @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]
+ when 0..75 then STATUS_COLOR[:low]
+ else
+ 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