sprite-factory 1.4.2 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/README.md +58 -5
- data/RELEASE_NOTES.md +10 -3
- data/Rakefile +6 -2
- data/lib/sprite_factory.rb +1 -1
- data/lib/sprite_factory/layout/horizontal.rb +6 -4
- data/lib/sprite_factory/layout/packed.rb +26 -15
- data/lib/sprite_factory/layout/vertical.rb +7 -5
- data/lib/sprite_factory/runner.rb +21 -5
- data/test/images/hover/div.bar__img.icon--hover.png +0 -0
- data/test/images/hover/div.bar__img.icon.png +0 -0
- data/test/images/hover/div.foo__img.icon--hover.png +0 -0
- data/test/images/hover/div.foo__img.icon.png +0 -0
- data/test/images/reference/hover.css +22 -0
- data/test/images/reference/hover.png +0 -0
- data/test/images/reference/index.html +25 -2
- data/test/images/reference/irregular.margin.css +24 -0
- data/test/images/reference/irregular.margin.png +0 -0
- data/test/images/reference/irregular.packed.css +6 -6
- data/test/images/reference/irregular.packed.png +0 -0
- data/test/images/reference/regular.margin.css +24 -0
- data/test/images/reference/regular.margin.png +0 -0
- data/test/images/reference/regular.packed.css +6 -6
- data/test/images/reference/regular.packed.png +0 -0
- data/test/integration_test.rb +24 -2
- data/test/layout/horizontal_test.rb +56 -0
- data/test/layout/packed_test.rb +82 -20
- data/test/layout/vertical_test.rb +56 -0
- data/test/runner_test.rb +24 -0
- data/test/test_case.rb +1 -0
- metadata +70 -42
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Sprite Factory (v1.
|
1
|
+
Sprite Factory (v1.5.0)
|
2
2
|
=======================
|
3
3
|
|
4
4
|
The sprite factory is a ruby library that can be used to generate
|
@@ -13,6 +13,7 @@ The library provides:
|
|
13
13
|
* support for multiple layout algorithms - horizontal, vertical or [packed](http://codeincomplete.com/posts/2011/5/7/bin_packing/)
|
14
14
|
* support for any stylesheet syntax, including [CSS](http://www.w3.org/Style/CSS/) and [Sass](http://sass-lang.com/).
|
15
15
|
* support for any image library, including [RMagick](http://rmagick.rubyforge.org/) and [ChunkyPNG](https://github.com/wvanbergen/chunky_png).
|
16
|
+
* support for any css selector style, including :hover pseudo-class selectors
|
16
17
|
* support for pngcrush'n the generated image file
|
17
18
|
* compatible with Rails 3.1 asset pipeline
|
18
19
|
|
@@ -92,6 +93,7 @@ Much of the behavior can be customized by overriding the following options:
|
|
92
93
|
- `:output_style` - specify output location for generated stylesheet (default: <input folder>.<style>)
|
93
94
|
- `:pngcrush` - pngcrush the generated output image (if pngcrush is available)
|
94
95
|
- `:padding` - add padding to each sprite
|
96
|
+
- `:margin` - add margin to each sprite
|
95
97
|
- `:width` - fix width of each sprite to a specific size
|
96
98
|
- `:height` - fix height of each sprite to a specific size
|
97
99
|
- `:nocss` - suppress generation of output stylesheet (`run!` returns css content as a string instead)
|
@@ -109,7 +111,13 @@ You can see the results of many of these options by viewing the sample page that
|
|
109
111
|
comes with the gem in `test/images/reference/index.html`.
|
110
112
|
|
111
113
|
>> NOTE: only the common options are available via the command line script (to keep it simple). Specifically,
|
112
|
-
the advanced `width`, `height`, `padding` and `nocss` options are only available via the Ruby interface.
|
114
|
+
the advanced `width`, `height`, `padding`, `margin` and `nocss` options are only available via the Ruby interface.
|
115
|
+
|
116
|
+
>> NOTE: the `width`, `height` and `padding` options are not particularly useful - you would be better off just
|
117
|
+
making your source images have the correct dimensions by editing them appropriately in photoshop (or your editor of choice)
|
118
|
+
|
119
|
+
>> NOTE: the `margin` option is used primarily to buffer each image in the generated sprite with > 1px margin to
|
120
|
+
avoid images bleeding into each other when the browser needs to scale them (e.g. when user increases/decreases font size).
|
113
121
|
|
114
122
|
Layout
|
115
123
|
======
|
@@ -129,7 +137,17 @@ Customizing the CSS Selector
|
|
129
137
|
|
130
138
|
By default, the CSS generated is fairly simple. It assumes you will be using `<img>`
|
131
139
|
elements for your sprites, and that the basename of each individual file is suitable for
|
132
|
-
use as a CSS classname. For example:
|
140
|
+
use as a CSS classname. For example, the following files:
|
141
|
+
|
142
|
+
images/icons/high.png
|
143
|
+
images/icons/medium.png
|
144
|
+
images/icons/low.png
|
145
|
+
|
146
|
+
... when run with:
|
147
|
+
|
148
|
+
SpriteFactory.run!('images/icons')
|
149
|
+
|
150
|
+
... will generate the following css:
|
133
151
|
|
134
152
|
img.high { width: 16px; height: 16px; background: url(images/icons.png) 0px 0px no-repeat; }
|
135
153
|
img.medium { width: 16px; height: 16px; background: url(images/icons.png) -16px 0px no-repeat; }
|
@@ -140,12 +158,47 @@ example:
|
|
140
158
|
|
141
159
|
SpriteFactory.run!('images/icons', :selector => 'span.icon_')
|
142
160
|
|
143
|
-
will generate:
|
161
|
+
... will generate:
|
144
162
|
|
145
163
|
span.icon_high { width: 16px; height: 16px; background: url(images/icons.png) 0px 0px no-repeat; }
|
146
164
|
span.icon_medium { width: 16px; height: 16px; background: url(images/icons.png) -16px 0px no-repeat; }
|
147
165
|
span.icon_low { width: 16px; height: 16px; background: url(images/icons.png) -32px 0px no-repeat; }
|
148
166
|
|
167
|
+
Customizing the CSS Selector Per Image
|
168
|
+
======================================
|
169
|
+
|
170
|
+
If you want to specify a custom selector for each individual image, then name the image files
|
171
|
+
accordingly - the library will map '\_\_' (double underscore) to a single space ' ' in any source
|
172
|
+
image filename. For example:
|
173
|
+
|
174
|
+
images/icons/div.foo__span.icon_alert.png
|
175
|
+
images/icons/div.bar__span.icon_alert.png
|
176
|
+
|
177
|
+
... when run with:
|
178
|
+
|
179
|
+
SpriteFactory.run!('images/icons', :selector => 'div.example ')
|
180
|
+
|
181
|
+
... will generate:
|
182
|
+
|
183
|
+
div.example div.foo span.icon_alert { ... first file ... }
|
184
|
+
div.example div.bar span.icon_alert { ... second file ... }
|
185
|
+
|
186
|
+
|
187
|
+
If you want to specify a psuedo class such as `:hover` for some of your images, the library will also
|
188
|
+
map '--' (double dash) to a colon ':' in any source image filename. For example:
|
189
|
+
|
190
|
+
images/icons/alert.png
|
191
|
+
images/icons/alert--hover.png
|
192
|
+
|
193
|
+
... when run with:
|
194
|
+
|
195
|
+
SpriteFactory.run!('images/icons', :selector => 'span.icon_')
|
196
|
+
|
197
|
+
... will generate:
|
198
|
+
|
199
|
+
span.icon_alert { ... first file ... }
|
200
|
+
span.icon_alert:hover { ... second file ... }
|
201
|
+
|
149
202
|
Customizing the CSS Image Path
|
150
203
|
==============================
|
151
204
|
|
@@ -210,7 +263,7 @@ value is a hash of image metadata that includes the following:
|
|
210
263
|
* `:width` - the image width
|
211
264
|
* `:height` - the image height
|
212
265
|
|
213
|
-
(*NOTE*: the image coords can differ form the css sprite coords when padding or fixed width/height options are specified)
|
266
|
+
(*NOTE*: the image coords can differ form the css sprite coords when padding/margin or fixed width/height options are specified)
|
214
267
|
|
215
268
|
Using sprite-factory with the Rails 3.1 asset pipeline
|
216
269
|
======================================================
|
data/RELEASE_NOTES.md
CHANGED
@@ -1,6 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
May 10th 2012 - v1.5.0
|
2
|
+
----------------------
|
3
|
+
* @halida added a new `margin` option to (optionally) separate images in generated spritesheet to avoid 'bleeding' when browser scales the sprite (e.g. when user increases text size)
|
4
|
+
* added `padding` support for `packed` layout
|
5
|
+
* added `margin` support for `packed` layout
|
6
|
+
* added support for using source image filename as automatic css selector [issue #12](https://github.com/jakesgordon/sprite-factory/issues/12)
|
7
|
+
* added support for `:hover` (and other pseudo-class) selectors [issue #14](https://github.com/jakesgordon/sprite-factory/issues/14)
|
8
|
+
|
9
|
+
February 29th 2012 - v1.4.2
|
10
|
+
---------------------------
|
4
11
|
* added support for `:nocomments => true` to suppress comments in generated output stylesheet
|
5
12
|
* added support for images in subfolders - fixes [github issue #11](https://github.com/jakesgordon/sprite-factory/issues/11)
|
6
13
|
|
data/Rakefile
CHANGED
@@ -31,19 +31,23 @@ task :reference do
|
|
31
31
|
regenerate.call('test/images/regular')
|
32
32
|
regenerate.call('test/images/regular', :output => 'test/images/regular.horizontal', :selector => 'img.horizontal_', :layout => :horizontal)
|
33
33
|
regenerate.call('test/images/regular', :output => 'test/images/regular.vertical', :selector => 'img.vertical_', :layout => :vertical)
|
34
|
-
regenerate.call('test/images/regular', :output => 'test/images/regular.packed', :selector => 'img.packed_', :layout => :packed)
|
34
|
+
regenerate.call('test/images/regular', :output => 'test/images/regular.packed', :selector => 'img.packed_', :layout => :packed, :padding => 10, :margin => 10)
|
35
35
|
regenerate.call('test/images/regular', :output => 'test/images/regular.padded', :selector => 'img.padded_', :padding => 10)
|
36
|
+
regenerate.call('test/images/regular', :output => 'test/images/regular.margin', :selector => 'img.margin_', :margin => 10)
|
36
37
|
regenerate.call('test/images/regular', :output => 'test/images/regular.fixed', :selector => 'img.fixed_', :width => 100, :height => 100)
|
37
38
|
regenerate.call('test/images/regular', :output => 'test/images/regular.sassy', :selector => 'img.sassy_', :style => :sass)
|
38
39
|
|
39
40
|
regenerate.call('test/images/irregular')
|
40
41
|
regenerate.call('test/images/irregular', :output => 'test/images/irregular.horizontal', :selector => 'img.horizontal_', :layout => :horizontal)
|
41
42
|
regenerate.call('test/images/irregular', :output => 'test/images/irregular.vertical', :selector => 'img.vertical_', :layout => :vertical)
|
42
|
-
regenerate.call('test/images/irregular', :output => 'test/images/irregular.packed', :selector => 'img.packed_', :layout => :packed)
|
43
|
+
regenerate.call('test/images/irregular', :output => 'test/images/irregular.packed', :selector => 'img.packed_', :layout => :packed, :padding => 10, :margin => 10)
|
43
44
|
regenerate.call('test/images/irregular', :output => 'test/images/irregular.padded', :selector => 'img.padded_', :padding => 10)
|
45
|
+
regenerate.call('test/images/irregular', :output => 'test/images/irregular.margin', :selector => 'img.margin_', :margin => 10)
|
44
46
|
regenerate.call('test/images/irregular', :output => 'test/images/irregular.fixed', :selector => 'img.fixed_', :width => 100, :height => 100)
|
45
47
|
regenerate.call('test/images/irregular', :output => 'test/images/irregular.sassy', :selector => 'img.sassy_', :style => :sass)
|
46
48
|
|
49
|
+
regenerate.call('test/images/hover', :output => 'test/images/hover', :selector => 'div.hover ', :style => :css)
|
50
|
+
|
47
51
|
regenerate.call('test/images/custom', :output => 'test/images/custom') do |images|
|
48
52
|
rules = []
|
49
53
|
rules << "div.running img.button { cursor: pointer; #{images[:running][:style]} }"
|
data/lib/sprite_factory.rb
CHANGED
@@ -2,7 +2,7 @@ module SpriteFactory
|
|
2
2
|
|
3
3
|
#----------------------------------------------------------------------------
|
4
4
|
|
5
|
-
VERSION = "1.
|
5
|
+
VERSION = "1.5.0"
|
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__)
|
@@ -7,7 +7,9 @@ module SpriteFactory
|
|
7
7
|
height = options[:height]
|
8
8
|
hpadding = options[:hpadding] || 0
|
9
9
|
vpadding = options[:vpadding] || 0
|
10
|
-
|
10
|
+
hmargin = options[:hmargin] || 0
|
11
|
+
vmargin = options[:vmargin] || 0
|
12
|
+
max_height = height || (2 *(vpadding + vmargin) + images.map{|i| i[:height]}.max)
|
11
13
|
x = 0
|
12
14
|
images.each do |i|
|
13
15
|
|
@@ -17,8 +19,8 @@ module SpriteFactory
|
|
17
19
|
i[:x] = x + (width - i[:width]) / 2
|
18
20
|
else
|
19
21
|
i[:cssw] = i[:width] + (2 * hpadding) # image width plus padding
|
20
|
-
i[:cssx] = x
|
21
|
-
i[:x]
|
22
|
+
i[:cssx] = x + hmargin # anchored at x
|
23
|
+
i[:x] = i[:cssx] + hpadding # image drawn offset to account for padding
|
22
24
|
end
|
23
25
|
|
24
26
|
if height
|
@@ -31,7 +33,7 @@ module SpriteFactory
|
|
31
33
|
i[:y] = i[:cssy] + vpadding # image drawn offset to account for padding
|
32
34
|
end
|
33
35
|
|
34
|
-
x
|
36
|
+
x += i[:cssw] + 2 * hmargin
|
35
37
|
|
36
38
|
end
|
37
39
|
{ :width => x, :height => max_height }
|
@@ -6,27 +6,36 @@ module SpriteFactory
|
|
6
6
|
|
7
7
|
def self.layout(images, options = {})
|
8
8
|
|
9
|
-
raise NotImplementedError, ":packed layout does not support the :padding option" if (options[:padding].to_i > 0) || (options[:hpadding].to_i > 0) || (options[:vpadding].to_i > 0)
|
10
9
|
raise NotImplementedError, ":packed layout does not support fixed :width/:height option" if options[:width] || options[:height]
|
11
10
|
|
12
11
|
return { :width => 0, :height => 0 } if images.empty?
|
13
12
|
|
13
|
+
hpadding = options[:hpadding] || 0
|
14
|
+
vpadding = options[:vpadding] || 0
|
15
|
+
hmargin = options[:hmargin] || 0
|
16
|
+
vmargin = options[:vmargin] || 0
|
17
|
+
|
18
|
+
images.each do |i|
|
19
|
+
i[:w] = i[:width] + (2*hpadding) + (2*hmargin)
|
20
|
+
i[:h] = i[:height] + (2*vpadding) + (2*vmargin)
|
21
|
+
end
|
22
|
+
|
14
23
|
images.sort! do |a,b|
|
15
|
-
diff = [b[:
|
16
|
-
diff = [b[:
|
17
|
-
diff = b[:
|
18
|
-
diff = b[:
|
24
|
+
diff = [b[:w], b[:h]].max <=> [a[:w], a[:h]].max
|
25
|
+
diff = [b[:w], b[:h]].min <=> [a[:w], a[:h]].min if diff.zero?
|
26
|
+
diff = b[:h] <=> a[:h] if diff.zero?
|
27
|
+
diff = b[:w] <=> a[:w] if diff.zero?
|
19
28
|
diff
|
20
29
|
end
|
21
30
|
|
22
|
-
root = { :x => 0, :y => 0, :w => images[0][:
|
31
|
+
root = { :x => 0, :y => 0, :w => images[0][:w], :h => images[0][:h] }
|
23
32
|
|
24
33
|
images.each do |i|
|
25
|
-
if (node = findNode(root, i[:
|
26
|
-
placeImage(i, node)
|
27
|
-
splitNode(node, i[:
|
34
|
+
if (node = findNode(root, i[:w], i[:h]))
|
35
|
+
placeImage(i, node, hpadding, vpadding, hmargin, vmargin)
|
36
|
+
splitNode(node, i[:w], i[:h])
|
28
37
|
else
|
29
|
-
root = grow(root, i[:
|
38
|
+
root = grow(root, i[:w], i[:h])
|
30
39
|
redo
|
31
40
|
end
|
32
41
|
end
|
@@ -35,11 +44,13 @@ module SpriteFactory
|
|
35
44
|
|
36
45
|
end
|
37
46
|
|
38
|
-
def self.placeImage(image, node)
|
39
|
-
image[:cssx] =
|
40
|
-
image[:cssy] =
|
41
|
-
image[:cssw] = image[:width]
|
42
|
-
image[:cssh] = image[:height]
|
47
|
+
def self.placeImage(image, node, hpadding, vpadding, hmargin, vmargin)
|
48
|
+
image[:cssx] = node[:x] + hmargin
|
49
|
+
image[:cssy] = node[:y] + vmargin
|
50
|
+
image[:cssw] = image[:width] + (2*hpadding)
|
51
|
+
image[:cssh] = image[:height] + (2*vpadding)
|
52
|
+
image[:x] = image[:cssx] + hpadding
|
53
|
+
image[:y] = image[:cssy] + vpadding
|
43
54
|
end
|
44
55
|
|
45
56
|
def self.findNode(root, w, h)
|
@@ -7,7 +7,9 @@ module SpriteFactory
|
|
7
7
|
height = options[:height]
|
8
8
|
hpadding = options[:hpadding] || 0
|
9
9
|
vpadding = options[:vpadding] || 0
|
10
|
-
|
10
|
+
hmargin = options[:hmargin] || 0
|
11
|
+
vmargin = options[:vmargin] || 0
|
12
|
+
max_width = width || (2 * (hpadding + hmargin) + images.map{|i| i[:width]}.max)
|
11
13
|
y = 0
|
12
14
|
images.each do |i|
|
13
15
|
|
@@ -26,12 +28,12 @@ module SpriteFactory
|
|
26
28
|
i[:cssy] = y
|
27
29
|
i[:y] = y + (height - i[:height]) / 2
|
28
30
|
else
|
29
|
-
i[:cssh] = i[:height] + (2 * vpadding)
|
30
|
-
i[:cssy] = y
|
31
|
-
i[:y] = i[:cssy] + vpadding
|
31
|
+
i[:cssh] = i[:height] + (2 * vpadding) # image height plus padding
|
32
|
+
i[:cssy] = y + vmargin # anchored at y
|
33
|
+
i[:y] = i[:cssy] + vpadding # image drawn offset to account for padding
|
32
34
|
end
|
33
35
|
|
34
|
-
y
|
36
|
+
y += i[:cssh] + 2 * vmargin
|
35
37
|
|
36
38
|
end
|
37
39
|
{ :width => max_width, :height => y }
|
@@ -38,6 +38,8 @@ module SpriteFactory
|
|
38
38
|
|
39
39
|
raise RuntimeError, "set :width for fixed width, or :hpadding for horizontal padding, but not both." if width && !hpadding.zero?
|
40
40
|
raise RuntimeError, "set :height for fixed height, or :vpadding for vertical padding, but not both." if height && !vpadding.zero?
|
41
|
+
raise RuntimeError, "set :width for fixed width, or :hmargin for horizontal margin, but not both." if width && !hmargin.zero?
|
42
|
+
raise RuntimeError, "set :height for fixed height, or :vmargin for vertical margin, but not both." if height && !hmargin.zero?
|
41
43
|
|
42
44
|
images = load_images
|
43
45
|
max = layout_images(images)
|
@@ -91,6 +93,14 @@ module SpriteFactory
|
|
91
93
|
config[:vpadding] || config[:padding] || 0
|
92
94
|
end
|
93
95
|
|
96
|
+
def hmargin
|
97
|
+
config[:hmargin] || config[:margin] || 0
|
98
|
+
end
|
99
|
+
|
100
|
+
def vmargin
|
101
|
+
config[:vmargin] || config[:margin] || 0
|
102
|
+
end
|
103
|
+
|
94
104
|
def width
|
95
105
|
config[:width]
|
96
106
|
end
|
@@ -156,16 +166,22 @@ module SpriteFactory
|
|
156
166
|
input_path = Pathname.new(input)
|
157
167
|
images = library.load(image_files)
|
158
168
|
images.each do |i|
|
159
|
-
i[:name] =
|
160
|
-
i[:ext] = File.extname(i[:name])
|
161
|
-
i[:name] = i[:name][0...-i[:ext].length] unless i[:ext].empty?
|
162
|
-
|
169
|
+
i[:name], i[:ext] = map_image_filename(i[:filename], input_path)
|
163
170
|
raise RuntimeError, "image #{i[:name]} does not fit within a fixed width of #{width}" if width && (width < i[:width])
|
164
171
|
raise RuntimeError, "image #{i[:name]} does not fit within a fixed height of #{height}" if height && (height < i[:height])
|
165
172
|
end
|
166
173
|
images
|
167
174
|
end
|
168
175
|
|
176
|
+
def map_image_filename(filename, input_path)
|
177
|
+
name = Pathname.new(filename).relative_path_from(input_path).to_s.gsub(File::SEPARATOR, "_")
|
178
|
+
name = name.gsub('--', ':')
|
179
|
+
name = name.gsub('__', ' ')
|
180
|
+
ext = File.extname(name)
|
181
|
+
name = name[0...-ext.length] unless ext.empty?
|
182
|
+
[name, ext]
|
183
|
+
end
|
184
|
+
|
169
185
|
def create_sprite(images, width, height)
|
170
186
|
library.create(output_image_file, images, width, height)
|
171
187
|
pngcrush(output_image_file)
|
@@ -178,7 +194,7 @@ module SpriteFactory
|
|
178
194
|
end
|
179
195
|
|
180
196
|
def layout_images(images)
|
181
|
-
layout_strategy.layout(images, :width => width, :height => height, :hpadding => hpadding, :vpadding => vpadding)
|
197
|
+
layout_strategy.layout(images, :width => width, :height => height, :hpadding => hpadding, :vpadding => vpadding, :hmargin => hmargin, :vmargin => vmargin)
|
182
198
|
end
|
183
199
|
|
184
200
|
#----------------------------------------------------------------------------
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,22 @@
|
|
1
|
+
/*
|
2
|
+
|
3
|
+
Creating a sprite from following images:
|
4
|
+
|
5
|
+
test/images/hover/div.bar__img.icon--hover.png (18x18)
|
6
|
+
test/images/hover/div.bar__img.icon.png (18x18)
|
7
|
+
test/images/hover/div.foo__img.icon--hover.png (18x18)
|
8
|
+
test/images/hover/div.foo__img.icon.png (18x18)
|
9
|
+
|
10
|
+
Output files:
|
11
|
+
test/images/hover.png
|
12
|
+
test/images/hover.css
|
13
|
+
|
14
|
+
Output size:
|
15
|
+
72x18
|
16
|
+
|
17
|
+
|
18
|
+
*/
|
19
|
+
div.hover div.bar img.icon:hover { width: 18px; height: 18px; background: url(hover.png) 0px 0px no-repeat; }
|
20
|
+
div.hover div.bar img.icon { width: 18px; height: 18px; background: url(hover.png) -18px 0px no-repeat; }
|
21
|
+
div.hover div.foo img.icon:hover { width: 18px; height: 18px; background: url(hover.png) -36px 0px no-repeat; }
|
22
|
+
div.hover div.foo img.icon { width: 18px; height: 18px; background: url(hover.png) -54px 0px no-repeat; }
|
Binary file
|
@@ -8,6 +8,7 @@
|
|
8
8
|
<link href='regular.vertical.css' rel='stylesheet' type='text/css' media='screen'></link>
|
9
9
|
<link href='regular.packed.css' rel='stylesheet' type='text/css' media='screen'></link>
|
10
10
|
<link href='regular.padded.css' rel='stylesheet' type='text/css' media='screen'></link>
|
11
|
+
<link href='regular.margin.css' rel='stylesheet' type='text/css' media='screen'></link>
|
11
12
|
<link href='regular.fixed.css' rel='stylesheet' type='text/css' media='screen'></link>
|
12
13
|
<link href='regular.sassy.css' rel='stylesheet' type='text/css' media='screen'></link>
|
13
14
|
<link href='irregular.css' rel='stylesheet' type='text/css' media='screen'></link>
|
@@ -15,11 +16,13 @@
|
|
15
16
|
<link href='irregular.vertical.css' rel='stylesheet' type='text/css' media='screen'></link>
|
16
17
|
<link href='irregular.packed.css' rel='stylesheet' type='text/css' media='screen'></link>
|
17
18
|
<link href='irregular.padded.css' rel='stylesheet' type='text/css' media='screen'></link>
|
19
|
+
<link href='irregular.margin.css' rel='stylesheet' type='text/css' media='screen'></link>
|
18
20
|
<link href='irregular.fixed.css' rel='stylesheet' type='text/css' media='screen'></link>
|
19
21
|
<link href='irregular.sassy.css' rel='stylesheet' type='text/css' media='screen'></link>
|
20
22
|
<link href='custom.css' rel='stylesheet' type='text/css' media='screen'></link>
|
21
23
|
<link href='formats.css' rel='stylesheet' type='text/css' media='screen'></link>
|
22
24
|
<link href='subfolders.css' rel='stylesheet' type='text/css' media='screen'></link>
|
25
|
+
<link href='hover.css' rel='stylesheet' type='text/css' media='screen'></link>
|
23
26
|
<style>
|
24
27
|
img { border: 1px solid red; }
|
25
28
|
</style>
|
@@ -47,7 +50,7 @@
|
|
47
50
|
<img src='s.gif' class='vertical_regular4'><br>
|
48
51
|
<img src='s.gif' class='vertical_regular5'><br>
|
49
52
|
|
50
|
-
<h1>Regular (packed)</h1>
|
53
|
+
<h1>Regular (packed with padding and margin)</h1>
|
51
54
|
<img src='s.gif' class='packed_regular1'>
|
52
55
|
<img src='s.gif' class='packed_regular2'>
|
53
56
|
<img src='s.gif' class='packed_regular3'>
|
@@ -61,6 +64,13 @@
|
|
61
64
|
<img src='s.gif' class='padded_regular4'>
|
62
65
|
<img src='s.gif' class='padded_regular5'>
|
63
66
|
|
67
|
+
<h1>Regular (margin)</h1>
|
68
|
+
<img src='s.gif' class='margin_regular1'>
|
69
|
+
<img src='s.gif' class='margin_regular2'>
|
70
|
+
<img src='s.gif' class='margin_regular3'>
|
71
|
+
<img src='s.gif' class='margin_regular4'>
|
72
|
+
<img src='s.gif' class='margin_regular5'>
|
73
|
+
|
64
74
|
<h1>Regular (fixed)</h1>
|
65
75
|
<img src='s.gif' class='fixed_regular1'>
|
66
76
|
<img src='s.gif' class='fixed_regular2'>
|
@@ -96,7 +106,7 @@
|
|
96
106
|
<img src='s.gif' class='vertical_irregular4'><br>
|
97
107
|
<img src='s.gif' class='vertical_irregular5'><br>
|
98
108
|
|
99
|
-
<h1>Irregular (packed)</h1>
|
109
|
+
<h1>Irregular (packed with padding and margin)</h1>
|
100
110
|
<img src='s.gif' class='packed_irregular1'>
|
101
111
|
<img src='s.gif' class='packed_irregular2'>
|
102
112
|
<img src='s.gif' class='packed_irregular3'>
|
@@ -110,6 +120,13 @@
|
|
110
120
|
<img src='s.gif' class='padded_irregular4'>
|
111
121
|
<img src='s.gif' class='padded_irregular5'>
|
112
122
|
|
123
|
+
<h1>Irregular (margin)</h1>
|
124
|
+
<img src='s.gif' class='margin_irregular1'>
|
125
|
+
<img src='s.gif' class='margin_irregular2'>
|
126
|
+
<img src='s.gif' class='margin_irregular3'>
|
127
|
+
<img src='s.gif' class='margin_irregular4'>
|
128
|
+
<img src='s.gif' class='margin_irregular5'>
|
129
|
+
|
113
130
|
<h1>Irregular (fixed)</h1>
|
114
131
|
<img src='s.gif' class='fixed_irregular1'>
|
115
132
|
<img src='s.gif' class='fixed_irregular2'>
|
@@ -144,6 +161,12 @@
|
|
144
161
|
<img src='s.gif' class='usa_amy'>
|
145
162
|
<img src='s.gif' class='usa_bob'>
|
146
163
|
|
164
|
+
<h1>With Hover State</h1>
|
165
|
+
<div class='hover'>
|
166
|
+
<div class='foo'><img src='s.gif' class='icon'></div>
|
167
|
+
<div class='bar'><img src='s.gif' class='icon'></div>
|
168
|
+
</div>
|
169
|
+
|
147
170
|
<script>
|
148
171
|
SpriteFactory = {
|
149
172
|
toggleTimer: function() {
|
@@ -0,0 +1,24 @@
|
|
1
|
+
/*
|
2
|
+
|
3
|
+
Creating a sprite from following images:
|
4
|
+
|
5
|
+
test/images/irregular/irregular1.png (60x60)
|
6
|
+
test/images/irregular/irregular2.png (16x16)
|
7
|
+
test/images/irregular/irregular3.png (48x48)
|
8
|
+
test/images/irregular/irregular4.png (34x14)
|
9
|
+
test/images/irregular/irregular5.png (46x25)
|
10
|
+
|
11
|
+
Output files:
|
12
|
+
test/images/irregular.margin.png
|
13
|
+
test/images/irregular.margin.css
|
14
|
+
|
15
|
+
Output size:
|
16
|
+
304x80
|
17
|
+
|
18
|
+
|
19
|
+
*/
|
20
|
+
img.margin_irregular1 { width: 60px; height: 60px; background: url(irregular.margin.png) -10px -10px no-repeat; }
|
21
|
+
img.margin_irregular2 { width: 16px; height: 16px; background: url(irregular.margin.png) -90px -32px no-repeat; }
|
22
|
+
img.margin_irregular3 { width: 48px; height: 48px; background: url(irregular.margin.png) -126px -16px no-repeat; }
|
23
|
+
img.margin_irregular4 { width: 34px; height: 14px; background: url(irregular.margin.png) -194px -33px no-repeat; }
|
24
|
+
img.margin_irregular5 { width: 46px; height: 25px; background: url(irregular.margin.png) -248px -27px no-repeat; }
|
Binary file
|
@@ -13,12 +13,12 @@
|
|
13
13
|
test/images/irregular.packed.css
|
14
14
|
|
15
15
|
Output size:
|
16
|
-
|
16
|
+
244x165
|
17
17
|
|
18
18
|
|
19
19
|
*/
|
20
|
-
img.packed_irregular1 { width:
|
21
|
-
img.packed_irregular3 { width:
|
22
|
-
img.packed_irregular5 { width:
|
23
|
-
img.packed_irregular4 { width:
|
24
|
-
img.packed_irregular2 { width:
|
20
|
+
img.packed_irregular1 { width: 80px; height: 80px; background: url(irregular.packed.png) -10px -10px no-repeat; }
|
21
|
+
img.packed_irregular3 { width: 68px; height: 68px; background: url(irregular.packed.png) -110px -10px no-repeat; }
|
22
|
+
img.packed_irregular5 { width: 66px; height: 45px; background: url(irregular.packed.png) -10px -110px no-repeat; }
|
23
|
+
img.packed_irregular4 { width: 54px; height: 34px; background: url(irregular.packed.png) -96px -110px no-repeat; }
|
24
|
+
img.packed_irregular2 { width: 36px; height: 36px; background: url(irregular.packed.png) -198px -10px no-repeat; }
|
Binary file
|
@@ -0,0 +1,24 @@
|
|
1
|
+
/*
|
2
|
+
|
3
|
+
Creating a sprite from following images:
|
4
|
+
|
5
|
+
test/images/regular/regular1.PNG (64x64)
|
6
|
+
test/images/regular/regular2.PNG (64x64)
|
7
|
+
test/images/regular/regular3.PNG (64x64)
|
8
|
+
test/images/regular/regular4.PNG (64x64)
|
9
|
+
test/images/regular/regular5.PNG (64x64)
|
10
|
+
|
11
|
+
Output files:
|
12
|
+
test/images/regular.margin.png
|
13
|
+
test/images/regular.margin.css
|
14
|
+
|
15
|
+
Output size:
|
16
|
+
420x84
|
17
|
+
|
18
|
+
|
19
|
+
*/
|
20
|
+
img.margin_regular1 { width: 64px; height: 64px; background: url(regular.margin.png) -10px -10px no-repeat; }
|
21
|
+
img.margin_regular2 { width: 64px; height: 64px; background: url(regular.margin.png) -94px -10px no-repeat; }
|
22
|
+
img.margin_regular3 { width: 64px; height: 64px; background: url(regular.margin.png) -178px -10px no-repeat; }
|
23
|
+
img.margin_regular4 { width: 64px; height: 64px; background: url(regular.margin.png) -262px -10px no-repeat; }
|
24
|
+
img.margin_regular5 { width: 64px; height: 64px; background: url(regular.margin.png) -346px -10px no-repeat; }
|
Binary file
|
@@ -13,12 +13,12 @@
|
|
13
13
|
test/images/regular.packed.css
|
14
14
|
|
15
15
|
Output size:
|
16
|
-
|
16
|
+
312x208
|
17
17
|
|
18
18
|
|
19
19
|
*/
|
20
|
-
img.packed_regular1 { width:
|
21
|
-
img.packed_regular2 { width:
|
22
|
-
img.packed_regular3 { width:
|
23
|
-
img.packed_regular4 { width:
|
24
|
-
img.packed_regular5 { width:
|
20
|
+
img.packed_regular1 { width: 84px; height: 84px; background: url(regular.packed.png) -10px -10px no-repeat; }
|
21
|
+
img.packed_regular2 { width: 84px; height: 84px; background: url(regular.packed.png) -114px -10px no-repeat; }
|
22
|
+
img.packed_regular3 { width: 84px; height: 84px; background: url(regular.packed.png) -10px -114px no-repeat; }
|
23
|
+
img.packed_regular4 { width: 84px; height: 84px; background: url(regular.packed.png) -114px -114px no-repeat; }
|
24
|
+
img.packed_regular5 { width: 84px; height: 84px; background: url(regular.packed.png) -218px -10px no-repeat; }
|
Binary file
|
data/test/integration_test.rb
CHANGED
@@ -24,7 +24,9 @@ module SpriteFactory
|
|
24
24
|
def test_generate_packed_regular_sprite
|
25
25
|
integration_test(REGULAR_PATH, :output => output_path('regular.packed'),
|
26
26
|
:selector => 'img.packed_',
|
27
|
-
:layout => :packed
|
27
|
+
:layout => :packed,
|
28
|
+
:padding => 10,
|
29
|
+
:margin => 10)
|
28
30
|
end
|
29
31
|
|
30
32
|
def test_generate_regular_sprite_with_padding
|
@@ -33,6 +35,12 @@ module SpriteFactory
|
|
33
35
|
:padding => 10)
|
34
36
|
end
|
35
37
|
|
38
|
+
def test_generate_regular_sprite_with_margin
|
39
|
+
integration_test(REGULAR_PATH, :output => output_path('regular.margin'),
|
40
|
+
:selector => 'img.margin_',
|
41
|
+
:margin => 10)
|
42
|
+
end
|
43
|
+
|
36
44
|
def test_generate_regular_sprite_with_fixed_size
|
37
45
|
integration_test(REGULAR_PATH, :output => output_path('regular.fixed'),
|
38
46
|
:selector => 'img.fixed_',
|
@@ -73,7 +81,9 @@ module SpriteFactory
|
|
73
81
|
def test_generate_packed_irregular_sprite
|
74
82
|
integration_test(IRREGULAR_PATH, :output => output_path('irregular.packed'),
|
75
83
|
:selector => 'img.packed_',
|
76
|
-
:layout => :packed
|
84
|
+
:layout => :packed,
|
85
|
+
:padding => 10,
|
86
|
+
:margin => 10)
|
77
87
|
end
|
78
88
|
|
79
89
|
def test_generate_irregular_sprite_with_padding
|
@@ -82,6 +92,12 @@ module SpriteFactory
|
|
82
92
|
:padding => 10)
|
83
93
|
end
|
84
94
|
|
95
|
+
def test_generate_irregular_sprite_with_margin
|
96
|
+
integration_test(IRREGULAR_PATH, :output => output_path('irregular.margin'),
|
97
|
+
:selector => 'img.margin_',
|
98
|
+
:margin => 10)
|
99
|
+
end
|
100
|
+
|
85
101
|
def test_generate_irregular_sprite_with_fixed_size
|
86
102
|
integration_test(IRREGULAR_PATH, :output => output_path('irregular.fixed'),
|
87
103
|
:selector => 'img.fixed_',
|
@@ -120,6 +136,12 @@ module SpriteFactory
|
|
120
136
|
|
121
137
|
#----------------------------------------------------------------------------
|
122
138
|
|
139
|
+
def test_generate_sprites_with_hover_pseudo_class
|
140
|
+
integration_test(HOVER_PATH, :selector => 'div.hover ')
|
141
|
+
end
|
142
|
+
|
143
|
+
#----------------------------------------------------------------------------
|
144
|
+
|
123
145
|
def test_generate_sprite_with_nocss
|
124
146
|
input = REGULAR_PATH
|
125
147
|
output = File.basename(REGULAR_PATH)
|
@@ -36,6 +36,34 @@ module SpriteFactory
|
|
36
36
|
|
37
37
|
#--------------------------------------------------------------------------
|
38
38
|
|
39
|
+
def test_margin_horizontal_layout_of_regular_images
|
40
|
+
images = get_regular_images
|
41
|
+
expected = [
|
42
|
+
{ :cssx => 10, :cssy => 20, :cssw => 20, :cssh => 10, :x => 10, :y => 20 },
|
43
|
+
{ :cssx => 50, :cssy => 20, :cssw => 20, :cssh => 10, :x => 50, :y => 20 },
|
44
|
+
{ :cssx => 90, :cssy => 20, :cssw => 20, :cssh => 10, :x => 90, :y => 20 },
|
45
|
+
{ :cssx => 130, :cssy => 20, :cssw => 20, :cssh => 10, :x => 130, :y => 20 },
|
46
|
+
{ :cssx => 170, :cssy => 20, :cssw => 20, :cssh => 10, :x => 170, :y => 20 }
|
47
|
+
]
|
48
|
+
verify_layout(200, 50, expected, images, :layout => :horizontal, :hmargin => 10, :vmargin => 20)
|
49
|
+
end
|
50
|
+
|
51
|
+
#--------------------------------------------------------------------------
|
52
|
+
|
53
|
+
def test_padded_and_margin_horizontal_layout_of_regular_images
|
54
|
+
images = get_regular_images
|
55
|
+
expected = [
|
56
|
+
{ :cssx => 10, :cssy => 20, :cssw => 24, :cssh => 18, :x => 12, :y => 24 },
|
57
|
+
{ :cssx => 54, :cssy => 20, :cssw => 24, :cssh => 18, :x => 56, :y => 24 },
|
58
|
+
{ :cssx => 98, :cssy => 20, :cssw => 24, :cssh => 18, :x => 100, :y => 24 },
|
59
|
+
{ :cssx => 142, :cssy => 20, :cssw => 24, :cssh => 18, :x => 144, :y => 24 },
|
60
|
+
{ :cssx => 186, :cssy => 20, :cssw => 24, :cssh => 18, :x => 188, :y => 24 }
|
61
|
+
]
|
62
|
+
verify_layout(220, 58, expected, images, :layout => :horizontal, :hmargin => 10, :vmargin => 20, :hpadding => 2, :vpadding => 4)
|
63
|
+
end
|
64
|
+
|
65
|
+
#--------------------------------------------------------------------------
|
66
|
+
|
39
67
|
def test_fixed_horizontal_layout_of_regular_images
|
40
68
|
images = get_regular_images
|
41
69
|
expected = [
|
@@ -80,6 +108,34 @@ module SpriteFactory
|
|
80
108
|
|
81
109
|
#--------------------------------------------------------------------------
|
82
110
|
|
111
|
+
def test_margin_horizontal_layout_of_irregular_images
|
112
|
+
images = get_irregular_images
|
113
|
+
expected = [
|
114
|
+
{ :cssx => 10, :cssy => 20, :cssw => 20, :cssh => 50, :x => 10, :y => 20 },
|
115
|
+
{ :cssx => 50, :cssy => 25, :cssw => 40, :cssh => 40, :x => 50, :y => 25 },
|
116
|
+
{ :cssx => 110, :cssy => 30, :cssw => 60, :cssh => 30, :x => 110, :y => 30 },
|
117
|
+
{ :cssx => 190, :cssy => 35, :cssw => 80, :cssh => 20, :x => 190, :y => 35 },
|
118
|
+
{ :cssx => 290, :cssy => 40, :cssw => 100, :cssh => 10, :x => 290, :y => 40 }
|
119
|
+
]
|
120
|
+
verify_layout(400, 90, expected, images, :layout => :horizontal, :hmargin => 10, :vmargin => 20)
|
121
|
+
end
|
122
|
+
|
123
|
+
#--------------------------------------------------------------------------
|
124
|
+
|
125
|
+
def test_padded_and_margin_horizontal_layout_of_irregular_images
|
126
|
+
images = get_irregular_images
|
127
|
+
expected = [
|
128
|
+
{ :cssx => 10, :cssy => 20, :cssw => 24, :cssh => 58, :x => 12, :y => 24 },
|
129
|
+
{ :cssx => 54, :cssy => 25, :cssw => 44, :cssh => 48, :x => 56, :y => 29 },
|
130
|
+
{ :cssx => 118, :cssy => 30, :cssw => 64, :cssh => 38, :x => 120, :y => 34 },
|
131
|
+
{ :cssx => 202, :cssy => 35, :cssw => 84, :cssh => 28, :x => 204, :y => 39 },
|
132
|
+
{ :cssx => 306, :cssy => 40, :cssw => 104, :cssh => 18, :x => 308, :y => 44 }
|
133
|
+
]
|
134
|
+
verify_layout(420, 98, expected, images, :layout => :horizontal, :hmargin => 10, :vmargin => 20, :hpadding => 2, :vpadding => 4)
|
135
|
+
end
|
136
|
+
|
137
|
+
#--------------------------------------------------------------------------
|
138
|
+
|
83
139
|
def test_fixed_horizontal_layout_of_irregular_images
|
84
140
|
images = get_irregular_images
|
85
141
|
expected = [
|
data/test/layout/packed_test.rb
CHANGED
@@ -10,22 +10,48 @@ module SpriteFactory
|
|
10
10
|
|
11
11
|
def test_packed_layout_of_regular_images
|
12
12
|
images = get_regular_images
|
13
|
-
expected = [
|
14
|
-
{ :x => 0, :y => 0 },
|
15
|
-
{ :x => 0, :y => 10 },
|
16
|
-
{ :x => 20, :y => 0 },
|
17
|
-
{ :x => 20, :y => 10 },
|
18
|
-
{ :x => 0, :y => 20 }
|
19
|
-
]
|
13
|
+
expected = [ # expected: -------
|
14
|
+
{ :cssx => 0, :cssy => 0, :cssw => 20, :cssh => 10, :x => 0, :y => 0 }, # |11|33|
|
15
|
+
{ :cssx => 0, :cssy => 10, :cssw => 20, :cssh => 10, :x => 0, :y => 10 }, # -------
|
16
|
+
{ :cssx => 20, :cssy => 0, :cssw => 20, :cssh => 10, :x => 20, :y => 0 }, # |22|44|
|
17
|
+
{ :cssx => 20, :cssy => 10, :cssw => 20, :cssh => 10, :x => 20, :y => 10 }, # -------
|
18
|
+
{ :cssx => 0, :cssy => 20, :cssw => 20, :cssh => 10, :x => 0, :y => 20 } # |55| |
|
19
|
+
] # -------
|
20
20
|
verify_layout(40, 30, expected, images, :layout => :packed)
|
21
21
|
end
|
22
22
|
|
23
23
|
#--------------------------------------------------------------------------
|
24
24
|
|
25
|
-
def test_padded_packed_layout_of_regular_images
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
def test_padded_packed_layout_of_regular_images # expected: ---------------
|
26
|
+
# | | |
|
27
|
+
images = get_regular_images # | 11 | 33 |
|
28
|
+
expected = [ # | | |
|
29
|
+
{ :cssx => 0, :cssy => 0, :cssw => 60, :cssh => 30, :x => 20, :y => 10 }, # ---------------
|
30
|
+
{ :cssx => 0, :cssy => 30, :cssw => 60, :cssh => 30, :x => 20, :y => 40 }, # | | |
|
31
|
+
{ :cssx => 60, :cssy => 0, :cssw => 60, :cssh => 30, :x => 80, :y => 10 }, # | 22 | 44 |
|
32
|
+
{ :cssx => 60, :cssy => 30, :cssw => 60, :cssh => 30, :x => 80, :y => 40 }, # | | |
|
33
|
+
{ :cssx => 0, :cssy => 60, :cssw => 60, :cssh => 30, :x => 20, :y => 70 } # ---------------
|
34
|
+
] # | |
|
35
|
+
verify_layout(120, 90, expected, images, :layout => :packed, # | 55 |
|
36
|
+
:hpadding => 20, # | |
|
37
|
+
:vpadding => 10) # --------
|
38
|
+
end
|
39
|
+
|
40
|
+
#--------------------------------------------------------------------------
|
41
|
+
|
42
|
+
def test_margin_packed_layout_of_regular_images # expected: ---------------
|
43
|
+
# | | |
|
44
|
+
images = get_regular_images # | 11 | 33 |
|
45
|
+
expected = [ # | | |
|
46
|
+
{ :cssx => 20, :cssy => 10, :cssw => 20, :cssh => 10, :x => 20, :y => 10 }, # ---------------
|
47
|
+
{ :cssx => 20, :cssy => 40, :cssw => 20, :cssh => 10, :x => 20, :y => 40 }, # | | |
|
48
|
+
{ :cssx => 80, :cssy => 10, :cssw => 20, :cssh => 10, :x => 80, :y => 10 }, # | 22 | 44 |
|
49
|
+
{ :cssx => 80, :cssy => 40, :cssw => 20, :cssh => 10, :x => 80, :y => 40 }, # | | |
|
50
|
+
{ :cssx => 20, :cssy => 70, :cssw => 20, :cssh => 10, :x => 20, :y => 70 } # ---------------
|
51
|
+
] # | |
|
52
|
+
verify_layout(120, 90, expected, images, :layout => :packed, # | 55 |
|
53
|
+
:hmargin => 20, # | |
|
54
|
+
:vmargin => 10) # --------
|
29
55
|
end
|
30
56
|
|
31
57
|
#--------------------------------------------------------------------------
|
@@ -42,18 +68,54 @@ module SpriteFactory
|
|
42
68
|
|
43
69
|
def test_packed_layout_of_irregular_images
|
44
70
|
images = get_irregular_images
|
45
|
-
|
46
|
-
expected = [
|
47
|
-
{ :x => 0, :y => 0 },
|
48
|
-
{ :x => 0, :y => 10 },
|
49
|
-
{ :x => 0, :y => 30 },
|
50
|
-
{ :x => 100, :y => 0 },
|
51
|
-
{ :x => 0, :y => 60 }
|
52
|
-
]
|
53
|
-
|
71
|
+
# expected: ---------------
|
72
|
+
expected = [ # |1111111111|44|
|
73
|
+
{ :cssx => 0, :cssy => 0, :cssw => 100, :cssh => 10, :x => 0, :y => 0 }, # -----------|44|
|
74
|
+
{ :cssx => 0, :cssy => 10, :cssw => 80, :cssh => 20, :x => 0, :y => 10 }, # |22222222| |44|
|
75
|
+
{ :cssx => 0, :cssy => 30, :cssw => 60, :cssh => 30, :x => 0, :y => 30 }, # -----------|44|
|
76
|
+
{ :cssx => 100, :cssy => 0, :cssw => 20, :cssh => 50, :x => 100, :y => 0 }, # |333333| ----
|
77
|
+
{ :cssx => 0, :cssy => 60, :cssw => 40, :cssh => 40, :x => 0, :y => 60 } # ---------------
|
78
|
+
] # |5555| |
|
79
|
+
# ---------------
|
54
80
|
verify_layout(120, 100, expected, images, :layout => :packed)
|
55
81
|
end
|
56
82
|
|
83
|
+
#--------------------------------------------------------------------------
|
84
|
+
|
85
|
+
def test_padded_packed_layout_of_irregular_images # expected: (but with more vertical padding than shown here)
|
86
|
+
images = get_irregular_images #
|
87
|
+
# -------------------------
|
88
|
+
expected = [ # | 1111111111 | 4444 |
|
89
|
+
{ :cssx => 0, :cssy => 0, :cssw => 140, :cssh => 30, :x => 20, :y => 10 }, # ---------------- 4444 |
|
90
|
+
{ :cssx => 0, :cssy => 30, :cssw => 120, :cssh => 40, :x => 20, :y => 40 }, # | 22222222 | ----------
|
91
|
+
{ :cssx => 0, :cssy => 70, :cssw => 100, :cssh => 50, :x => 20, :y => 80 }, # -------------- |
|
92
|
+
{ :cssx => 140, :cssy => 0, :cssw => 80, :cssh => 60, :x => 160, :y => 10 }, # | 333333 | |
|
93
|
+
{ :cssx => 0, :cssy => 120, :cssw => 60, :cssh => 70, :x => 20, :y => 130 } # |----------- |
|
94
|
+
] # | 55 | |
|
95
|
+
# -------------------------
|
96
|
+
verify_layout(220, 190, expected, images, :layout => :packed, #
|
97
|
+
:hpadding => 20, #
|
98
|
+
:vpadding => 10) #
|
99
|
+
end
|
100
|
+
|
101
|
+
#--------------------------------------------------------------------------
|
102
|
+
|
103
|
+
def test_margin_packed_layout_of_irregular_images # expected: (but with more vertical margin than shown here)
|
104
|
+
images = get_irregular_images #
|
105
|
+
# -------------------------
|
106
|
+
expected = [ # | 1111111111 | 4444 |
|
107
|
+
{ :cssx => 20, :cssy => 10, :cssw => 100, :cssh => 10, :x => 20, :y => 10 }, # ---------------- 4444 |
|
108
|
+
{ :cssx => 20, :cssy => 40, :cssw => 80, :cssh => 20, :x => 20, :y => 40 }, # | 22222222 | ----------
|
109
|
+
{ :cssx => 20, :cssy => 80, :cssw => 60, :cssh => 30, :x => 20, :y => 80 }, # -------------- |
|
110
|
+
{ :cssx => 160, :cssy => 10, :cssw => 40, :cssh => 40, :x => 160, :y => 10 }, # | 333333 | |
|
111
|
+
{ :cssx => 20, :cssy => 130, :cssw => 20, :cssh => 50, :x => 20, :y => 130 } # |----------- |
|
112
|
+
] # | 55 | |
|
113
|
+
# -------------------------
|
114
|
+
verify_layout(220, 190, expected, images, :layout => :packed, #
|
115
|
+
:hmargin => 20, #
|
116
|
+
:vmargin => 10) #
|
117
|
+
end
|
118
|
+
|
57
119
|
#==========================================================================
|
58
120
|
# other packed algorithm test
|
59
121
|
#==========================================================================
|
@@ -36,6 +36,34 @@ module SpriteFactory
|
|
36
36
|
|
37
37
|
#--------------------------------------------------------------------------
|
38
38
|
|
39
|
+
def test_margin_vertical_layout_of_regular_images
|
40
|
+
images = get_regular_images
|
41
|
+
expected = [
|
42
|
+
{ :cssx => 10, :cssy => 20, :cssw => 20, :cssh => 10, :x => 10, :y => 20 },
|
43
|
+
{ :cssx => 10, :cssy => 70, :cssw => 20, :cssh => 10, :x => 10, :y => 70 },
|
44
|
+
{ :cssx => 10, :cssy => 120, :cssw => 20, :cssh => 10, :x => 10, :y => 120 },
|
45
|
+
{ :cssx => 10, :cssy => 170, :cssw => 20, :cssh => 10, :x => 10, :y => 170 },
|
46
|
+
{ :cssx => 10, :cssy => 220, :cssw => 20, :cssh => 10, :x => 10, :y => 220 }
|
47
|
+
]
|
48
|
+
verify_layout(40, 250, expected, images, :layout => :vertical, :hmargin => 10, :vmargin => 20)
|
49
|
+
end
|
50
|
+
|
51
|
+
#--------------------------------------------------------------------------
|
52
|
+
|
53
|
+
def test_padded_and_margin_vertical_layout_of_regular_images
|
54
|
+
images = get_regular_images
|
55
|
+
expected = [
|
56
|
+
{ :cssx => 10, :cssy => 20, :cssw => 24, :cssh => 18, :x => 12, :y => 24 },
|
57
|
+
{ :cssx => 10, :cssy => 78, :cssw => 24, :cssh => 18, :x => 12, :y => 82 },
|
58
|
+
{ :cssx => 10, :cssy => 136, :cssw => 24, :cssh => 18, :x => 12, :y => 140 },
|
59
|
+
{ :cssx => 10, :cssy => 194, :cssw => 24, :cssh => 18, :x => 12, :y => 198 },
|
60
|
+
{ :cssx => 10, :cssy => 252, :cssw => 24, :cssh => 18, :x => 12, :y => 256 }
|
61
|
+
]
|
62
|
+
verify_layout(44, 290, expected, images, :layout => :vertical, :hmargin => 10, :vmargin => 20, :hpadding => 2, :vpadding => 4)
|
63
|
+
end
|
64
|
+
|
65
|
+
#--------------------------------------------------------------------------
|
66
|
+
|
39
67
|
def test_fixed_vertical_layout_of_regular_images
|
40
68
|
images = get_regular_images
|
41
69
|
expected = [
|
@@ -80,6 +108,34 @@ module SpriteFactory
|
|
80
108
|
|
81
109
|
#--------------------------------------------------------------------------
|
82
110
|
|
111
|
+
def test_margin_vertical_layout_of_irregular_images
|
112
|
+
images = get_irregular_images
|
113
|
+
expected = [
|
114
|
+
{ :cssx => 50, :cssy => 20, :cssw => 20, :cssh => 50, :x => 50, :y => 20 },
|
115
|
+
{ :cssx => 40, :cssy => 110, :cssw => 40, :cssh => 40, :x => 40, :y => 110 },
|
116
|
+
{ :cssx => 30, :cssy => 190, :cssw => 60, :cssh => 30, :x => 30, :y => 190 },
|
117
|
+
{ :cssx => 20, :cssy => 260, :cssw => 80, :cssh => 20, :x => 20, :y => 260 },
|
118
|
+
{ :cssx => 10, :cssy => 320, :cssw => 100, :cssh => 10, :x => 10, :y => 320 }
|
119
|
+
]
|
120
|
+
verify_layout(120, 350, expected, images, :layout => :vertical, :hmargin => 10, :vmargin => 20)
|
121
|
+
end
|
122
|
+
|
123
|
+
#--------------------------------------------------------------------------
|
124
|
+
|
125
|
+
def test_padded_and_margin_vertical_layout_of_irregular_images
|
126
|
+
images = get_irregular_images
|
127
|
+
expected = [
|
128
|
+
{ :cssx => 50, :cssy => 20, :cssw => 24, :cssh => 58, :x => 52, :y => 24 },
|
129
|
+
{ :cssx => 40, :cssy => 118, :cssw => 44, :cssh => 48, :x => 42, :y => 122 },
|
130
|
+
{ :cssx => 30, :cssy => 206, :cssw => 64, :cssh => 38, :x => 32, :y => 210 },
|
131
|
+
{ :cssx => 20, :cssy => 284, :cssw => 84, :cssh => 28, :x => 22, :y => 288 },
|
132
|
+
{ :cssx => 10, :cssy => 352, :cssw => 104, :cssh => 18, :x => 12, :y => 356 }
|
133
|
+
]
|
134
|
+
verify_layout(124, 390, expected, images, :layout => :vertical, :hmargin => 10, :vmargin => 20, :hpadding => 2, :vpadding => 4)
|
135
|
+
end
|
136
|
+
|
137
|
+
#--------------------------------------------------------------------------
|
138
|
+
|
83
139
|
def test_fixed_vertical_layout_of_irregular_images
|
84
140
|
images = get_irregular_images
|
85
141
|
expected = [
|
data/test/runner_test.rb
CHANGED
@@ -81,6 +81,22 @@ module SpriteFactory
|
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
|
+
def test_default_margin
|
85
|
+
Runner.publicize_methods do
|
86
|
+
r = Runner.new(REGULAR_PATH)
|
87
|
+
assert_equal(0, r.hmargin)
|
88
|
+
assert_equal(0, r.vmargin)
|
89
|
+
|
90
|
+
r = Runner.new(REGULAR_PATH, :margin => 10)
|
91
|
+
assert_equal(10, r.hmargin)
|
92
|
+
assert_equal(10, r.vmargin)
|
93
|
+
|
94
|
+
r = Runner.new(REGULAR_PATH, :hmargin => 10, :vmargin => 20)
|
95
|
+
assert_equal(10, r.hmargin)
|
96
|
+
assert_equal(20, r.vmargin)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
84
100
|
#----------------------------------------------------------------------------
|
85
101
|
|
86
102
|
def test_default_css_path
|
@@ -150,6 +166,14 @@ module SpriteFactory
|
|
150
166
|
SpriteFactory.run!(REGULAR_PATH, :height => 50, :padding => 10)
|
151
167
|
end
|
152
168
|
|
169
|
+
assert_runtime_error "set :width for fixed width, or :hmargin for horizontal margin, but not both." do
|
170
|
+
SpriteFactory.run!(REGULAR_PATH, :width => 50, :margin => 10)
|
171
|
+
end
|
172
|
+
|
173
|
+
assert_runtime_error "set :height for fixed height, or :vmargin for vertical margin, but not both." do
|
174
|
+
SpriteFactory.run!(REGULAR_PATH, :height => 50, :margin => 10)
|
175
|
+
end
|
176
|
+
|
153
177
|
assert_runtime_error "image regular1 does not fit within a fixed width of 10" do
|
154
178
|
SpriteFactory.run!(REGULAR_PATH, :width => 10)
|
155
179
|
end
|
data/test/test_case.rb
CHANGED
@@ -15,6 +15,7 @@ module SpriteFactory
|
|
15
15
|
FORMATS_PATH = 'test/images/formats'
|
16
16
|
EMPTY_PATH = 'test/images/empty'
|
17
17
|
SUBFOLDERS_PATH = 'test/images/subfolders'
|
18
|
+
HOVER_PATH = 'test/images/hover'
|
18
19
|
|
19
20
|
REGULAR = SpriteFactory.find_files(File.join(REGULAR_PATH, '*.png'))
|
20
21
|
IRREGULAR = SpriteFactory.find_files(File.join(IRREGULAR_PATH, '*.png'))
|
metadata
CHANGED
@@ -1,48 +1,58 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: sprite-factory
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 5
|
8
|
+
- 0
|
9
|
+
version: 1.5.0
|
6
10
|
platform: ruby
|
7
|
-
authors:
|
11
|
+
authors:
|
8
12
|
- Jake Gordon
|
9
13
|
autorequire:
|
10
14
|
bindir: bin
|
11
15
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
16
|
+
|
17
|
+
date: 2012-05-10 00:00:00 -07:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
15
21
|
name: rmagick
|
16
|
-
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
17
24
|
none: false
|
18
|
-
requirements:
|
19
|
-
- -
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
22
31
|
type: :development
|
23
|
-
|
24
|
-
|
25
|
-
- !ruby/object:Gem::Dependency
|
32
|
+
version_requirements: *id001
|
33
|
+
- !ruby/object:Gem::Dependency
|
26
34
|
name: chunky_png
|
27
|
-
|
35
|
+
prerelease: false
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
28
37
|
none: false
|
29
|
-
requirements:
|
30
|
-
- -
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
version: "0"
|
33
44
|
type: :development
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
file and creates an appropriate CSS stylesheet
|
38
|
-
email:
|
45
|
+
version_requirements: *id002
|
46
|
+
description: Combines individual images from a directory into a single sprite image file and creates an appropriate CSS stylesheet
|
47
|
+
email:
|
39
48
|
- jake@codeincomplete.com
|
40
|
-
executables:
|
49
|
+
executables:
|
41
50
|
- sf
|
42
51
|
extensions: []
|
43
|
-
|
52
|
+
|
53
|
+
extra_rdoc_files:
|
44
54
|
- README.md
|
45
|
-
files:
|
55
|
+
files:
|
46
56
|
- .gitignore
|
47
57
|
- LICENSE
|
48
58
|
- README.md
|
@@ -66,6 +76,10 @@ files:
|
|
66
76
|
- test/images/formats/monkey.gif
|
67
77
|
- test/images/formats/spies.jpg
|
68
78
|
- test/images/formats/thief.png
|
79
|
+
- test/images/hover/div.bar__img.icon--hover.png
|
80
|
+
- test/images/hover/div.bar__img.icon.png
|
81
|
+
- test/images/hover/div.foo__img.icon--hover.png
|
82
|
+
- test/images/hover/div.foo__img.icon.png
|
69
83
|
- test/images/irregular/irregular1.png
|
70
84
|
- test/images/irregular/irregular2.png
|
71
85
|
- test/images/irregular/irregular3.png
|
@@ -76,12 +90,16 @@ files:
|
|
76
90
|
- test/images/reference/custom.png
|
77
91
|
- test/images/reference/formats.css
|
78
92
|
- test/images/reference/formats.png
|
93
|
+
- test/images/reference/hover.css
|
94
|
+
- test/images/reference/hover.png
|
79
95
|
- test/images/reference/index.html
|
80
96
|
- test/images/reference/irregular.css
|
81
97
|
- test/images/reference/irregular.fixed.css
|
82
98
|
- test/images/reference/irregular.fixed.png
|
83
99
|
- test/images/reference/irregular.horizontal.css
|
84
100
|
- test/images/reference/irregular.horizontal.png
|
101
|
+
- test/images/reference/irregular.margin.css
|
102
|
+
- test/images/reference/irregular.margin.png
|
85
103
|
- test/images/reference/irregular.packed.css
|
86
104
|
- test/images/reference/irregular.packed.png
|
87
105
|
- test/images/reference/irregular.padded.css
|
@@ -99,6 +117,8 @@ files:
|
|
99
117
|
- test/images/reference/regular.fixed.png
|
100
118
|
- test/images/reference/regular.horizontal.css
|
101
119
|
- test/images/reference/regular.horizontal.png
|
120
|
+
- test/images/reference/regular.margin.css
|
121
|
+
- test/images/reference/regular.margin.png
|
102
122
|
- test/images/reference/regular.nocomments.css
|
103
123
|
- test/images/reference/regular.nocomments.png
|
104
124
|
- test/images/reference/regular.packed.css
|
@@ -133,29 +153,37 @@ files:
|
|
133
153
|
- test/runner_test.rb
|
134
154
|
- test/style_test.rb
|
135
155
|
- test/test_case.rb
|
156
|
+
has_rdoc: true
|
136
157
|
homepage: https://github.com/jakesgordon/sprite-factory
|
137
158
|
licenses: []
|
159
|
+
|
138
160
|
post_install_message:
|
139
|
-
rdoc_options:
|
161
|
+
rdoc_options:
|
140
162
|
- --charset=UTF-8
|
141
|
-
require_paths:
|
163
|
+
require_paths:
|
142
164
|
- lib
|
143
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
165
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
144
166
|
none: false
|
145
|
-
requirements:
|
146
|
-
- -
|
147
|
-
- !ruby/object:Gem::Version
|
148
|
-
|
149
|
-
|
167
|
+
requirements:
|
168
|
+
- - ">="
|
169
|
+
- !ruby/object:Gem::Version
|
170
|
+
segments:
|
171
|
+
- 0
|
172
|
+
version: "0"
|
173
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
150
174
|
none: false
|
151
|
-
requirements:
|
152
|
-
- -
|
153
|
-
- !ruby/object:Gem::Version
|
154
|
-
|
175
|
+
requirements:
|
176
|
+
- - ">="
|
177
|
+
- !ruby/object:Gem::Version
|
178
|
+
segments:
|
179
|
+
- 0
|
180
|
+
version: "0"
|
155
181
|
requirements: []
|
182
|
+
|
156
183
|
rubyforge_project:
|
157
|
-
rubygems_version: 1.
|
184
|
+
rubygems_version: 1.3.7
|
158
185
|
signing_key:
|
159
186
|
specification_version: 3
|
160
187
|
summary: Automatic CSS sprite generator
|
161
188
|
test_files: []
|
189
|
+
|