sprite-factory 1.0.0

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.
Files changed (71) hide show
  1. data/LICENSE +20 -0
  2. data/README.md +207 -0
  3. data/Rakefile +67 -0
  4. data/bin/sf +46 -0
  5. data/lib/sprite_factory.rb +51 -0
  6. data/lib/sprite_factory/layout.rb +89 -0
  7. data/lib/sprite_factory/library/chunky_png.rb +31 -0
  8. data/lib/sprite_factory/library/rmagick.rb +32 -0
  9. data/lib/sprite_factory/runner.rb +204 -0
  10. data/lib/sprite_factory/style.rb +58 -0
  11. data/sprite_factory.gemspec +24 -0
  12. data/test/images/custom/custom.css +4 -0
  13. data/test/images/custom/running.png +0 -0
  14. data/test/images/custom/stopped.png +0 -0
  15. data/test/images/empty/readme.txt +1 -0
  16. data/test/images/formats/alice.gif +0 -0
  17. data/test/images/formats/monkey.gif +0 -0
  18. data/test/images/formats/spies.jpg +0 -0
  19. data/test/images/formats/thief.png +0 -0
  20. data/test/images/irregular/irregular1.png +0 -0
  21. data/test/images/irregular/irregular2.png +0 -0
  22. data/test/images/irregular/irregular3.png +0 -0
  23. data/test/images/irregular/irregular4.png +0 -0
  24. data/test/images/irregular/irregular5.png +0 -0
  25. data/test/images/irregular/readme.txt +2 -0
  26. data/test/images/reference/custom.css +22 -0
  27. data/test/images/reference/custom.png +0 -0
  28. data/test/images/reference/formats.css +22 -0
  29. data/test/images/reference/formats.png +0 -0
  30. data/test/images/reference/index.html +135 -0
  31. data/test/images/reference/irregular.css +24 -0
  32. data/test/images/reference/irregular.fixed.css +24 -0
  33. data/test/images/reference/irregular.fixed.png +0 -0
  34. data/test/images/reference/irregular.horizontal.css +24 -0
  35. data/test/images/reference/irregular.horizontal.png +0 -0
  36. data/test/images/reference/irregular.padded.css +24 -0
  37. data/test/images/reference/irregular.padded.png +0 -0
  38. data/test/images/reference/irregular.png +0 -0
  39. data/test/images/reference/irregular.sassy.css +38 -0
  40. data/test/images/reference/irregular.sassy.png +0 -0
  41. data/test/images/reference/irregular.sassy.sass +40 -0
  42. data/test/images/reference/irregular.vertical.css +24 -0
  43. data/test/images/reference/irregular.vertical.png +0 -0
  44. data/test/images/reference/regular.css +24 -0
  45. data/test/images/reference/regular.custom.css +24 -0
  46. data/test/images/reference/regular.custom.png +0 -0
  47. data/test/images/reference/regular.fixed.css +24 -0
  48. data/test/images/reference/regular.fixed.png +0 -0
  49. data/test/images/reference/regular.horizontal.css +24 -0
  50. data/test/images/reference/regular.horizontal.png +0 -0
  51. data/test/images/reference/regular.padded.css +24 -0
  52. data/test/images/reference/regular.padded.png +0 -0
  53. data/test/images/reference/regular.png +0 -0
  54. data/test/images/reference/regular.sassy.css +38 -0
  55. data/test/images/reference/regular.sassy.png +0 -0
  56. data/test/images/reference/regular.sassy.sass +40 -0
  57. data/test/images/reference/regular.vertical.css +24 -0
  58. data/test/images/reference/regular.vertical.png +0 -0
  59. data/test/images/reference/s.gif +0 -0
  60. data/test/images/regular/regular1.png +0 -0
  61. data/test/images/regular/regular2.png +0 -0
  62. data/test/images/regular/regular3.png +0 -0
  63. data/test/images/regular/regular4.png +0 -0
  64. data/test/images/regular/regular5.png +0 -0
  65. data/test/integration_test.rb +100 -0
  66. data/test/layout_test.rb +228 -0
  67. data/test/library_test.rb +57 -0
  68. data/test/runner_test.rb +156 -0
  69. data/test/style_test.rb +64 -0
  70. data/test/test_case.rb +127 -0
  71. metadata +159 -0
@@ -0,0 +1,100 @@
1
+ require File.expand_path('test_case', File.dirname(__FILE__))
2
+
3
+ module SpriteFactory
4
+ class IntegrationTest < SpriteFactory::TestCase
5
+
6
+ #----------------------------------------------------------------------------
7
+
8
+ def test_generate_regular_sprite
9
+ integration_test(REGULAR_PATH)
10
+ end
11
+
12
+ def test_generate_horizontal_regular_sprite
13
+ integration_test(REGULAR_PATH, :output => output_path('regular.horizontal'),
14
+ :selector => 'img.horizontal_',
15
+ :layout => :horizontal)
16
+ end
17
+
18
+ def test_generate_vertical_regular_sprite
19
+ integration_test(REGULAR_PATH, :output => output_path('regular.vertical'),
20
+ :selector => 'img.vertical_',
21
+ :layout => :vertical)
22
+ end
23
+
24
+ def test_generate_regular_sprite_with_padding
25
+ integration_test(REGULAR_PATH, :output => output_path('regular.padded'),
26
+ :selector => 'img.padded_',
27
+ :padding => 10)
28
+ end
29
+
30
+ def test_generate_regular_sprite_with_fixed_size
31
+ integration_test(REGULAR_PATH, :output => output_path('regular.fixed'),
32
+ :selector => 'img.fixed_',
33
+ :width => 100,
34
+ :height => 100)
35
+ end
36
+
37
+ def test_generate_regular_sprite_with_sassy_style
38
+ integration_test(REGULAR_PATH, :output => output_path('regular.sassy'),
39
+ :selector => 'img.sassy_',
40
+ :style => :sass)
41
+ end
42
+
43
+ #----------------------------------------------------------------------------
44
+
45
+ def test_generate_irregular_sprite
46
+ integration_test(IRREGULAR_PATH)
47
+ end
48
+
49
+ def test_generate_horizontal_irregular_sprite
50
+ integration_test(IRREGULAR_PATH, :output => output_path('irregular.horizontal'),
51
+ :selector => 'img.horizontal_',
52
+ :layout => :horizontal)
53
+ end
54
+
55
+ def test_generate_vertical_irregular_sprite
56
+ integration_test(IRREGULAR_PATH, :output => output_path('irregular.vertical'),
57
+ :selector => 'img.vertical_',
58
+ :layout => :vertical)
59
+ end
60
+
61
+ def test_generate_irregular_sprite_with_padding
62
+ integration_test(IRREGULAR_PATH, :output => output_path('irregular.padded'),
63
+ :selector => 'img.padded_',
64
+ :padding => 10)
65
+ end
66
+
67
+ def test_generate_irregular_sprite_with_fixed_size
68
+ integration_test(IRREGULAR_PATH, :output => output_path('irregular.fixed'),
69
+ :selector => 'img.fixed_',
70
+ :width => 100,
71
+ :height => 100)
72
+ end
73
+
74
+ def test_generate_irregular_sprite_with_sassy_style
75
+ integration_test(IRREGULAR_PATH, :output => output_path('irregular.sassy'),
76
+ :selector => 'img.sassy_',
77
+ :style => :sass)
78
+ end
79
+
80
+ #----------------------------------------------------------------------------
81
+
82
+ def test_generate_custom_sprite
83
+ integration_test(CUSTOM_PATH) do |images|
84
+ rules = []
85
+ rules << "div.running img.button { cursor: pointer; #{images[:running][:style]} }"
86
+ rules << "div.stopped img.button { cursor: pointer; #{images[:stopped][:style]} }"
87
+ rules.join("\n")
88
+ end
89
+ end
90
+
91
+ #----------------------------------------------------------------------------
92
+
93
+ def test_generate_sprite_from_other_formats
94
+ integration_test(FORMATS_PATH, :library => :rmagick)
95
+ end
96
+
97
+ #----------------------------------------------------------------------------
98
+
99
+ end
100
+ end
@@ -0,0 +1,228 @@
1
+ require File.expand_path('test_case', File.dirname(__FILE__))
2
+
3
+ module SpriteFactory
4
+ class LayoutTest < SpriteFactory::TestCase
5
+
6
+ #==========================================================================
7
+ # test REGULAR images
8
+ #==========================================================================
9
+
10
+ def test_horizontal_layout_of_regular_images
11
+ images = get_regular_images
12
+ expected = [
13
+ { :x => 0, :y => 0 },
14
+ { :x => 20, :y => 0 },
15
+ { :x => 40, :y => 0 },
16
+ { :x => 60, :y => 0 },
17
+ { :x => 80, :y => 0 }
18
+ ]
19
+ verify_layout(100, 10, expected, images, :layout => :horizontal)
20
+ end
21
+
22
+
23
+ #--------------------------------------------------------------------------
24
+
25
+ def test_vertical_layout_of_regular_images
26
+ images = get_regular_images
27
+ expected = [
28
+ { :x => 0, :y => 0 },
29
+ { :x => 0, :y => 10 },
30
+ { :x => 0, :y => 20 },
31
+ { :x => 0, :y => 30 },
32
+ { :x => 0, :y => 40 }
33
+ ]
34
+ verify_layout(20, 50, expected, images, :layout => :vertical)
35
+ end
36
+
37
+ #--------------------------------------------------------------------------
38
+
39
+ def test_padded_horizontal_layout_of_regular_images
40
+ images = get_regular_images
41
+ expected = [
42
+ { :cssx => 0, :cssy => 0, :cssw => 40, :cssh => 50, :x => 10, :y => 20 },
43
+ { :cssx => 40, :cssy => 0, :cssw => 40, :cssh => 50, :x => 50, :y => 20 },
44
+ { :cssx => 80, :cssy => 0, :cssw => 40, :cssh => 50, :x => 90, :y => 20 },
45
+ { :cssx => 120, :cssy => 0, :cssw => 40, :cssh => 50, :x => 130, :y => 20 },
46
+ { :cssx => 160, :cssy => 0, :cssw => 40, :cssh => 50, :x => 170, :y => 20 }
47
+ ]
48
+ verify_layout(200, 50, expected, images, :layout => :horizontal, :hpadding => 10, :vpadding => 20)
49
+ end
50
+
51
+ #--------------------------------------------------------------------------
52
+
53
+ def test_padded_vertical_layout_of_regular_images
54
+ images = get_regular_images
55
+ expected = [
56
+ { :cssx => 0, :cssy => 0, :cssw => 40, :cssh => 50, :x => 10, :y => 20 },
57
+ { :cssx => 0, :cssy => 50, :cssw => 40, :cssh => 50, :x => 10, :y => 70 },
58
+ { :cssx => 0, :cssy => 100, :cssw => 40, :cssh => 50, :x => 10, :y => 120 },
59
+ { :cssx => 0, :cssy => 150, :cssw => 40, :cssh => 50, :x => 10, :y => 170 },
60
+ { :cssx => 0, :cssy => 200, :cssw => 40, :cssh => 50, :x => 10, :y => 220 }
61
+ ]
62
+ verify_layout(40, 250, expected, images, :layout => :vertical, :hpadding => 10, :vpadding => 20)
63
+ end
64
+
65
+ #--------------------------------------------------------------------------
66
+
67
+ def test_fixed_horizontal_layout_of_regular_images
68
+ images = get_regular_images
69
+ expected = [
70
+ { :cssx => 0, :cssy => 0, :cssw => 50, :cssh => 50, :x => 15, :y => 20 },
71
+ { :cssx => 50, :cssy => 0, :cssw => 50, :cssh => 50, :x => 65, :y => 20 },
72
+ { :cssx => 100, :cssy => 0, :cssw => 50, :cssh => 50, :x => 115, :y => 20 },
73
+ { :cssx => 150, :cssy => 0, :cssw => 50, :cssh => 50, :x => 165, :y => 20 },
74
+ { :cssx => 200, :cssy => 0, :cssw => 50, :cssh => 50, :x => 215, :y => 20 }
75
+ ]
76
+ verify_layout(250, 50, expected, images, :layout => :horizontal, :width => 50, :height => 50)
77
+ end
78
+
79
+ #--------------------------------------------------------------------------
80
+
81
+ def test_fixed_vertical_layout_of_regular_images
82
+ images = get_regular_images
83
+ expected = [
84
+ { :cssx => 0, :cssy => 0, :cssw => 50, :cssh => 50, :x => 15, :y => 20 },
85
+ { :cssx => 0, :cssy => 50, :cssw => 50, :cssh => 50, :x => 15, :y => 70 },
86
+ { :cssx => 0, :cssy => 100, :cssw => 50, :cssh => 50, :x => 15, :y => 120 },
87
+ { :cssx => 0, :cssy => 150, :cssw => 50, :cssh => 50, :x => 15, :y => 170 },
88
+ { :cssx => 0, :cssy => 200, :cssw => 50, :cssh => 50, :x => 15, :y => 220 }
89
+ ]
90
+ verify_layout(50, 250, expected, images, :layout => :vertical, :width => 50, :height => 50)
91
+ end
92
+
93
+ #==========================================================================
94
+ # test IRREGULAR images
95
+ #==========================================================================
96
+
97
+ def test_horizontal_layout_of_irregular_images
98
+ images = get_irregular_images
99
+ expected = [
100
+ { :x => 0, :y => 0 },
101
+ { :x => 20, :y => 5 },
102
+ { :x => 60, :y => 10 },
103
+ { :x => 120, :y => 15 },
104
+ { :x => 200, :y => 20 }
105
+ ]
106
+ verify_layout(300, 50, expected, images, :layout => :horizontal)
107
+ end
108
+
109
+ #--------------------------------------------------------------------------
110
+
111
+ def test_vertical_layout_of_irregular_images
112
+ images = get_irregular_images
113
+ expected = [
114
+ { :x => 40, :y => 0 },
115
+ { :x => 30, :y => 50 },
116
+ { :x => 20, :y => 90 },
117
+ { :x => 10, :y => 120 },
118
+ { :x => 0, :y => 140 }
119
+ ]
120
+ verify_layout(100, 150, expected, images, :layout => :vertical)
121
+ end
122
+
123
+ #--------------------------------------------------------------------------
124
+
125
+ def test_padded_horizontal_layout_of_irregular_images
126
+ images = get_irregular_images
127
+ expected = [
128
+ { :cssx => 0, :cssy => 0, :cssw => 40, :cssh => 90, :x => 10, :y => 20 },
129
+ { :cssx => 40, :cssy => 5, :cssw => 60, :cssh => 80, :x => 50, :y => 25 },
130
+ { :cssx => 100, :cssy => 10, :cssw => 80, :cssh => 70, :x => 110, :y => 30 },
131
+ { :cssx => 180, :cssy => 15, :cssw => 100, :cssh => 60, :x => 190, :y => 35 },
132
+ { :cssx => 280, :cssy => 20, :cssw => 120, :cssh => 50, :x => 290, :y => 40 }
133
+ ]
134
+ verify_layout(400, 90, expected, images, :layout => :horizontal, :hpadding => 10, :vpadding => 20)
135
+ end
136
+
137
+ #--------------------------------------------------------------------------
138
+
139
+ def test_padded_vertical_layout_of_irregular_images
140
+ images = get_irregular_images
141
+ expected = [
142
+ { :cssx => 40, :cssy => 0, :cssw => 40, :cssh => 90, :x => 50, :y => 20 },
143
+ { :cssx => 30, :cssy => 90, :cssw => 60, :cssh => 80, :x => 40, :y => 110 },
144
+ { :cssx => 20, :cssy => 170, :cssw => 80, :cssh => 70, :x => 30, :y => 190 },
145
+ { :cssx => 10, :cssy => 240, :cssw => 100, :cssh => 60, :x => 20, :y => 260 },
146
+ { :cssx => 0, :cssy => 300, :cssw => 120, :cssh => 50, :x => 10, :y => 320 }
147
+ ]
148
+ verify_layout(120, 350, expected, images, :layout => :vertical, :hpadding => 10, :vpadding => 20)
149
+ end
150
+
151
+ #--------------------------------------------------------------------------
152
+
153
+ def test_fixed_horizontal_layout_of_irregular_images
154
+ images = get_irregular_images
155
+ expected = [
156
+ { :cssx => 0, :cssy => 0, :cssw => 100, :cssh => 100, :x => 40, :y => 25 },
157
+ { :cssx => 100, :cssy => 0, :cssw => 100, :cssh => 100, :x => 130, :y => 30 },
158
+ { :cssx => 200, :cssy => 0, :cssw => 100, :cssh => 100, :x => 220, :y => 35 },
159
+ { :cssx => 300, :cssy => 0, :cssw => 100, :cssh => 100, :x => 310, :y => 40 },
160
+ { :cssx => 400, :cssy => 0, :cssw => 100, :cssh => 100, :x => 400, :y => 45 }
161
+ ]
162
+ verify_layout(500, 100, expected, images, :layout => :horizontal, :width => 100, :height => 100)
163
+ end
164
+
165
+ #--------------------------------------------------------------------------
166
+
167
+ def test_fixed_vertical_layout_of_irregular_images
168
+ images = get_irregular_images
169
+ expected = [
170
+ { :cssx => 0, :cssy => 0, :cssw => 100, :cssh => 100, :x => 40, :y => 25 },
171
+ { :cssx => 0, :cssy => 100, :cssw => 100, :cssh => 100, :x => 30, :y => 130 },
172
+ { :cssx => 0, :cssy => 200, :cssw => 100, :cssh => 100, :x => 20, :y => 235 },
173
+ { :cssx => 0, :cssy => 300, :cssw => 100, :cssh => 100, :x => 10, :y => 340 },
174
+ { :cssx => 0, :cssy => 400, :cssw => 100, :cssh => 100, :x => 0, :y => 445 }
175
+ ]
176
+ verify_layout(100, 500, expected, images, :layout => :vertical, :width => 100, :height => 100)
177
+ end
178
+
179
+ #==========================================================================
180
+ # private test helpers
181
+ #==========================================================================
182
+
183
+ private
184
+
185
+ def get_regular_images
186
+ return [
187
+ {:width => 20, :height => 10},
188
+ {:width => 20, :height => 10},
189
+ {:width => 20, :height => 10},
190
+ {:width => 20, :height => 10},
191
+ {:width => 20, :height => 10}
192
+ ]
193
+ end
194
+
195
+ def get_irregular_images
196
+ return [
197
+ {:width => 20, :height => 50},
198
+ {:width => 40, :height => 40},
199
+ {:width => 60, :height => 30},
200
+ {:width => 80, :height => 20},
201
+ {:width => 100, :height => 10}
202
+ ]
203
+ end
204
+
205
+ #--------------------------------------------------------------------------
206
+
207
+ def verify_layout(expected_width, expected_height, expected_images, images, options = {})
208
+ max = Layout.send(options[:layout] || :horizontal, images, options)
209
+ assert_equal(expected_width, max[:width])
210
+ assert_equal(expected_height, max[:height])
211
+ assert_equal(expected_images.length, images.length)
212
+ images.length.times.each do |n|
213
+ expected = expected_images[n]
214
+ actual = images[n]
215
+ assert_equal(expected[:x], actual[:x], "image #{n} - unexpected x")
216
+ assert_equal(expected[:y], actual[:y], "image #{n} - unexpected y")
217
+ assert_equal(expected[:cssx] || expected[:x], actual[:cssx], "image #{n} - unexpected cssx")
218
+ assert_equal(expected[:cssy] || expected[:y], actual[:cssy], "image #{n} - unexpected cssy")
219
+ assert_equal(expected[:cssw] || actual[:width], actual[:cssw], "image #{n} - unexpected cssw")
220
+ assert_equal(expected[:cssh] || actual[:height], actual[:cssh], "image #{n} - unexpected cssh")
221
+ end
222
+ end
223
+
224
+ #--------------------------------------------------------------------------
225
+
226
+ end # class LayoutTest
227
+ end # module SpriteFactory
228
+
@@ -0,0 +1,57 @@
1
+ require File.expand_path('test_case', File.dirname(__FILE__))
2
+
3
+ class SpriteFactory::LibraryTest < SpriteFactory::TestCase
4
+
5
+ #--------------------------------------------------------------------------
6
+
7
+ LIBRARIES = {
8
+ :rmagick => SpriteFactory::Library::RMagick,
9
+ :chunkypng => SpriteFactory::Library::ChunkyPng
10
+ }
11
+
12
+ #--------------------------------------------------------------------------
13
+
14
+ LIBRARIES.each do |name, library| # use metaprogramming to define independent tests for each library
15
+
16
+ define_method "test_load_regular_using_#{name}" do
17
+ assert_images(REGULAR_INFO, library.load(REGULAR))
18
+ end
19
+
20
+ define_method "test_load_irregular_using_#{name}" do
21
+ assert_images(IRREGULAR_INFO, library.load(IRREGULAR))
22
+ end
23
+
24
+ define_method "test_create_using_#{name}" do
25
+ with_clean_output do
26
+ images = library.load(REGULAR)
27
+ x = 0
28
+ images.each do |image|
29
+ image[:x] = x
30
+ image[:y] = 0
31
+ x = x + image[:width]
32
+ end
33
+ width = images.map{|i| i[:width]}.inject(0){|n,w| n = n + w }
34
+ height = images.map{|i| i[:height]}.max
35
+ library.create(output_path('regular.horizontal.png'), images, width, height)
36
+ assert_reference_image('regular.horizontal.png')
37
+ end
38
+ end
39
+
40
+ end
41
+
42
+ #--------------------------------------------------------------------------
43
+
44
+ private
45
+
46
+ def assert_images(expected, actual, msg = nil)
47
+ assert_equal(expected.length, actual.length, "#{msg} - expected the same number of images")
48
+ expected.length.times do |n|
49
+ assert_equal(expected[n][:filename], actual[n][:filename], "#{msg} - unexpected filename at index #{n}")
50
+ assert_equal(expected[n][:width], actual[n][:width], "#{msg} - unexpected width at index #{n}")
51
+ assert_equal(expected[n][:height], actual[n][:height], "#{msg} - unexpected height at index #{n}")
52
+ end
53
+ end
54
+
55
+ #----------------------------------------------------------------------------
56
+
57
+ end
@@ -0,0 +1,156 @@
1
+ require File.expand_path('test_case', File.dirname(__FILE__))
2
+
3
+ module SpriteFactory
4
+ class RunnerTest < SpriteFactory::TestCase
5
+
6
+ #----------------------------------------------------------------------------
7
+
8
+ def test_defaults
9
+
10
+ Runner.publicize_methods do
11
+
12
+ r = Runner.new(REGULAR_PATH)
13
+ assert_equal(REGULAR_PATH, r.input)
14
+ assert_equal(REGULAR_PATH, r.output)
15
+ assert_equal(REGULAR_PATH + ".png", r.output_image_file)
16
+ assert_equal(REGULAR_PATH + ".css", r.output_style_file)
17
+ assert_equal(REGULAR, r.image_files)
18
+ assert_equal(:horizontal, r.layout_name)
19
+ assert_equal(:css, r.style_name)
20
+ assert_equal(:rmagick, r.library_name)
21
+
22
+ r = Runner.new(IRREGULAR_PATH)
23
+ assert_equal(IRREGULAR_PATH, r.input)
24
+ assert_equal(IRREGULAR_PATH, r.output)
25
+ assert_equal(IRREGULAR_PATH + ".png", r.output_image_file)
26
+ assert_equal(IRREGULAR_PATH + ".css", r.output_style_file)
27
+ assert_equal(IRREGULAR, r.image_files)
28
+ assert_equal(:horizontal, r.layout_name)
29
+ assert_equal(:css, r.style_name)
30
+ assert_equal(:rmagick, r.library_name)
31
+
32
+ r = Runner.new(REGULAR_PATH, :output => IRREGULAR_PATH)
33
+ assert_equal(REGULAR_PATH, r.input)
34
+ assert_equal(IRREGULAR_PATH, r.output)
35
+ assert_equal(IRREGULAR_PATH + ".png", r.output_image_file)
36
+ assert_equal(IRREGULAR_PATH + ".css", r.output_style_file)
37
+ assert_equal(REGULAR, r.image_files)
38
+ assert_equal(:horizontal, r.layout_name)
39
+ assert_equal(:css, r.style_name)
40
+ assert_equal(:rmagick, r.library_name)
41
+
42
+ r = Runner.new(REGULAR_PATH, :layout => :vertical, :library => :chunkypng, :style => :sass)
43
+ assert_equal(REGULAR_PATH, r.input)
44
+ assert_equal(REGULAR_PATH, r.output)
45
+ assert_equal(REGULAR_PATH + ".png", r.output_image_file)
46
+ assert_equal(REGULAR_PATH + ".sass", r.output_style_file)
47
+ assert_equal(REGULAR, r.image_files)
48
+ assert_equal(:vertical, r.layout_name)
49
+ assert_equal(:sass, r.style_name)
50
+ assert_equal(:chunkypng, r.library_name)
51
+
52
+ end
53
+
54
+ end
55
+
56
+ #----------------------------------------------------------------------------
57
+
58
+ def test_default_padding
59
+ Runner.publicize_methods do
60
+ r = Runner.new(REGULAR_PATH)
61
+ assert_equal(0, r.hpadding)
62
+ assert_equal(0, r.vpadding)
63
+
64
+ r = Runner.new(REGULAR_PATH, :padding => 10)
65
+ assert_equal(10, r.hpadding)
66
+ assert_equal(10, r.vpadding)
67
+
68
+ r = Runner.new(REGULAR_PATH, :hpadding => 10, :vpadding => 20)
69
+ assert_equal(10, r.hpadding)
70
+ assert_equal(20, r.vpadding)
71
+ end
72
+ end
73
+
74
+ #----------------------------------------------------------------------------
75
+
76
+ def test_default_css_path
77
+ Runner.publicize_methods do
78
+ r1 = Runner.new(REGULAR_PATH)
79
+ r2 = Runner.new(REGULAR_PATH, :csspath => "http://s3.amazonaws.com/sf")
80
+ r3 = Runner.new(REGULAR_PATH, :csspath => "<%= image_path('$IMAGE') %>")
81
+ r4 = Runner.new(REGULAR_PATH, :csspath => lambda{|image| "/very/dynamic/path/#{image}"})
82
+
83
+ assert_equal("regular.png", r1.css_path, "by default, csspath should be basename of the generated sprite image")
84
+ assert_equal("http://s3.amazonaws.com/sf/regular.png", r2.css_path, "allow customization by prepending to basename of the generated sprite image")
85
+ assert_equal("<%= image_path('regular.png') %>", r3.css_path, "allow customization by providing custom format string with $IMAGE token to be replaced with basename of the generated sprite image")
86
+ assert_equal("/very/dynamic/path/regular.png", r4.css_path, "allow customization by lambda function - allow caller to decide how to generate css path to sprite image")
87
+ end
88
+ end
89
+
90
+ #----------------------------------------------------------------------------
91
+
92
+ def test_trailing_slash_on_input_is_ignored
93
+ Runner.publicize_methods do
94
+ r = Runner.new("#{REGULAR_PATH}/")
95
+ assert_equal(REGULAR_PATH, r.input)
96
+ assert_equal(REGULAR_PATH, r.output)
97
+ assert_equal(REGULAR_PATH + ".png", r.output_image_file)
98
+ assert_equal(REGULAR_PATH + ".css", r.output_style_file)
99
+ assert_equal(REGULAR, r.image_files)
100
+ end
101
+ end
102
+
103
+ #----------------------------------------------------------------------------
104
+
105
+ def test_invalid_config
106
+
107
+ assert_runtime_error "input must be a single directory" do
108
+ SpriteFactory.run!("")
109
+ end
110
+
111
+ assert_runtime_error "input must be a single directory" do
112
+ SpriteFactory.run!(REGULAR.first)
113
+ end
114
+
115
+ assert_runtime_error "no output file specified" do
116
+ SpriteFactory.run!(REGULAR_PATH, :output => "")
117
+ end
118
+
119
+ assert_runtime_error "no image files found" do
120
+ SpriteFactory.run!(EMPTY_PATH)
121
+ end
122
+
123
+ assert_runtime_error "unknown layout diagonal" do
124
+ SpriteFactory.run!(REGULAR_PATH, :layout => :diagonal)
125
+ end
126
+
127
+ assert_runtime_error "unknown style funky" do
128
+ SpriteFactory.run!(REGULAR_PATH, :style => :funky)
129
+ end
130
+
131
+ assert_runtime_error "unknown library hogwarts" do
132
+ SpriteFactory.run!(REGULAR_PATH, :library => :hogwarts)
133
+ end
134
+
135
+ assert_runtime_error "set :width for fixed width, or :hpadding for horizontal padding, but not both." do
136
+ SpriteFactory.run!(REGULAR_PATH, :width => 50, :padding => 10)
137
+ end
138
+
139
+ assert_runtime_error "set :height for fixed height, or :vpadding for vertical padding, but not both." do
140
+ SpriteFactory.run!(REGULAR_PATH, :height => 50, :padding => 10)
141
+ end
142
+
143
+ assert_runtime_error "image regular1 does not fit within a fixed width of 10" do
144
+ SpriteFactory.run!(REGULAR_PATH, :width => 10)
145
+ end
146
+
147
+ assert_runtime_error "image regular1 does not fit within a fixed height of 10" do
148
+ SpriteFactory.run!(REGULAR_PATH, :height => 10)
149
+ end
150
+
151
+ end
152
+
153
+ #----------------------------------------------------------------------------
154
+
155
+ end
156
+ end