sprite-factory-custom 1.6.1 → 1.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/sf +2 -0
- data/lib/sprite_factory.rb +2 -2
- data/lib/sprite_factory/runner.rb +23 -7
- data/lib/sprite_factory/style.rb +24 -5
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 01d3b01280973bccc764b752828e05df00aec623
|
4
|
+
data.tar.gz: f72a6e66a2418e791de99c2958f2d83b2863a625
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df91210723d163fb6a5638627d8e21094b46f389723a077f9a5001c1a02b7dc384e4d46783a4599ce0069ecf4a0163aa0150723f0d214cc3f31103f5cef2e669
|
7
|
+
data.tar.gz: 77904ece1613fa8ca9c673c8dae89b5556b8248d2f3d40cd39bb8089e5aace7a4983fa1123371dc02a1b9a314fcb8500ae728b627f742d50094ff20d2d90f9a1
|
data/bin/sf
CHANGED
@@ -31,6 +31,7 @@ padding_help = "add padding to each sprite"
|
|
31
31
|
margin_help = "add margin to each sprite"
|
32
32
|
nocomments_help = "suppress comments in generated stylesheet"
|
33
33
|
custom_styles_help = "Add custom styles for each sprites (E.g.: --custom-styles='display: inline-block;'"
|
34
|
+
retina_help = "create 50% smaller images & css as well"
|
34
35
|
|
35
36
|
op.on("--layout [ORIENTATION]", layout_help) {|value| options[:layout] = value }
|
36
37
|
op.on("--style [STYLE]", style_help) {|value| options[:style] = value }
|
@@ -44,6 +45,7 @@ op.on("--pngcrush", pngcrush_help) {|value| options[:pngcr
|
|
44
45
|
op.on("--padding [PIXELS]", padding_help) {|value| options[:padding] = value.to_i }
|
45
46
|
op.on("--margin [PIXELS]", margin_help) {|value| options[:margin] = value.to_i }
|
46
47
|
op.on("--nocomments", nocomments_help) {|value| options[:nocomments] = true }
|
48
|
+
op.on("--retina", retina_help) {|value| options[:retina] = true }
|
47
49
|
|
48
50
|
begin
|
49
51
|
op.parse!(ARGV)
|
data/lib/sprite_factory.rb
CHANGED
@@ -2,9 +2,9 @@ module SpriteFactory
|
|
2
2
|
|
3
3
|
#----------------------------------------------------------------------------
|
4
4
|
|
5
|
-
VERSION = "1.6.
|
5
|
+
VERSION = "1.6.2"
|
6
6
|
SUMMARY = "Automatic CSS sprite generator"
|
7
|
-
DESCRIPTION = "[tam-vo/sprite-factory] Combines individual images from a directory into a single sprite image file and creates an appropriate CSS stylesheet"
|
7
|
+
DESCRIPTION = "[tam-vo/sprite-factory v#{VERSION}] Combines individual images from a directory into a single sprite image file and creates an appropriate CSS stylesheet"
|
8
8
|
LIB = File.dirname(__FILE__)
|
9
9
|
|
10
10
|
autoload :Runner, File.join(LIB, 'sprite_factory/runner') # controller that glues everything together
|
@@ -12,7 +12,7 @@ module SpriteFactory
|
|
12
12
|
|
13
13
|
attr :input
|
14
14
|
attr :config
|
15
|
-
|
15
|
+
|
16
16
|
def initialize(input, config = {})
|
17
17
|
@input = input.to_s[-1] == "/" ? input[0...-1] : input # gracefully ignore trailing slash on input directory name
|
18
18
|
@config = config
|
@@ -25,7 +25,7 @@ module SpriteFactory
|
|
25
25
|
@config[:pngcrush] ||= SpriteFactory.pngcrush
|
26
26
|
@config[:nocomments] ||= SpriteFactory.nocomments
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
#----------------------------------------------------------------------------
|
30
30
|
|
31
31
|
def run!(&block)
|
@@ -55,7 +55,9 @@ module SpriteFactory
|
|
55
55
|
|
56
56
|
css = []
|
57
57
|
css << style_comment(header) unless nocomments? # header comment
|
58
|
-
css <<
|
58
|
+
css << retina_wrapper_start() if retina? # if retina images
|
59
|
+
css << style(selector, css_url, images, max, &block) # generated styles
|
60
|
+
css << retina_wrapper_end() if retina? # if retina images
|
59
61
|
css << IO.read(custom_style_file) if File.exists?(custom_style_file) # custom styles
|
60
62
|
css = css.join("\n")
|
61
63
|
|
@@ -67,6 +69,8 @@ module SpriteFactory
|
|
67
69
|
css_file.close
|
68
70
|
end
|
69
71
|
|
72
|
+
|
73
|
+
|
70
74
|
if config[:return] == :images
|
71
75
|
images # if caller explicitly asked for detailed images hash instead of generated CSS
|
72
76
|
else
|
@@ -76,9 +80,13 @@ module SpriteFactory
|
|
76
80
|
end
|
77
81
|
|
78
82
|
#----------------------------------------------------------------------------
|
79
|
-
|
83
|
+
|
80
84
|
private
|
81
85
|
|
86
|
+
def retina?
|
87
|
+
config[:retina]
|
88
|
+
end
|
89
|
+
|
82
90
|
def selector
|
83
91
|
config[:selector]
|
84
92
|
end
|
@@ -227,8 +235,8 @@ module SpriteFactory
|
|
227
235
|
|
228
236
|
#----------------------------------------------------------------------------
|
229
237
|
|
230
|
-
def style(selector, url, images, &block)
|
231
|
-
defaults = Style.generate(style_name, selector, url, images, custom_styles) # must call, even if custom block is given, because it stashes generated css style into image[:style] attributes
|
238
|
+
def style(selector, url, images, max, &block)
|
239
|
+
defaults = Style.generate(style_name, selector, url, images, custom_styles, config, max) # must call, even if custom block is given, because it stashes generated css style into image[:style] attributes
|
232
240
|
if block_given?
|
233
241
|
yield images.inject({}) {|h,i| h[i[:name].to_sym] = i; h} # provide custom rule builder a hash by image name
|
234
242
|
else
|
@@ -240,6 +248,14 @@ module SpriteFactory
|
|
240
248
|
Style.comment(style_name, comment)
|
241
249
|
end
|
242
250
|
|
251
|
+
def retina_wrapper_start
|
252
|
+
Style.retina_wrapper_start
|
253
|
+
end
|
254
|
+
|
255
|
+
def retina_wrapper_end
|
256
|
+
Style.retina_wrapper_end
|
257
|
+
end
|
258
|
+
|
243
259
|
#----------------------------------------------------------------------------
|
244
260
|
|
245
261
|
SUPPORTS_PNGCRUSH = !`which pngcrush`.empty? rescue false # rescue on environments without `which` (windows)
|
@@ -248,7 +264,7 @@ module SpriteFactory
|
|
248
264
|
if SUPPORTS_PNGCRUSH && config[:pngcrush]
|
249
265
|
crushed = "#{image}.crushed"
|
250
266
|
`pngcrush -rem alla -reduce -brute #{image} #{crushed}`
|
251
|
-
FileUtils.mv(crushed, image)
|
267
|
+
FileUtils.mv(crushed, image)
|
252
268
|
end
|
253
269
|
end
|
254
270
|
|
data/lib/sprite_factory/style.rb
CHANGED
@@ -15,6 +15,14 @@ module SpriteFactory
|
|
15
15
|
return "/*\n#{comment}\n*/"
|
16
16
|
end
|
17
17
|
|
18
|
+
def self.retina_style_start
|
19
|
+
"@media only screen and (-webkit-min-device-pixel-ratio: 2), only screen and (min-device-pixel-ratio: 2) {"
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.retina_style_end
|
23
|
+
"}"
|
24
|
+
end
|
25
|
+
|
18
26
|
#----------------------------------------------------------------------------
|
19
27
|
|
20
28
|
def self.scss(selector, name, attributes)
|
@@ -45,18 +53,21 @@ module SpriteFactory
|
|
45
53
|
|
46
54
|
#----------------------------------------------------------------------------
|
47
55
|
|
48
|
-
def self.generate(style_name, selector, url, images, custom_styles
|
56
|
+
def self.generate(style_name, selector, url, images, custom_styles, config, max)
|
49
57
|
styles = []
|
58
|
+
divider = config[:retina] ? 2 : 1
|
50
59
|
images.each do |image|
|
60
|
+
puts "DIV #{divider}"
|
51
61
|
attr = [
|
52
|
-
"width: #{image[:cssw]}px",
|
53
|
-
"height: #{image[:cssh]}px",
|
54
|
-
"background: #{url} #{-image[:cssx]}px #{-image[:cssy]}px no-repeat",
|
62
|
+
"width: #{image[:cssw] / divider}px",
|
63
|
+
"height: #{image[:cssh] / divider}px",
|
64
|
+
"background: #{url} #{-image[:cssx] / divider}px #{-image[:cssy] / divider}px no-repeat",
|
55
65
|
custom_styles
|
56
66
|
]
|
67
|
+
attr << "background-size: #{max[:width]/2}px #{max[:height]/2}px" if config[:retina]
|
57
68
|
image[:selector] = selector # make selector available for (optional) custom rule generators
|
58
69
|
image[:style] = send("#{style_name}_style", attr) # make pure style available for (optional) custom rule generators (see usage of yield inside Runner#style)
|
59
|
-
styles << send(style_name, selector, image[:name], attr)
|
70
|
+
styles << send(style_name, selector, image[:name].gsub('@2x', ''), attr)
|
60
71
|
end
|
61
72
|
styles << ""
|
62
73
|
styles.join("\n")
|
@@ -70,5 +81,13 @@ module SpriteFactory
|
|
70
81
|
|
71
82
|
#----------------------------------------------------------------------------
|
72
83
|
|
84
|
+
def self.retina_wrapper_start
|
85
|
+
send('retina_style_start')
|
86
|
+
end
|
87
|
+
|
88
|
+
def self.retina_wrapper_end
|
89
|
+
send('retina_style_end')
|
90
|
+
end
|
91
|
+
|
73
92
|
end
|
74
93
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sprite-factory-custom
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.6.
|
4
|
+
version: 1.6.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jake Gordon
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-04-
|
12
|
+
date: 2014-04-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rmagick
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
- - '>='
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '0'
|
42
|
-
description: '[tam-vo/sprite-factory] Combines individual images from a directory
|
42
|
+
description: '[tam-vo/sprite-factory v1.6.2] Combines individual images from a directory
|
43
43
|
into a single sprite image file and creates an appropriate CSS stylesheet'
|
44
44
|
email:
|
45
45
|
- jake@codeincomplete.com
|