repo-small-badge 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/badges/coverage_badge_total.svg +31 -0
- data/lib/repo_small_badge/configuration.rb +97 -0
- data/lib/repo_small_badge/image.rb +47 -86
- data/lib/repo_small_badge/version.rb +1 -1
- data/spec/repo_small_badge_spec.rb +10 -1
- data/spec/support/mocks.rb +9 -4
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d5f7992964dd9cad861f7a69f7570b743362c4edce645a770f54fc16cb5e7ca
|
4
|
+
data.tar.gz: 67351cf68c32503cb1e73cd15b995b2aecc188b940e435bec4878f8076aeb59c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f2f91a28b8f2de41c4c2f7ba3d48195e73cdba2520faec4ea2e53667f7f0b33a5a3950b94ab6a41fcf2016c38bfd0ba04ea469084f0b4b5376e5aa74bd99c5e
|
7
|
+
data.tar.gz: 99254c8a452c4d4997c2ce4f55606cddb1038967e029d03a5a07061b43c88b493ec72a01f44210c9de7fea138d41d2f8ae5a00c19b8a4490675744711e071ffa
|
data/.gitignore
CHANGED
@@ -0,0 +1,31 @@
|
|
1
|
+
<svg contentScriptType="text/ecmascript" contentStyleType="text/css" preserveAspectRatio="xMidYMid meet" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" version="1.0" height="20" width="100%">
|
2
|
+
|
3
|
+
<linearGradient id="smooth" x2="0" y2="100%">
|
4
|
+
<stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
|
5
|
+
<stop offset="1" stop-opacity=".1"/>
|
6
|
+
</linearGradient>
|
7
|
+
<clipPath id="round">
|
8
|
+
<rect height="20" width="200" rx="3" fill="#fff"/>
|
9
|
+
</clipPath>
|
10
|
+
<g clip-path="url(#round)">
|
11
|
+
<rect height="20" width="100" fill="#555"/>
|
12
|
+
<rect x="100" height="20" width="100" fill="#4dc71f"/>
|
13
|
+
<rect height="20" width="200" fill="url(#smooth)"/>
|
14
|
+
</g>
|
15
|
+
<g fill="#fff" text-anchor="middle" font-family="Helvetica" size="16">
|
16
|
+
<text x="50" y="15" fill="#010101" fill-opacity="0.3">
|
17
|
+
scov total
|
18
|
+
</text>
|
19
|
+
<text x="50" y="14">
|
20
|
+
scov total
|
21
|
+
</text>
|
22
|
+
</g>
|
23
|
+
<g fill="#fff" text-anchor="middle" font-family="Helvetica-Narrow-Bold" size="16">
|
24
|
+
<text x="150" y="15" fill="#010101" fill-opacity="0.3">
|
25
|
+
100%
|
26
|
+
</text>
|
27
|
+
<text x="150" y="14">
|
28
|
+
100%
|
29
|
+
</text>
|
30
|
+
</g>
|
31
|
+
</svg>
|
@@ -0,0 +1,97 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RepoSmallBadge
|
4
|
+
# Hidden class to handle the interface to configuration
|
5
|
+
class Configuration
|
6
|
+
def initialize(config_hash)
|
7
|
+
@config = config_hash
|
8
|
+
end
|
9
|
+
|
10
|
+
def merge!(new_config)
|
11
|
+
@config.merge!(new_config)
|
12
|
+
end
|
13
|
+
|
14
|
+
def value_background
|
15
|
+
@config.fetch(:value_background, '#4c1')
|
16
|
+
end
|
17
|
+
|
18
|
+
def value_color
|
19
|
+
@config.fetch(:value_color, title_color)
|
20
|
+
end
|
21
|
+
|
22
|
+
def value_font
|
23
|
+
@config.fetch(:value_font, font)
|
24
|
+
end
|
25
|
+
|
26
|
+
def value_font_size
|
27
|
+
@config.fetch(:value_font_size, font_size)
|
28
|
+
end
|
29
|
+
|
30
|
+
def title_background
|
31
|
+
@config.fetch(:title_background, '#555')
|
32
|
+
end
|
33
|
+
|
34
|
+
def background
|
35
|
+
@config.fetch(:background, '#fff')
|
36
|
+
end
|
37
|
+
|
38
|
+
def title_font
|
39
|
+
@config.fetch(:title_font, font)
|
40
|
+
end
|
41
|
+
|
42
|
+
def title_font_size
|
43
|
+
@config.fetch(:title_font_size, font_size)
|
44
|
+
end
|
45
|
+
|
46
|
+
def title_color
|
47
|
+
@config.fetch(:title_color, '#fff')
|
48
|
+
end
|
49
|
+
|
50
|
+
def font
|
51
|
+
@config.fetch(:font, 'Verdana,sans-serif')
|
52
|
+
end
|
53
|
+
|
54
|
+
def font_size
|
55
|
+
@config.fetch(:font_size, 11).to_s
|
56
|
+
end
|
57
|
+
|
58
|
+
def rounded_edge_radius
|
59
|
+
if @config.fetch(:rounded_border, true)
|
60
|
+
@config.fetch(:rounded_edge_radius, '3')
|
61
|
+
else
|
62
|
+
0
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def badge_width
|
67
|
+
@config.fetch(:badge_width, 120).to_i
|
68
|
+
end
|
69
|
+
|
70
|
+
def badge_height
|
71
|
+
@config.fetch(:badge_height, 20).to_i
|
72
|
+
end
|
73
|
+
|
74
|
+
def badge_middle
|
75
|
+
badge_width / 2
|
76
|
+
end
|
77
|
+
|
78
|
+
def filename(suffix = '')
|
79
|
+
prefix = @config.fetch(:filename_prefix, 'badge')
|
80
|
+
format = @config.fetch(:format, 'svg')
|
81
|
+
"#{output_path}/#{prefix}_#{suffix}.#{format}"
|
82
|
+
end
|
83
|
+
|
84
|
+
def title(suffix)
|
85
|
+
prefix = @config.fetch(:title_prefix, '')
|
86
|
+
if prefix.to_s.empty?
|
87
|
+
suffix
|
88
|
+
else
|
89
|
+
"#{@config.fetch(:title_prefix, '')} #{suffix}"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def output_path
|
94
|
+
@config.fetch(:output_path, '.')
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -1,20 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'victor'
|
4
|
+
require 'repo_small_badge/configuration'
|
4
5
|
|
5
6
|
module RepoSmallBadge
|
6
|
-
#
|
7
|
-
#
|
7
|
+
# Class that creates the Badge SVG image.
|
8
|
+
# Behaviour is defined by the configuration hash.
|
9
|
+
# For the different configurables see RepoSmallBadge::Configuration.
|
8
10
|
class Image < Victor::SVGBase
|
9
11
|
# Create new instance.
|
10
12
|
# @config is a Hash of configurables. Keys are symbols.
|
11
13
|
def initialize(config = {})
|
12
|
-
@config = config
|
14
|
+
@config = Configuration.new(config)
|
13
15
|
super(template: :html, contentScriptType: 'text/ecmascript',
|
14
16
|
contentStyleType: 'text/css', preserveAspectRatio: 'xMidYMid meet',
|
15
17
|
'xmlns:xlink': 'http://www.w3.org/1999/xlink',
|
16
18
|
xmlns: 'http://www.w3.org/2000/svg', version: '1.0',
|
17
|
-
height: badge_height)
|
19
|
+
height: @config.badge_height)
|
18
20
|
end
|
19
21
|
|
20
22
|
# Creates the badge.
|
@@ -23,15 +25,17 @@ module RepoSmallBadge
|
|
23
25
|
# @value is the overall value to be written to the right side of the badge.
|
24
26
|
def badge(name, title, value)
|
25
27
|
svg_header
|
28
|
+
svg_rounded_box
|
26
29
|
svg_boxes
|
27
|
-
|
28
|
-
|
30
|
+
svg_title(title)
|
31
|
+
svg_value(value)
|
32
|
+
save(@config.filename(name))
|
29
33
|
end
|
30
34
|
|
31
35
|
# Updates the configuration settings and overwrites existing ones.
|
32
36
|
# @config the hash that has to be merged.
|
33
37
|
def config_merge(config)
|
34
|
-
@config.merge(config)
|
38
|
+
@config.merge!(config)
|
35
39
|
end
|
36
40
|
|
37
41
|
private
|
@@ -43,100 +47,57 @@ module RepoSmallBadge
|
|
43
47
|
end
|
44
48
|
end
|
45
49
|
|
50
|
+
# rubocop:disable Metrics/MethodLength
|
46
51
|
def svg_boxes
|
47
|
-
middle = badge_width / 2
|
48
|
-
svg_rounded_box
|
49
|
-
|
50
52
|
element :g, 'clip-path' => 'url(#round)' do
|
51
|
-
element :rect, height: badge_height,
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
width:
|
53
|
+
element :rect, height: @config.badge_height,
|
54
|
+
width: @config.badge_middle,
|
55
|
+
fill: @config.title_background
|
56
|
+
element :rect, x: @config.badge_middle,
|
57
|
+
height: @config.badge_height,
|
58
|
+
width: @config.badge_middle,
|
59
|
+
fill: @config.value_background
|
60
|
+
element :rect, height: @config.badge_height,
|
61
|
+
width: @config.badge_width, fill: 'url(#smooth)'
|
57
62
|
end
|
63
|
+
# rubocop:enable Metrics/MethodLength
|
58
64
|
end
|
59
65
|
|
60
66
|
def svg_rounded_box
|
61
67
|
element :clipPath, id: 'round' do
|
62
|
-
element :rect, height: badge_height, width: badge_width,
|
63
|
-
rx: rounded_edge_radius, fill: background
|
68
|
+
element :rect, height: @config.badge_height, width: @config.badge_width,
|
69
|
+
rx: @config.rounded_edge_radius, fill: @config.background
|
64
70
|
end
|
65
71
|
end
|
66
72
|
|
67
73
|
# rubocop:disable Metrics/AbcSize
|
68
|
-
def
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
element :text, title(title),
|
73
|
-
|
74
|
-
|
75
|
-
element :text,
|
76
|
-
|
77
|
-
element :text, value, x: middle / 2 + middle, y: badge_height - 6
|
78
|
-
end
|
79
|
-
end
|
80
|
-
# rubocop:enable Metrics/AbcSize
|
81
|
-
|
82
|
-
def value_background
|
83
|
-
@config.fetch(:value_background, '#4c1')
|
84
|
-
end
|
85
|
-
|
86
|
-
def title_background
|
87
|
-
@config.fetch(:title_background, '#555')
|
88
|
-
end
|
89
|
-
|
90
|
-
def background
|
91
|
-
@config.fetch(:background, '#fff')
|
92
|
-
end
|
93
|
-
|
94
|
-
def title_color
|
95
|
-
@config.fetch(:title_color, '#fff')
|
96
|
-
end
|
97
|
-
|
98
|
-
def font
|
99
|
-
@config.fetch(:font, 'Verdana,sans-serif')
|
100
|
-
end
|
101
|
-
|
102
|
-
def font_size
|
103
|
-
@config.fetch(:font_size, 11).to_s
|
104
|
-
end
|
105
|
-
|
106
|
-
def rounded_edge_radius
|
107
|
-
if @config.fetch(:rounded_border, true)
|
108
|
-
@config.fetch(:rounded_edge_radius, '3')
|
109
|
-
else
|
110
|
-
0
|
74
|
+
def svg_title(title)
|
75
|
+
element :g, fill: @config.title_color, 'text-anchor': 'middle',
|
76
|
+
'font-family': @config.title_font,
|
77
|
+
size: @config.title_font_size do |_svg|
|
78
|
+
element :text, @config.title(title),
|
79
|
+
x: @config.badge_middle / 2, y: @config.badge_height - 5,
|
80
|
+
fill: '#010101', 'fill-opacity': '0.3'
|
81
|
+
element :text, @config.title(title),
|
82
|
+
x: @config.badge_middle / 2, y: @config.badge_height - 6
|
111
83
|
end
|
112
84
|
end
|
113
85
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
end
|
127
|
-
|
128
|
-
def title(suffix)
|
129
|
-
prefix = @config.fetch(:title_prefix, '')
|
130
|
-
if prefix.to_s.empty?
|
131
|
-
suffix
|
132
|
-
else
|
133
|
-
"#{@config.fetch(:title_prefix, '')} #{suffix}"
|
86
|
+
# rubocop:disable Metrics/MethodLength
|
87
|
+
def svg_value(value)
|
88
|
+
element :g, fill: @config.value_color, 'text-anchor': 'middle',
|
89
|
+
'font-family': @config.value_font,
|
90
|
+
size: @config.value_font_size do |_svg|
|
91
|
+
element :text, value,
|
92
|
+
x: @config.badge_middle / 2 + @config.badge_middle,
|
93
|
+
y: @config.badge_height - 5,
|
94
|
+
fill: '#010101', 'fill-opacity': '0.3'
|
95
|
+
element :text, value,
|
96
|
+
x: @config.badge_middle / 2 + @config.badge_middle,
|
97
|
+
y: @config.badge_height - 6
|
134
98
|
end
|
135
99
|
end
|
136
|
-
|
137
|
-
|
138
|
-
@config.fetch(:output_path, '.')
|
139
|
-
end
|
100
|
+
# rubocop:enable Metrics/MethodLength
|
101
|
+
# rubocop:enable Metrics/AbcSize
|
140
102
|
end
|
141
|
-
# rubocop:enable Metrics/ClassLength
|
142
103
|
end
|
@@ -9,7 +9,7 @@ describe RepoSmallBadge::Image do
|
|
9
9
|
describe '#coverage' do
|
10
10
|
it do
|
11
11
|
allow(File).to receive(:write)
|
12
|
-
.with('./badge_total.svg',
|
12
|
+
.with('./badge_total.svg', rounded_svg_string).and_return(true)
|
13
13
|
expect(subject.badge('total', 'Total', '100%'))
|
14
14
|
.to be_truthy
|
15
15
|
end
|
@@ -27,6 +27,15 @@ describe RepoSmallBadge::Image do
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
+
context 'with different fonts colors size' do
|
31
|
+
subject do
|
32
|
+
described_class
|
33
|
+
.new(badge_width: 200,
|
34
|
+
title_color: '#ffffff', title_font: 'Verdura', title_size: 12,
|
35
|
+
value_color: '#ffffcc', value_font: 'Berdura', value_size: 10)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
30
39
|
context '#config_merge' do
|
31
40
|
it do
|
32
41
|
expect(subject.config_merge(badge_height: 10)[:badge_height]).to eq 10
|
data/spec/support/mocks.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module TestRepoSmallBadge
|
4
|
-
# rubocop:disable Metrics/MethodLength,
|
5
|
-
def
|
4
|
+
# rubocop:disable Metrics/MethodLength,Metrics/LineLength,Metrics/ParameterLists
|
5
|
+
def rounded_svg_string(title_color: '#fff', title_font: 'Verdana,sans-serif', title_font_size: 11,
|
6
|
+
value_color: '#fff', value_font: 'Verdana,sans-serif', value_font_size: 11)
|
6
7
|
%(<svg contentScriptType="text/ecmascript" contentStyleType="text/css" preserveAspectRatio="xMidYMid meet" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" version="1.0" height="20" width="100%">
|
7
8
|
|
8
9
|
<linearGradient id="smooth" x2="0" y2="100%">
|
@@ -17,13 +18,15 @@ module TestRepoSmallBadge
|
|
17
18
|
<rect x="60" height="20" width="60" fill="#4c1"/>
|
18
19
|
<rect height="20" width="120" fill="url(#smooth)"/>
|
19
20
|
</g>
|
20
|
-
<g fill="#
|
21
|
+
<g fill="#{title_color}" text-anchor="middle" font-family="#{title_font}" size="#{title_font_size}">
|
21
22
|
<text x="30" y="15" fill="#010101" fill-opacity="0.3">
|
22
23
|
Total
|
23
24
|
</text>
|
24
25
|
<text x="30" y="14">
|
25
26
|
Total
|
26
27
|
</text>
|
28
|
+
</g>
|
29
|
+
<g fill="#{value_color}" text-anchor="middle" font-family="#{value_font}" size="#{value_font_size}">
|
27
30
|
<text x="90" y="15" fill="#010101" fill-opacity="0.3">
|
28
31
|
100%
|
29
32
|
</text>
|
@@ -56,6 +59,8 @@ badge Total
|
|
56
59
|
<text x="50" y="14">
|
57
60
|
badge Total
|
58
61
|
</text>
|
62
|
+
</g>
|
63
|
+
<g fill="#fff" text-anchor="middle" font-family="Verdana,sans-serif" size="11">
|
59
64
|
<text x="150" y="15" fill="#010101" fill-opacity="0.3">
|
60
65
|
100%
|
61
66
|
</text>
|
@@ -65,5 +70,5 @@ badge Total
|
|
65
70
|
</g>
|
66
71
|
</svg>)
|
67
72
|
end
|
68
|
-
# rubocop:enable Metrics/MethodLength,
|
73
|
+
# rubocop:enable Metrics/MethodLength,Metrics/LineLength,Metrics/ParameterLists
|
69
74
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: repo-small-badge
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marc Grimme
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-02-
|
11
|
+
date: 2019-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: victor
|
@@ -114,8 +114,10 @@ files:
|
|
114
114
|
- MIT-LICENSE
|
115
115
|
- README.md
|
116
116
|
- Rakefile
|
117
|
+
- badges/coverage_badge_total.svg
|
117
118
|
- bin/console
|
118
119
|
- lib/repo_small_badge.rb
|
120
|
+
- lib/repo_small_badge/configuration.rb
|
119
121
|
- lib/repo_small_badge/image.rb
|
120
122
|
- lib/repo_small_badge/version.rb
|
121
123
|
- repo-small-badge.gemspec
|