sprite-factory 1.7 → 1.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/RELEASE_NOTES.md +5 -0
  4. data/lib/sprite_factory.rb +2 -2
  5. data/lib/sprite_factory/runner.rb +14 -1
  6. data/test/images/custom/custom.css +0 -0
  7. data/test/images/custom/running.png +0 -0
  8. data/test/images/custom/stopped.png +0 -0
  9. data/test/images/formats/thief.png +0 -0
  10. data/test/images/glob/excluded1.png +0 -0
  11. data/test/images/glob/excluded2.png +0 -0
  12. data/test/images/glob/included1.png +0 -0
  13. data/test/images/glob/included2.png +0 -0
  14. data/test/images/glob/included3.png +0 -0
  15. data/test/images/hover/div.bar__img.icon--active.png +0 -0
  16. data/test/images/hover/div.bar__img.icon--focus.png +0 -0
  17. data/test/images/hover/div.bar__img.icon--hover.png +0 -0
  18. data/test/images/hover/div.bar__img.icon--link.png +0 -0
  19. data/test/images/hover/div.bar__img.icon--visited.png +0 -0
  20. data/test/images/hover/div.bar__img.icon.png +0 -0
  21. data/test/images/hover/div.foo__img.icon--active.png +0 -0
  22. data/test/images/hover/div.foo__img.icon--focus.png +0 -0
  23. data/test/images/hover/div.foo__img.icon--hover.png +0 -0
  24. data/test/images/hover/div.foo__img.icon--link.png +0 -0
  25. data/test/images/hover/div.foo__img.icon--visited.png +0 -0
  26. data/test/images/hover/div.foo__img.icon.png +0 -0
  27. data/test/images/irregular/irregular1.png +0 -0
  28. data/test/images/irregular/irregular2.png +0 -0
  29. data/test/images/irregular/irregular3.png +0 -0
  30. data/test/images/irregular/irregular4.png +0 -0
  31. data/test/images/irregular/irregular5.png +0 -0
  32. data/test/images/names/Odd.Period.png +0 -0
  33. data/test/images/reference/irregular.filtered.css +20 -0
  34. data/test/images/reference/irregular.filtered.png +0 -0
  35. data/test/images/reference/regular.filtered.css +20 -0
  36. data/test/images/reference/regular.filtered.png +0 -0
  37. data/test/images/subfolders/england/amy.png +0 -0
  38. data/test/images/subfolders/england/bob.png +0 -0
  39. data/test/images/subfolders/france/bob.png +0 -0
  40. data/test/images/subfolders/usa/amy.png +0 -0
  41. data/test/images/subfolders/usa/bob.png +0 -0
  42. data/test/integration_test.rb +12 -0
  43. data/test/runner_test.rb +27 -3
  44. data/test/test_case.rb +1 -1
  45. metadata +6 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b8eaae33fa1ece6b170c111201b49c9c43aedf9a
4
- data.tar.gz: 61a3998645237d26ded4d57c98970182ed1b9a85
3
+ metadata.gz: cb0f2314f328570697404a534cda489ed35c3c43
4
+ data.tar.gz: ad014967a8ecb4679f66e9f46ac4de2bf8c8d9ff
5
5
  SHA512:
6
- metadata.gz: 75b2b7092d6c87cde70180776c04a6e0fa6ec10f6c12244b8163f1749634875ed871274101f70449b830d3ee4451c58fe9de18cead42059aea204d673d941eb1
7
- data.tar.gz: e2145ffe3b32229049d3ab9929e4c3f3da8e65b2417f731cb58913760a4075179881f9941c60b63fc5660a7dac7db14e949ef79418f3d919e01865f96e839867
6
+ metadata.gz: ce72a68481f25969e2eb9b4295176af0f4981ba67df6cc3d76a61aeb04bb9623d718a1dff078baf25173ec026c4c5514da000d759d0a95dbf19a0a4bc2e461e2
7
+ data.tar.gz: fb87c0cd93acd937fa422a76992dc3f4261f41609acd19efd72384946d2e14093cad27d8e5f1bb9ba0497be4b48661317dc41567ec1c3a3d8d50dc80debc6b35
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- Sprite Factory (v1.7)
1
+ Sprite Factory (v1.7.1)
2
2
  =======================
3
3
 
4
4
  The sprite factory is a ruby library that can be used to generate
@@ -1,3 +1,8 @@
1
+ September 9th 2015 - v1.7.1
2
+ ---------------------------
3
+
4
+ * added `exclude` option to ignore select images in source directory (courtesy of @AlexanderRD)
5
+
1
6
  August 15th 2015 - v1.7
2
7
  -----------------------
3
8
 
@@ -2,7 +2,7 @@ module SpriteFactory
2
2
 
3
3
  #----------------------------------------------------------------------------
4
4
 
5
- VERSION = "1.7"
5
+ VERSION = "1.7.1"
6
6
  SUMMARY = "Automatic CSS sprite generator"
7
7
  DESCRIPTION = "Combines individual images from a directory into a single sprite image file and creates an appropriate CSS stylesheet"
8
8
  LIB = File.dirname(__FILE__)
@@ -30,6 +30,7 @@ module SpriteFactory
30
30
  attr_accessor :separator
31
31
  attr_accessor :glob
32
32
  attr_accessor :sanitizer
33
+ attr_accessor :exclude
33
34
  end
34
35
 
35
36
  #----------------------------------------------------------------------------
@@ -85,4 +86,3 @@ module SpriteFactory
85
86
  #----------------------------------------------------------------------------
86
87
 
87
88
  end
88
-
@@ -27,6 +27,7 @@ module SpriteFactory
27
27
  @config[:separator] ||= SpriteFactory.separator || '_'
28
28
  @config[:glob] ||= SpriteFactory.glob || '*'
29
29
  @config[:sanitizer] ||= SpriteFactory.sanitizer
30
+ @config[:exclude] ||= SpriteFactory.exclude || []
30
31
  end
31
32
 
32
33
  #----------------------------------------------------------------------------
@@ -149,6 +150,14 @@ module SpriteFactory
149
150
  config[:sanitizer]
150
151
  end
151
152
 
153
+ def exclude
154
+ config[:exclude]
155
+ end
156
+
157
+ def exclude?(file)
158
+ Array(exclude).any? { |name| file.include?(name) }
159
+ end
160
+
152
161
  def custom_style_file
153
162
  File.join(input, File.basename(input) + ".#{style_name}")
154
163
  end
@@ -169,11 +178,15 @@ module SpriteFactory
169
178
  end
170
179
  end
171
180
 
181
+ #----------------------------------------------------------------------------
182
+
172
183
  def image_files
173
184
  return [] if input.nil?
174
185
  valid_extensions = library::VALID_EXTENSIONS
175
186
  expansions = Array(valid_extensions).map{|ext| File.join(input, "**", "#{config[:glob]}.#{ext}")}
176
- SpriteFactory.find_files(*expansions)
187
+ files = SpriteFactory.find_files(*expansions)
188
+ files = files.reject{ |file| exclude?(file) }
189
+ files
177
190
  end
178
191
 
179
192
  #----------------------------------------------------------------------------
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,20 @@
1
+ /*
2
+
3
+ Creating a sprite from following images:
4
+
5
+ test/images/irregular/irregular2.png (16x16)
6
+ test/images/irregular/irregular3.png (48x48)
7
+ test/images/irregular/irregular4.png (34x14)
8
+
9
+ Output files:
10
+ test/images/irregular.filtered.png
11
+ test/images/irregular.filtered.css
12
+
13
+ Output size:
14
+ 98x48
15
+
16
+
17
+ */
18
+ img.filtered_irregular2 { width: 16px; height: 16px; background: url(irregular.filtered.png) 0px -16px no-repeat; }
19
+ img.filtered_irregular3 { width: 48px; height: 48px; background: url(irregular.filtered.png) -16px 0px no-repeat; }
20
+ img.filtered_irregular4 { width: 34px; height: 14px; background: url(irregular.filtered.png) -64px -17px no-repeat; }
@@ -0,0 +1,20 @@
1
+ /*
2
+
3
+ Creating a sprite from following images:
4
+
5
+ test/images/regular/regular2.PNG (64x64)
6
+ test/images/regular/regular3.PNG (64x64)
7
+ test/images/regular/regular4.PNG (64x64)
8
+
9
+ Output files:
10
+ test/images/regular.filtered.png
11
+ test/images/regular.filtered.css
12
+
13
+ Output size:
14
+ 192x64
15
+
16
+
17
+ */
18
+ img.filtered_regular2 { width: 64px; height: 64px; background: url(regular.filtered.png) 0px 0px no-repeat; }
19
+ img.filtered_regular3 { width: 64px; height: 64px; background: url(regular.filtered.png) -64px 0px no-repeat; }
20
+ img.filtered_regular4 { width: 64px; height: 64px; background: url(regular.filtered.png) -128px 0px no-repeat; }
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -60,6 +60,12 @@ module SpriteFactory
60
60
  :nocomments => true)
61
61
  end
62
62
 
63
+ def test_generate_regular_sprite_with_exclude_array
64
+ integration_test(REGULAR_PATH, :output => output_path('regular.filtered'),
65
+ :selector => 'img.filtered_',
66
+ :exclude => ['regular1.PNG', 'regular5.PNG'])
67
+ end
68
+
63
69
  #----------------------------------------------------------------------------
64
70
 
65
71
  def test_generate_irregular_sprite
@@ -111,6 +117,12 @@ module SpriteFactory
111
117
  :style => :sass)
112
118
  end
113
119
 
120
+ def test_generate_irregular_sprite_with_exclude_array
121
+ integration_test(IRREGULAR_PATH, :output => output_path('irregular.filtered'),
122
+ :selector => 'img.filtered_',
123
+ :exclude => ['irregular1.png', 'irregular5.png'])
124
+ end
125
+
114
126
  #----------------------------------------------------------------------------
115
127
 
116
128
  def test_generate_custom_sprite
@@ -19,6 +19,7 @@ module SpriteFactory
19
19
  assert_equal(:css, r.style_name)
20
20
  assert_equal(:rmagick, r.library_name)
21
21
  assert_equal(SEPARATOR, r.separator)
22
+ assert_equal([], r.exclude)
22
23
 
23
24
  r = Runner.new(IRREGULAR_PATH)
24
25
  assert_equal(IRREGULAR_PATH, r.input)
@@ -30,6 +31,7 @@ module SpriteFactory
30
31
  assert_equal(:css, r.style_name)
31
32
  assert_equal(:rmagick, r.library_name)
32
33
  assert_equal(SEPARATOR, r.separator)
34
+ assert_equal([], r.exclude)
33
35
 
34
36
  r = Runner.new(IRREGULAR_PATH, :separator => '.')
35
37
  assert_equal(IRREGULAR_PATH, r.input)
@@ -52,6 +54,19 @@ module SpriteFactory
52
54
  assert_equal(:css, r.style_name)
53
55
  assert_equal(:rmagick, r.library_name)
54
56
  assert_equal(SEPARATOR, r.separator)
57
+ assert_equal([], r.exclude)
58
+
59
+ r = Runner.new(REGULAR_PATH, :exclude => ['foo.png'])
60
+ assert_equal(REGULAR_PATH, r.input)
61
+ assert_equal(REGULAR_PATH, r.output)
62
+ assert_equal(REGULAR_PATH + ".png", r.output_image_file)
63
+ assert_equal(REGULAR_PATH + ".css", r.output_style_file)
64
+ assert_equal(REGULAR, r.image_files)
65
+ assert_equal(:horizontal, r.layout_name)
66
+ assert_equal(:css, r.style_name)
67
+ assert_equal(:rmagick, r.library_name)
68
+ assert_equal(SEPARATOR, r.separator)
69
+ assert_equal(['foo.png'], r.exclude)
55
70
 
56
71
  r = Runner.new(REGULAR_PATH, :output_image => "foo.png", :output_style => "bar.css.sass.erb")
57
72
  assert_equal(REGULAR_PATH, r.input)
@@ -63,6 +78,7 @@ module SpriteFactory
63
78
  assert_equal(:css, r.style_name)
64
79
  assert_equal(:rmagick, r.library_name)
65
80
  assert_equal(SEPARATOR, r.separator)
81
+ assert_equal([], r.exclude)
66
82
 
67
83
  r = Runner.new(REGULAR_PATH, :layout => :vertical, :library => :chunkypng, :style => :sass)
68
84
  assert_equal(REGULAR_PATH, r.input)
@@ -74,9 +90,8 @@ module SpriteFactory
74
90
  assert_equal(:sass, r.style_name)
75
91
  assert_equal(:chunkypng, r.library_name)
76
92
  assert_equal(SEPARATOR, r.separator)
77
-
78
- end
79
-
93
+ assert_equal([], r.exclude)
94
+ end
80
95
  end
81
96
 
82
97
  #----------------------------------------------------------------------------
@@ -202,6 +217,15 @@ module SpriteFactory
202
217
 
203
218
  #----------------------------------------------------------------------------
204
219
 
220
+ def test_images_are_filtered_correctly
221
+ Runner.publicize_methods do
222
+ expected = REGULAR_INFO.map{ |i| i[:filename] }
223
+ excluded = expected.pop(2)
224
+ actual = Runner.new(REGULAR_PATH, :exclude => excluded).image_files
225
+ assert_equal(expected, actual)
226
+ end
227
+ end
228
+
205
229
  def test_images_are_sorted_in_classname_order
206
230
  Runner.publicize_methods do
207
231
  expected = [
@@ -107,7 +107,7 @@ module SpriteFactory
107
107
  actual_image = Magick::Image.read(actual)[0]
108
108
  expected_image = Magick::Image.read(expected)[0]
109
109
  img, val = expected_image.compare_channel(actual_image, Magick::MeanAbsoluteErrorMetric)
110
- assert_equal(0.0, val, "generated image does not match pregenerated reference:\n actual: #{actual}\n expected: #{expected}")
110
+ assert_in_delta(0.0, val, 1e-7, "generated image does not match pregenerated reference:\n actual: #{actual}\n expected: #{expected}\n expected: #{expected}")
111
111
  end
112
112
 
113
113
  def assert_reference_style(name)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sprite-factory
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.7'
4
+ version: 1.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jake Gordon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-15 00:00:00.000000000 Z
11
+ date: 2015-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rmagick
@@ -112,6 +112,8 @@ files:
112
112
  - test/images/reference/hover.png
113
113
  - test/images/reference/index.html
114
114
  - test/images/reference/irregular.css
115
+ - test/images/reference/irregular.filtered.css
116
+ - test/images/reference/irregular.filtered.png
115
117
  - test/images/reference/irregular.fixed.css
116
118
  - test/images/reference/irregular.fixed.png
117
119
  - test/images/reference/irregular.horizontal.css
@@ -131,6 +133,8 @@ files:
131
133
  - test/images/reference/regular.css
132
134
  - test/images/reference/regular.custom.css
133
135
  - test/images/reference/regular.custom.png
136
+ - test/images/reference/regular.filtered.css
137
+ - test/images/reference/regular.filtered.png
134
138
  - test/images/reference/regular.fixed.css
135
139
  - test/images/reference/regular.fixed.png
136
140
  - test/images/reference/regular.horizontal.css