shield-system 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +19 -12
- data/src/presets/github_build_status.rb +3 -2
- data/src/shield_system.rb +10 -4
- data/src/systems/github_shield.rb +17 -8
- metadata +1 -1
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Shield-System lets you generate github style status images for use anywhere e.g. custom badges with tests results.
|
4
4
|
|
5
|
-
[![Build Status](https://travis-ci.org/masterthought/
|
5
|
+
[![Build Status](https://travis-ci.org/masterthought/shield-system.png?branch=master)](https://travis-ci.org/masterthought/shield-system)
|
6
6
|
|
7
7
|
## Background
|
8
8
|
|
@@ -14,6 +14,12 @@ tests and statuses.
|
|
14
14
|
|
15
15
|
gem install shield-system
|
16
16
|
|
17
|
+
Requires RMagick so imagemagick needs to be installed. on a mac with brew:
|
18
|
+
|
19
|
+
brew install git (if you don't have git)
|
20
|
+
brew install ghostscript
|
21
|
+
brew install imagemagick
|
22
|
+
|
17
23
|
## Usage
|
18
24
|
|
19
25
|
### Create build status preset shields
|
@@ -37,7 +43,7 @@ tests and statuses.
|
|
37
43
|
(https://raw.github.com/masterthought/shield-system/master/examples/images/unknown.gif)
|
38
44
|
|
39
45
|
require 'shield_system'
|
40
|
-
require '
|
46
|
+
require 'presets/github_build_status.rb'
|
41
47
|
|
42
48
|
output_path = File.dirname(__FILE__)
|
43
49
|
build_status = GithubBuildStatus.new(output_path)
|
@@ -72,8 +78,8 @@ tests and statuses.
|
|
72
78
|
![Font]
|
73
79
|
(https://raw.github.com/masterthought/shield-system/master/examples/images/font.gif)
|
74
80
|
|
75
|
-
shield.github_shield('height','Dependencies','up-to-date',BuildStatus.key.colour,BuildStatus.passing.colour,BuildStatus.value.colour,'white',
|
76
|
-
shield.github_shield('font','GPA','4.0','#25B9E6',BuildStatus.passing.colour,'#0C0861','white',
|
81
|
+
shield.github_shield('height','Dependencies','up-to-date',BuildStatus.key.colour,BuildStatus.passing.colour,BuildStatus.value.colour,'white',TRANSPARENT_BACKGROUND,FONT_EAGLE,30,15,'arial')
|
82
|
+
shield.github_shield('font','GPA','4.0','#25B9E6',BuildStatus.passing.colour,'#0C0861','white',TRANSPARENT_BACKGROUND,FONT_EAGLE,20,13,'times')
|
77
83
|
|
78
84
|
### Creating Sparklines
|
79
85
|
|
@@ -90,23 +96,24 @@ tests and statuses.
|
|
90
96
|
### sparklines bar and pie
|
91
97
|
|
92
98
|
# labels
|
93
|
-
shield.
|
94
|
-
shield.
|
99
|
+
shield.label('build-history-label-bar', 'Build History', '#A8A7A5', 'white', TRANSPARENT_BACKGROUND, FONT_EAGLE, 28, 13)
|
100
|
+
shield.label('build-history-label-pie', 'Passing Tests', '#A8A7A5', 'white', TRANSPARENT_BACKGROUND, FONT_EAGLE, 28, 13)
|
95
101
|
# sparklines
|
96
|
-
shield.sparkline_shield('build-history-bar'
|
97
|
-
shield.sparkline_shield('build-history-pie'
|
102
|
+
shield.sparkline_shield('build-history-bar', :bar, [100, 100, 90, 80, 90, 90, 100, 120, 120, 90, 80, 70, 100, 120])
|
103
|
+
shield.sparkline_shield('build-history-pie', :pie, [70])
|
98
104
|
|
99
105
|
## Additional Info
|
100
106
|
|
101
107
|
github_shield takes several configuration parameters:
|
102
108
|
|
103
|
-
github_shield(shield_name, key_text, status_text, key_colour, status_colour, key_text_colour, status_text_colour, background_colour=
|
109
|
+
github_shield(shield_name, key_text, status_text, key_colour, status_colour, key_text_colour, status_text_colour, background_colour=TRANSPARENT_BACKGROUND, custom_font=FONT_EAGLE, height=18, font_size=11, font_family='arial', buffer=5)
|
104
110
|
|
105
111
|
most are self explanatory but here's some clarification on the last ones:
|
106
112
|
|
107
|
-
* background_colour = by default is
|
108
|
-
* buffer = by default is 5 - this is width added to the text width for the key and value you supply.
|
109
|
-
|
113
|
+
* background_colour = by default is TRANSPARENT_BACKGROUND but you can use this to set a specific colour
|
114
|
+
* buffer = by default is 5 - this is width added to the text width for the key and value you supply. you can increase the buffer to make more background space to the right of the text.
|
115
|
+
* custom_font = this is set to FONT_EAGLE by default. When custom_font is set it ignores font_family. You can turn off custom_font by setting it to NO_CUSTOM_FONT then the font_family will work.
|
116
|
+
(custom font is better cross platform otherwise the tests were failing as different OS's render the system fonts differently)
|
110
117
|
|
111
118
|
## Develop
|
112
119
|
|
@@ -3,9 +3,10 @@ require File.dirname(__FILE__) + '/../presets/helpers/build_status'
|
|
3
3
|
|
4
4
|
class GithubBuildStatus
|
5
5
|
|
6
|
-
def initialize(output_path,background_colour=
|
6
|
+
def initialize(output_path,background_colour=TRANSPARENT_BACKGROUND,custom_font=NO_CUSTOM_FONT)
|
7
7
|
@shield = ShieldSystem.new(output_path)
|
8
8
|
@background_colour = background_colour
|
9
|
+
@custom_font = custom_font
|
9
10
|
end
|
10
11
|
|
11
12
|
def passing
|
@@ -34,7 +35,7 @@ class GithubBuildStatus
|
|
34
35
|
|
35
36
|
def shield(status, override_filename=false)
|
36
37
|
@shield.github_shield(override_filename ? status.name.downcase : BuildStatus.filename, BuildStatus.key.name, status.name,
|
37
|
-
BuildStatus.key.colour, status.colour, BuildStatus.value.colour, BuildStatus.value.colour, @background_colour)
|
38
|
+
BuildStatus.key.colour, status.colour, BuildStatus.value.colour, BuildStatus.value.colour, @background_colour, @custom_font)
|
38
39
|
end
|
39
40
|
|
40
41
|
end
|
data/src/shield_system.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/systems/github_shield'
|
2
|
+
require File.dirname(__FILE__) + '/systems/label'
|
2
3
|
require File.dirname(__FILE__) + '/systems/sparkline_shield'
|
4
|
+
require File.dirname(__FILE__) + '/constants'
|
3
5
|
|
4
6
|
class ShieldSystem
|
5
7
|
|
@@ -7,12 +9,16 @@ class ShieldSystem
|
|
7
9
|
@output_path = output_path
|
8
10
|
end
|
9
11
|
|
10
|
-
def github_shield(shield_name, key_text, status_text, key_colour, status_colour, key_text_colour, status_text_colour, background_colour=
|
11
|
-
GithubShield.new(shield_name, key_text, status_text, key_colour, status_colour, key_text_colour, status_text_colour, background_colour, @output_path, height, font_size, font_family, buffer).generate
|
12
|
+
def github_shield(shield_name, key_text, status_text, key_colour, status_colour, key_text_colour, status_text_colour, background_colour=TRANSPARENT_BACKGROUND, custom_font=FONT_EAGLE, height=18, font_size=11, font_family='arial', buffer=5)
|
13
|
+
GithubShield.new(shield_name, key_text, status_text, key_colour, status_colour, key_text_colour, status_text_colour, background_colour, @output_path, custom_font, height, font_size, font_family, buffer).generate
|
12
14
|
end
|
13
15
|
|
14
|
-
def
|
15
|
-
|
16
|
+
def label(label_name, label_text, label_colour, label_text_colour, background_colour=TRANSPARENT_BACKGROUND, custom_font=FONT_EAGLE, height=18, font_size=11, font_family='arial', buffer=5)
|
17
|
+
Label.new(label_name, label_text, label_colour, label_text_colour, background_colour, @output_path, custom_font, height, font_size, font_family, buffer).generate
|
18
|
+
end
|
19
|
+
|
20
|
+
def sparkline_shield(shield_name, chart_type, data, options={})
|
21
|
+
SparklineShield.new(shield_name, chart_type, data, options, @output_path).generate
|
16
22
|
end
|
17
23
|
|
18
24
|
|
@@ -2,7 +2,7 @@ require 'RMagick'
|
|
2
2
|
|
3
3
|
class GithubShield
|
4
4
|
|
5
|
-
def initialize(shield_name, key_text, status_text, key_colour, status_colour, key_text_colour, status_text_colour, background_colour, output_path, height, font_size, font_family, buffer)
|
5
|
+
def initialize(shield_name, key_text, status_text, key_colour, status_colour, key_text_colour, status_text_colour, background_colour, output_path, custom_font, height, font_size, font_family, buffer)
|
6
6
|
@shield_name = shield_name
|
7
7
|
@key_text = " #{key_text}"
|
8
8
|
@status_text = " #{status_text}"
|
@@ -14,6 +14,7 @@ class GithubShield
|
|
14
14
|
@output_path = output_path
|
15
15
|
@font_size = font_size.to_i
|
16
16
|
@font_family = font_family
|
17
|
+
@custom_font = custom_font
|
17
18
|
@buffer = buffer.to_i
|
18
19
|
@key_width = get_text_width(@key_text)
|
19
20
|
@status_width = get_text_width(@status_text)
|
@@ -53,15 +54,15 @@ class GithubShield
|
|
53
54
|
def bridge_rectangle
|
54
55
|
@draw.fill(@key_colour)
|
55
56
|
@draw.stroke(@key_colour)
|
56
|
-
@draw.stroke_width(
|
57
|
+
@draw.stroke_width(2)
|
57
58
|
@draw.rectangle(@key_width, 0, @key_width+1, @height-1)
|
58
59
|
@draw.stroke('transparent')
|
59
60
|
end
|
60
61
|
|
61
62
|
def key_text
|
62
63
|
@draw.fill(@key_text_colour)
|
63
|
-
@draw
|
64
|
-
@draw.font_size
|
64
|
+
set_font(@draw)
|
65
|
+
@draw.pointsize=@font_size
|
65
66
|
@draw.text_antialias(true)
|
66
67
|
@draw.font_style(Magick::NormalStyle)
|
67
68
|
@draw.font_weight(Magick::BoldWeight)
|
@@ -71,8 +72,8 @@ class GithubShield
|
|
71
72
|
|
72
73
|
def status_text
|
73
74
|
@draw.fill(@status_text_colour)
|
74
|
-
@draw
|
75
|
-
@draw.font_size
|
75
|
+
set_font(@draw)
|
76
|
+
@draw.pointsize=@font_size
|
76
77
|
@draw.text_antialias(true)
|
77
78
|
@draw.font_style(Magick::NormalStyle)
|
78
79
|
@draw.font_weight(Magick::BoldWeight)
|
@@ -89,8 +90,8 @@ class GithubShield
|
|
89
90
|
canvas = Magick::Image.new(100, 100){ self.background_color = 'transparent' }
|
90
91
|
canvas.alpha(Magick::ActivateAlphaChannel)
|
91
92
|
label = Magick::Draw.new
|
92
|
-
label
|
93
|
-
label.font_size
|
93
|
+
set_font(label)
|
94
|
+
label.pointsize=@font_size
|
94
95
|
label.text_antialias(true)
|
95
96
|
label.font_style(Magick::NormalStyle)
|
96
97
|
label.font_weight(Magick::BoldWeight)
|
@@ -100,6 +101,14 @@ class GithubShield
|
|
100
101
|
metrics.width.to_i + @buffer
|
101
102
|
end
|
102
103
|
|
104
|
+
def set_font(parent)
|
105
|
+
if @custom_font.nil?
|
106
|
+
parent.font_family(@font_family)
|
107
|
+
else
|
108
|
+
parent.font = @custom_font
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
103
112
|
end
|
104
113
|
|
105
114
|
|