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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9c1aa41c8b2a446d25aa1d251bf3848553db43ca
4
- data.tar.gz: c07aa71d59df2608e602c8f8a7c59f7d4fba6409
3
+ metadata.gz: b531f2410d7ef66c94c59b34d29c8850fa87e31b
4
+ data.tar.gz: 44769f7c088d363f25d3cf9683c8f534a57a8230
5
5
  SHA512:
6
- metadata.gz: 0ea689d47e152592a313dad0e5f9676fe869cbe807fbc306aa8b04e7b98c28e018199f24b7887f00c7d3cbdcedccb76fc5611b34014261654e4440721ec576a3
7
- data.tar.gz: 5ae5a1564f437fbc6ee1421b8a0a2d641e2e4ef7b74b7601b376e1666109d0e208d253d29106576c940295a0552023513b766ea862cf196b032d41a251ab243f
6
+ metadata.gz: d53413ff88bd9fe13ffcdedda58dac00442677f9c2d419787412b54fbe1e563698f3d140079f8e0cc55167daf3018e9519e8ae93653d5098226ee721c4cf4d66
7
+ data.tar.gz: 53ae1c5ea49354065317166b5f4291164e607b0084ea645f75d4561ec29ae8b7a9f45d132f4b46e7b83f8b757e0baa0ea2c1ff7faadbf53432e2392b033fc4df
@@ -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
- say_status :optimizing, relative_to_original_destination_root(sprite.path)
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'
@@ -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
- @blob = combined.to_blob { self.format = 'png' }
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'
@@ -1,3 +1,3 @@
1
1
  module Spriteful
2
- VERSION = '0.3.1'
2
+ VERSION = '0.3.2'
3
3
  end
@@ -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.1
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-10 00:00:00.000000000 Z
11
+ date: 2014-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor