sprite-factory 1.4.1 → 1.4.2

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.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- Sprite Factory (v1.4.1)
1
+ Sprite Factory (v1.4.2)
2
2
  =======================
3
3
 
4
4
  The sprite factory is a ruby library that can be used to generate
@@ -54,11 +54,18 @@ You can also use the SpriteFactory class directly from your own code:
54
54
 
55
55
  SpriteFactory.run!('images/icons')
56
56
 
57
- The original image name is used for the CSS class to show that image in HTML:
57
+ The original image file name is used for the CSS class to show that image in HTML:
58
58
 
59
- <img src='s.gif' class='high'>
60
- <img src='s.gif' class='medium'>
61
- <img src='s.gif' class='low'>
59
+ <img src='s.gif' class='high'> # e.g. original image was high.png
60
+ <img src='s.gif' class='medium'> # e.g. original image was medium.png
61
+ <img src='s.gif' class='low'> # e.g. original image was low.png
62
+
63
+ If original image files are included in sub-folders, the relative path
64
+ name will be used for the CSS class to show that image in HTML:
65
+
66
+ <img src='s.gif' class='other_high'> # e.g. original image was other/high.png
67
+ <img src='s.gif' class='other_medium'> # e.g. original image was other/medium.png
68
+ <img src='s.gif' class='other_low'> # e.g. original image was other/low.png
62
69
 
63
70
  When using a framework such as Rails, you would usually DRY this up with a helper method:
64
71
 
@@ -87,7 +94,8 @@ Much of the behavior can be customized by overriding the following options:
87
94
  - `:padding` - add padding to each sprite
88
95
  - `:width` - fix width of each sprite to a specific size
89
96
  - `:height` - fix height of each sprite to a specific size
90
- - `:nocss` - suppress generation of output style file (`run!` returns css content as a string instead)
97
+ - `:nocss` - suppress generation of output stylesheet (`run!` returns css content as a string instead)
98
+ - `:nocomments` - suppress generation of comments in output stylesheet
91
99
 
92
100
  Options can be passed as command line arguments to the `sf` script:
93
101
 
@@ -1,4 +1,9 @@
1
1
 
2
+ UNRELEASED - v1.4.2
3
+ -------------------
4
+ * added support for `:nocomments => true` to suppress comments in generated output stylesheet
5
+ * added support for images in subfolders - fixes [github issue #11](https://github.com/jakesgordon/sprite-factory/issues/11)
6
+
2
7
  August 5th 2011 - v1.4.1
3
8
  ------------------------
4
9
  * added support for `:style => :scss` to generate .scss file (even though content will be almost exactly same as .css style)
data/bin/sf CHANGED
@@ -27,6 +27,7 @@ csspath_help = "specify custom path to use for css image urls ( default: ou
27
27
  output_image_help = "specify output location for generated image ( default: <input folder>.png )"
28
28
  output_style_help = "specify output location for generated stylesheet ( default: <input folder>.<style>)"
29
29
  pngcrush_help = "use pngcrush to optimize generated image"
30
+ nocomments_help = "suppress comments in generated stylesheet"
30
31
 
31
32
  op.on("--layout [ORIENTATION]", layout_help) {|value| options[:layout] = value }
32
33
  op.on("--style [STYLE]", style_help) {|value| options[:style] = value }
@@ -36,6 +37,7 @@ op.on("--csspath [CSSPATH]", csspath_help) {|value| options[:csspa
36
37
  op.on("--output-image [PATH]", output_image_help) {|value| options[:output_image] = value }
37
38
  op.on("--output-style [PATH]", output_style_help) {|value| options[:output_style] = value }
38
39
  op.on("--pngcrush", pngcrush_help) {|value| options[:pngcrush] = value }
40
+ op.on("--nocomments", nocomments_help) {|value| options[:nocomments] = true }
39
41
 
40
42
  begin
41
43
  op.parse!(ARGV)
@@ -2,7 +2,7 @@ module SpriteFactory
2
2
 
3
3
  #----------------------------------------------------------------------------
4
4
 
5
- VERSION = "1.4.1"
5
+ VERSION = "1.4.2"
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__)
@@ -26,6 +26,7 @@ module SpriteFactory
26
26
  attr_accessor :selector
27
27
  attr_accessor :csspath
28
28
  attr_accessor :pngcrush
29
+ attr_accessor :nocomments
29
30
  end
30
31
 
31
32
  #----------------------------------------------------------------------------
@@ -12,13 +12,14 @@ module SpriteFactory
12
12
  def initialize(input, config = {})
13
13
  @input = input.to_s[-1] == "/" ? input[0...-1] : input # gracefully ignore trailing slash on input directory name
14
14
  @config = config
15
- @config[:style] ||= SpriteFactory.style || :css
16
- @config[:layout] ||= SpriteFactory.layout || :horizontal
17
- @config[:library] ||= SpriteFactory.library || :rmagick
18
- @config[:selector] ||= SpriteFactory.selector || 'img.'
19
- @config[:csspath] ||= SpriteFactory.csspath
20
- @config[:report] ||= SpriteFactory.report
21
- @config[:pngcrush] ||= SpriteFactory.pngcrush
15
+ @config[:style] ||= SpriteFactory.style || :css
16
+ @config[:layout] ||= SpriteFactory.layout || :horizontal
17
+ @config[:library] ||= SpriteFactory.library || :rmagick
18
+ @config[:selector] ||= SpriteFactory.selector || 'img.'
19
+ @config[:csspath] ||= SpriteFactory.csspath
20
+ @config[:report] ||= SpriteFactory.report
21
+ @config[:pngcrush] ||= SpriteFactory.pngcrush
22
+ @config[:nocomments] ||= SpriteFactory.nocomments
22
23
  end
23
24
 
24
25
  #----------------------------------------------------------------------------
@@ -45,7 +46,7 @@ module SpriteFactory
45
46
  report(header)
46
47
 
47
48
  css = []
48
- css << style_comment(header) # header comment
49
+ css << style_comment(header) unless nocomments? # header comment
49
50
  css << style(selector, css_path, images, &block) # generated styles
50
51
  css << IO.read(custom_style_file) if File.exists?(custom_style_file) # custom styles
51
52
  css = css.join("\n")
@@ -114,6 +115,10 @@ module SpriteFactory
114
115
  config[:nocss] # set true if you dont want an output style file generated (e.g. you will take the #run! output and store it yourself)
115
116
  end
116
117
 
118
+ def nocomments?
119
+ config[:nocomments] # set true if you dont want any comments in the output style file
120
+ end
121
+
117
122
  def custom_style_file
118
123
  File.join(input, File.basename(input) + ".#{style_name}")
119
124
  end
@@ -148,9 +153,10 @@ module SpriteFactory
148
153
  end
149
154
 
150
155
  def load_images
156
+ input_path = Pathname.new(input)
151
157
  images = library.load(image_files)
152
158
  images.each do |i|
153
- i[:name] = File.basename(i[:filename])
159
+ i[:name] = Pathname.new(i[:filename]).relative_path_from(input_path).to_s.gsub(File::SEPARATOR, "_")
154
160
  i[:ext] = File.extname(i[:name])
155
161
  i[:name] = i[:name][0...-i[:ext].length] unless i[:ext].empty?
156
162
 
@@ -192,7 +198,7 @@ module SpriteFactory
192
198
 
193
199
  #----------------------------------------------------------------------------
194
200
 
195
- SUPPORTS_PNGCRUSH = !`which pngcrush`.empty?
201
+ SUPPORTS_PNGCRUSH = !`which pngcrush`.empty? rescue false # rescue on environments without `which` (windows)
196
202
 
197
203
  def pngcrush(image)
198
204
  if SUPPORTS_PNGCRUSH && config[:pngcrush]
@@ -26,7 +26,7 @@ module SpriteFactory
26
26
  end
27
27
 
28
28
  def self.scss_comment(comment)
29
- css_comment(attributes)
29
+ css_comment(comment)
30
30
  end
31
31
 
32
32
  #----------------------------------------------------------------------------
@@ -19,6 +19,7 @@
19
19
  <link href='irregular.sassy.css' rel='stylesheet' type='text/css' media='screen'></link>
20
20
  <link href='custom.css' rel='stylesheet' type='text/css' media='screen'></link>
21
21
  <link href='formats.css' rel='stylesheet' type='text/css' media='screen'></link>
22
+ <link href='subfolders.css' rel='stylesheet' type='text/css' media='screen'></link>
22
23
  <style>
23
24
  img { border: 1px solid red; }
24
25
  </style>
@@ -136,6 +137,13 @@
136
137
  <img src='s.gif' class='spies'>
137
138
  <img src='s.gif' class='thief'>
138
139
 
140
+ <h1>From Sub Folders</h1>
141
+ <img src='s.gif' class='england_amy'>
142
+ <img src='s.gif' class='england_bob'>
143
+ <img src='s.gif' class='france_bob'>
144
+ <img src='s.gif' class='usa_amy'>
145
+ <img src='s.gif' class='usa_bob'>
146
+
139
147
  <script>
140
148
  SpriteFactory = {
141
149
  toggleTimer: function() {
@@ -0,0 +1,5 @@
1
+ img.nocomments_regular1 { width: 64px; height: 64px; background: url(regular.nocomments.png) 0px 0px no-repeat; }
2
+ img.nocomments_regular2 { width: 64px; height: 64px; background: url(regular.nocomments.png) -64px 0px no-repeat; }
3
+ img.nocomments_regular3 { width: 64px; height: 64px; background: url(regular.nocomments.png) -128px 0px no-repeat; }
4
+ img.nocomments_regular4 { width: 64px; height: 64px; background: url(regular.nocomments.png) -192px 0px no-repeat; }
5
+ img.nocomments_regular5 { width: 64px; height: 64px; background: url(regular.nocomments.png) -256px 0px no-repeat; }
@@ -0,0 +1,24 @@
1
+ /*
2
+
3
+ Creating a sprite from following images:
4
+
5
+ test/images/subfolders/england/amy.png (64x64)
6
+ test/images/subfolders/england/bob.png (64x64)
7
+ test/images/subfolders/france/bob.png (64x64)
8
+ test/images/subfolders/usa/amy.png (64x64)
9
+ test/images/subfolders/usa/bob.png (64x64)
10
+
11
+ Output files:
12
+ test/images/subfolders.png
13
+ test/images/subfolders.css
14
+
15
+ Output size:
16
+ 320x64
17
+
18
+
19
+ */
20
+ img.england_amy { width: 64px; height: 64px; background: url(subfolders.png) 0px 0px no-repeat; }
21
+ img.england_bob { width: 64px; height: 64px; background: url(subfolders.png) -64px 0px no-repeat; }
22
+ img.france_bob { width: 64px; height: 64px; background: url(subfolders.png) -128px 0px no-repeat; }
23
+ img.usa_amy { width: 64px; height: 64px; background: url(subfolders.png) -192px 0px no-repeat; }
24
+ img.usa_bob { width: 64px; height: 64px; background: url(subfolders.png) -256px 0px no-repeat; }
@@ -46,6 +46,12 @@ module SpriteFactory
46
46
  :style => :sass)
47
47
  end
48
48
 
49
+ def test_generate_regular_with_nocomments
50
+ integration_test(REGULAR_PATH, :output => output_path('regular.nocomments'),
51
+ :selector => 'img.nocomments_',
52
+ :nocomments => true)
53
+ end
54
+
49
55
  #----------------------------------------------------------------------------
50
56
 
51
57
  def test_generate_irregular_sprite
@@ -108,6 +114,12 @@ module SpriteFactory
108
114
 
109
115
  #----------------------------------------------------------------------------
110
116
 
117
+ def test_generate_sprite_using_images_in_subfolders
118
+ integration_test(SUBFOLDERS_PATH)
119
+ end
120
+
121
+ #----------------------------------------------------------------------------
122
+
111
123
  def test_generate_sprite_with_nocss
112
124
  input = REGULAR_PATH
113
125
  output = File.basename(REGULAR_PATH)
@@ -8,12 +8,13 @@ module SpriteFactory
8
8
 
9
9
  IMAGES_PATH = 'test/images'
10
10
 
11
- REFERENCE_PATH = 'test/images/reference'
12
- REGULAR_PATH = 'test/images/regular'
13
- IRREGULAR_PATH = 'test/images/irregular'
14
- CUSTOM_PATH = 'test/images/custom'
15
- FORMATS_PATH = 'test/images/formats'
16
- EMPTY_PATH = 'test/images/empty'
11
+ REFERENCE_PATH = 'test/images/reference'
12
+ REGULAR_PATH = 'test/images/regular'
13
+ IRREGULAR_PATH = 'test/images/irregular'
14
+ CUSTOM_PATH = 'test/images/custom'
15
+ FORMATS_PATH = 'test/images/formats'
16
+ EMPTY_PATH = 'test/images/empty'
17
+ SUBFOLDERS_PATH = 'test/images/subfolders'
17
18
 
18
19
  REGULAR = SpriteFactory.find_files(File.join(REGULAR_PATH, '*.png'))
19
20
  IRREGULAR = SpriteFactory.find_files(File.join(IRREGULAR_PATH, '*.png'))
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sprite-factory
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.4.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-06 00:00:00.000000000Z
12
+ date: 2012-02-29 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rmagick
16
- requirement: &12869300 !ruby/object:Gem::Requirement
16
+ requirement: &20623420 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *12869300
24
+ version_requirements: *20623420
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: chunky_png
27
- requirement: &12901920 !ruby/object:Gem::Requirement
27
+ requirement: &20623000 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *12901920
35
+ version_requirements: *20623000
36
36
  description: Combines individual images from a directory into a single sprite image
37
37
  file and creates an appropriate CSS stylesheet
38
38
  email:
@@ -99,6 +99,8 @@ files:
99
99
  - test/images/reference/regular.fixed.png
100
100
  - test/images/reference/regular.horizontal.css
101
101
  - test/images/reference/regular.horizontal.png
102
+ - test/images/reference/regular.nocomments.css
103
+ - test/images/reference/regular.nocomments.png
102
104
  - test/images/reference/regular.packed.css
103
105
  - test/images/reference/regular.packed.png
104
106
  - test/images/reference/regular.padded.css
@@ -110,11 +112,18 @@ files:
110
112
  - test/images/reference/regular.vertical.css
111
113
  - test/images/reference/regular.vertical.png
112
114
  - test/images/reference/s.gif
115
+ - test/images/reference/subfolders.css
116
+ - test/images/reference/subfolders.png
113
117
  - test/images/regular/regular1.PNG
114
118
  - test/images/regular/regular2.PNG
115
119
  - test/images/regular/regular3.PNG
116
120
  - test/images/regular/regular4.PNG
117
121
  - test/images/regular/regular5.PNG
122
+ - test/images/subfolders/england/amy.png
123
+ - test/images/subfolders/england/bob.png
124
+ - test/images/subfolders/france/bob.png
125
+ - test/images/subfolders/usa/amy.png
126
+ - test/images/subfolders/usa/bob.png
118
127
  - test/integration_test.rb
119
128
  - test/layout/horizontal_test.rb
120
129
  - test/layout/packed_test.rb