shield-system 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/src/constants.rb +3 -0
- data/src/fonts/bureaueaglebook.ttf +0 -0
- data/src/systems/label.rb +85 -0
- metadata +5 -2
data/src/constants.rb
ADDED
Binary file
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'RMagick'
|
2
|
+
|
3
|
+
class Label
|
4
|
+
|
5
|
+
def initialize(label_name, label_text, label_colour, label_text_colour, background_colour, output_path, custom_font, height, font_size, font_family, buffer)
|
6
|
+
@label_name = label_name
|
7
|
+
@label_text = " #{label_text}"
|
8
|
+
@label_colour = label_colour
|
9
|
+
@label_text_colour = label_text_colour
|
10
|
+
$background_colour = background_colour
|
11
|
+
@output_path = output_path
|
12
|
+
@font_size = font_size.to_i
|
13
|
+
@font_family = font_family
|
14
|
+
@custom_font = custom_font
|
15
|
+
@buffer = buffer.to_i
|
16
|
+
@label_width = get_text_width(@label_text)
|
17
|
+
@height = height.to_i
|
18
|
+
@canvas = Magick::Image.new(@label_width, @height){ self.background_color = $background_colour }
|
19
|
+
@canvas.alpha(Magick::ActivateAlphaChannel)
|
20
|
+
@draw = Magick::Draw.new
|
21
|
+
@corners = 3
|
22
|
+
end
|
23
|
+
|
24
|
+
def generate
|
25
|
+
label_rectangle
|
26
|
+
label_text
|
27
|
+
publish
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def label_rectangle
|
33
|
+
@draw.fill(@label_colour)
|
34
|
+
@draw.stroke(@label_colour)
|
35
|
+
@draw.stroke_width(1)
|
36
|
+
@draw.roundrectangle(0, 0, @label_width, @height-1, @corners, @corners)
|
37
|
+
@draw.stroke('transparent')
|
38
|
+
end
|
39
|
+
|
40
|
+
def label_text
|
41
|
+
@draw.fill(@label_text_colour)
|
42
|
+
set_font(@draw)
|
43
|
+
@draw.pointsize=@font_size
|
44
|
+
@draw.text_antialias(true)
|
45
|
+
@draw.font_style(Magick::NormalStyle)
|
46
|
+
@draw.font_weight(Magick::BoldWeight)
|
47
|
+
@draw.gravity(Magick::WestGravity)
|
48
|
+
@draw.text(0, 0, @label_text)
|
49
|
+
end
|
50
|
+
|
51
|
+
def publish
|
52
|
+
@draw.draw(@canvas)
|
53
|
+
@canvas.write(@output_path + '/' + @label_name + '.gif')
|
54
|
+
end
|
55
|
+
|
56
|
+
def get_text_width(text)
|
57
|
+
canvas = Magick::Image.new(100, 100){ self.background_color = 'transparent' }
|
58
|
+
canvas.alpha(Magick::ActivateAlphaChannel)
|
59
|
+
label = Magick::Draw.new
|
60
|
+
set_font(label)
|
61
|
+
label.pointsize=@font_size
|
62
|
+
label.text_antialias(true)
|
63
|
+
label.font_style(Magick::NormalStyle)
|
64
|
+
label.font_weight(Magick::BoldWeight)
|
65
|
+
label.gravity(Magick::WestGravity)
|
66
|
+
label.text(0, 0, text)
|
67
|
+
metrics = label.get_type_metrics(canvas, text)
|
68
|
+
metrics.width.to_i + @buffer
|
69
|
+
end
|
70
|
+
|
71
|
+
def set_font(parent)
|
72
|
+
if @custom_font.nil?
|
73
|
+
parent.font_family(@font_family)
|
74
|
+
else
|
75
|
+
parent.font = @custom_font
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shield-system
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-08-
|
12
|
+
date: 2013-08-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -67,10 +67,13 @@ extra_rdoc_files:
|
|
67
67
|
- README.md
|
68
68
|
files:
|
69
69
|
- src/shield_system.rb
|
70
|
+
- src/constants.rb
|
70
71
|
- src/systems/github_shield.rb
|
71
72
|
- src/systems/sparkline_shield.rb
|
72
73
|
- src/presets/helpers/build_status.rb
|
73
74
|
- src/presets/github_build_status.rb
|
75
|
+
- src/fonts/bureaueaglebook.ttf
|
76
|
+
- src/systems/label.rb
|
74
77
|
- README.md
|
75
78
|
homepage: https://github.com/masterthought/shield-system
|
76
79
|
licenses:
|