spriteful 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/spriteful/cli.rb +4 -4
- data/lib/spriteful/sprite.rb +27 -4
- data/lib/spriteful/version.rb +1 -1
- data/spec/sprite_spec.rb +9 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b531f2410d7ef66c94c59b34d29c8850fa87e31b
|
4
|
+
data.tar.gz: 44769f7c088d363f25d3cf9683c8f534a57a8230
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d53413ff88bd9fe13ffcdedda58dac00442677f9c2d419787412b54fbe1e563698f3d140079f8e0cc55167daf3018e9519e8ae93653d5098226ee721c4cf4d66
|
7
|
+
data.tar.gz: 53ae1c5ea49354065317166b5f4291164e607b0084ea645f75d4561ec29ae8b7a9f45d132f4b46e7b83f8b757e0baa0ea2c1ff7faadbf53432e2392b033fc4df
|
data/lib/spriteful/cli.rb
CHANGED
@@ -89,16 +89,16 @@ module Spriteful
|
|
89
89
|
stylesheet = Spriteful::Stylesheet.new(sprite, File.expand_path(options.stylesheets), stylesheet_options)
|
90
90
|
|
91
91
|
sprite.combine!
|
92
|
-
create_file sprite.path, sprite.blob
|
93
|
-
create_file stylesheet.path, stylesheet.render
|
94
92
|
if options.optimize?
|
95
93
|
if optimizer.enabled?
|
96
|
-
|
97
|
-
optimizer.optimize!(sprite.path)
|
94
|
+
optimizer.optimize!(sprite.tmp_path)
|
98
95
|
else
|
99
96
|
say_status :optimizing, "No optimizer found. Please install at least one of the following: #{optimizer.optimizers.join(', ')}.", :yellow
|
100
97
|
end
|
101
98
|
end
|
99
|
+
create_file sprite.path, sprite.blob
|
100
|
+
create_file stylesheet.path, stylesheet.render
|
101
|
+
sprite.cleanup
|
102
102
|
end
|
103
103
|
|
104
104
|
# Internal: Saves the existing options on 'ARGV' to the '.spritefulrc'
|
data/lib/spriteful/sprite.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'RMagick'
|
2
|
+
require 'tempfile'
|
2
3
|
|
3
4
|
module Spriteful
|
4
5
|
# Public: the 'Sprite' class is responsible for combining a directory
|
@@ -17,9 +18,6 @@ module Spriteful
|
|
17
18
|
# Public: Gets the the spacing between the images in the sprite.
|
18
19
|
attr_reader :spacing
|
19
20
|
|
20
|
-
# Public: Gets the the binary contents of the combined image.
|
21
|
-
attr_reader :blob
|
22
|
-
|
23
21
|
# Public: Gets the the width of the combined image.
|
24
22
|
attr_reader :width
|
25
23
|
|
@@ -28,6 +26,7 @@ module Spriteful
|
|
28
26
|
|
29
27
|
# Public: Gets the flag to check if the sprite is vertical or not.
|
30
28
|
attr_reader :vertical
|
29
|
+
|
31
30
|
alias :vertical? :vertical
|
32
31
|
|
33
32
|
# Public: Initialize a Sprite.
|
@@ -59,6 +58,7 @@ module Spriteful
|
|
59
58
|
@images = initialize_images(@list)
|
60
59
|
|
61
60
|
@height, @width = detect_dimensions
|
61
|
+
@tmpfile = Tempfile.new(filename)
|
62
62
|
end
|
63
63
|
|
64
64
|
# Public: combines the source images into a single one,
|
@@ -71,7 +71,30 @@ module Spriteful
|
|
71
71
|
@images.each do |image|
|
72
72
|
combined.composite!(image.source, image.left.abs, image.top.abs, Magick::SrcOverCompositeOp)
|
73
73
|
end
|
74
|
-
@
|
74
|
+
@tmpfile.write(combined.to_blob { self.format = 'png' })
|
75
|
+
@tmpfile.close
|
76
|
+
end
|
77
|
+
|
78
|
+
# Public: Gets the temporary path where the sprite is stored.
|
79
|
+
#
|
80
|
+
# Returns a String.
|
81
|
+
def tmp_path
|
82
|
+
@tmpfile.path
|
83
|
+
end
|
84
|
+
|
85
|
+
# Public: Gets the binary contents generated by the sprite.
|
86
|
+
#
|
87
|
+
# Returns a String.
|
88
|
+
def blob
|
89
|
+
File.binread(tmp_path)
|
90
|
+
end
|
91
|
+
|
92
|
+
# Public: Execute any post generation code to free any resources used by the
|
93
|
+
# sprite.
|
94
|
+
#
|
95
|
+
# Returns nothing.
|
96
|
+
def cleanup
|
97
|
+
@tmpfile.unlink
|
75
98
|
end
|
76
99
|
|
77
100
|
# Public: exposes the source images found in the 'source'
|
data/lib/spriteful/version.rb
CHANGED
data/spec/sprite_spec.rb
CHANGED
@@ -114,4 +114,13 @@ describe Spriteful::Sprite do
|
|
114
114
|
expect(red.left).to eq(0)
|
115
115
|
end
|
116
116
|
end
|
117
|
+
|
118
|
+
describe '#cleanup' do
|
119
|
+
it 'removes the sprite temporary file' do
|
120
|
+
sprite = Spriteful::Sprite.new(source, destination)
|
121
|
+
sprite.cleanup
|
122
|
+
|
123
|
+
expect(sprite.tmp_path).to be_nil
|
124
|
+
end
|
125
|
+
end
|
117
126
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spriteful
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lucas Mazza
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|