spriteful 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -1
- data/lib/spriteful.rb +1 -0
- data/lib/spriteful/cli.rb +15 -1
- data/lib/spriteful/optimizer.rb +56 -0
- data/lib/spriteful/version.rb +1 -1
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0368a10d14e6885315939bf705b93a6ee52da147
|
4
|
+
data.tar.gz: b1a79824842c4dd6d94ff7ac061d3344ee813684
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce91faa1f865bc71bcd786fa376e609b62ea86fa147392ca9bca188e1e58af331e9f5fcfb58709345496ac31361156f70e18eba480eebf90efe36bfbabb394b1
|
7
|
+
data.tar.gz: 7e0e39fe26e733430c32e844bb5af0a99df132e3f1914be0ae3498fbaa666f8bc5f4dd50a3a9ee33207b2036a995e88d077fe5505aa18c951f2133695bcb882d
|
data/README.md
CHANGED
@@ -127,7 +127,7 @@ Spriteful has a basic support for dealing with SVG images (and not only PNGs). S
|
|
127
127
|
will be combined along the rest of your images and will be embedded directly on the final
|
128
128
|
Stylesheet in the data URI format. Using the `svg` root class (based on Modernizr), the
|
129
129
|
data URI will be used for browsers that support SVG images and the composed PNG will work
|
130
|
-
as a fallback for legacy browsers.
|
130
|
+
as a fallback for legacy browsers.
|
131
131
|
We recommend that you install librsvg to improve ImageMagick support for SVG images.
|
132
132
|
|
133
133
|
```css
|
@@ -145,6 +145,16 @@ We recommend that you install librsvg to improve ImageMagick support for SVG ima
|
|
145
145
|
Future versions of Spriteful could have support for generating composed images as SVG files
|
146
146
|
(and not only PNG), so feel free to send a contribution improving the feature.
|
147
147
|
|
148
|
+
|
149
|
+
## Image Optimization
|
150
|
+
|
151
|
+
Spriteful supports PNG optimization through the [image_optim](https://github.com/toy/image_optim)
|
152
|
+
gem. You should have one of the following utilities present on your system: `pngcrush`, `pngout`,
|
153
|
+
`optipng` or `advpng`. If none can be found, the optimization will be skipped.
|
154
|
+
|
155
|
+
If you are using SVG images, the embedded SVG as data URI will be optimized with the
|
156
|
+
[svg_optimizer](https://github.com/fnando/svg_optimizer) gem.
|
157
|
+
|
148
158
|
## Available options
|
149
159
|
|
150
160
|
* `--stylesheets` (`-s`) - Directory to save the generated stylesheet(s), instead of copying them to the clipboard.
|
data/lib/spriteful.rb
CHANGED
data/lib/spriteful/cli.rb
CHANGED
@@ -20,7 +20,8 @@ module Spriteful
|
|
20
20
|
class_option :spacing, type: :numeric, desc: 'Add spacing between the images in the sprite.'
|
21
21
|
|
22
22
|
class_option :version, type: :boolean, aliases: '-v'
|
23
|
-
class_option :optimize, type: :boolean, default: true, desc: '
|
23
|
+
class_option :optimize, type: :boolean, default: true, desc: 'Optimizes the combined PNG and inline SVG images.'
|
24
|
+
|
24
25
|
# Public: Gets the CLI banner for the Thor help message.
|
25
26
|
#
|
26
27
|
# Returns a String.
|
@@ -61,6 +62,11 @@ module Spriteful
|
|
61
62
|
end
|
62
63
|
|
63
64
|
private
|
65
|
+
# Internal: Gets an instance of `Spriteful::Optimizer`.
|
66
|
+
def optimizer
|
67
|
+
@optimizer ||= Optimizer.new
|
68
|
+
end
|
69
|
+
|
64
70
|
# Internal: create a sprite image and stylesheet from a given source.
|
65
71
|
#
|
66
72
|
# Returns nothing.
|
@@ -71,6 +77,14 @@ module Spriteful
|
|
71
77
|
sprite.combine!
|
72
78
|
create_file sprite.path, sprite.blob
|
73
79
|
create_file stylesheet.path, stylesheet.render
|
80
|
+
if options.optimize?
|
81
|
+
if optimizer.enabled?
|
82
|
+
say_status :optimizing, relative_to_original_destination_root(sprite.path)
|
83
|
+
optimizer.optimize!(sprite.path)
|
84
|
+
else
|
85
|
+
say_status :optimizing, "No optimizer found. Please install at least one of the following: #{optimizer.optimizers.join(', ')}.", :yellow
|
86
|
+
end
|
87
|
+
end
|
74
88
|
end
|
75
89
|
|
76
90
|
# Internal: Saves the existing options on 'ARGV' to the '.spritefulrc'
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'image_optim'
|
2
|
+
|
3
|
+
module Spriteful
|
4
|
+
# Internal: Wrapper class for the `ImageOptim` gem that can
|
5
|
+
# optimize PNG images and won't crash if no PNG optimizer is
|
6
|
+
# presented.
|
7
|
+
class Optimizer
|
8
|
+
# Public: Initializes the Optimizer, checking for missing
|
9
|
+
# optimizers that should be ignored when optimizing the image.
|
10
|
+
def initialize
|
11
|
+
@optimizer = ImageOptim.new(optimization_options)
|
12
|
+
end
|
13
|
+
|
14
|
+
# Public: Optimizes and replaces the given path.
|
15
|
+
#
|
16
|
+
# Returns nothing.
|
17
|
+
def optimize!(path)
|
18
|
+
@optimizer.optimize_image!(path)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Public: Returns true if any optimization can be executed
|
22
|
+
# of if the `optimize!` will be a no-op.
|
23
|
+
#
|
24
|
+
# Returns true or false.
|
25
|
+
def enabled?
|
26
|
+
optimization_options.values.any?
|
27
|
+
end
|
28
|
+
|
29
|
+
# Public: Gets a list of supported optimizers.
|
30
|
+
def optimizers
|
31
|
+
%w(pngcrush pngout optipng advpng)
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
# Internal: Maps which optimizers (or 'workers') that
|
36
|
+
# are missing from the system and should be ignored by
|
37
|
+
# the `ImageOptim` optimizer.
|
38
|
+
#
|
39
|
+
# Returns a Hash.
|
40
|
+
def optimization_options
|
41
|
+
@options ||= optimizers.each_with_object({}) do |key, hash|
|
42
|
+
hash[key.to_sym] = command_exists?(key)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# Internal: Checks if a command exists.
|
47
|
+
#
|
48
|
+
# Returns true or false.
|
49
|
+
def command_exists?(command)
|
50
|
+
ENV['PATH'].split(File::PATH_SEPARATOR).any? do |root|
|
51
|
+
path = File.join(root, command)
|
52
|
+
File.executable?(path) && File.file?(path)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/lib/spriteful/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spriteful
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lucas Mazza
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -58,6 +58,20 @@ dependencies:
|
|
58
58
|
- - ">="
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: image_optim
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :runtime
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
61
75
|
- !ruby/object:Gem::Dependency
|
62
76
|
name: rspec
|
63
77
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,6 +128,7 @@ files:
|
|
114
128
|
- lib/spriteful.rb
|
115
129
|
- lib/spriteful/cli.rb
|
116
130
|
- lib/spriteful/image.rb
|
131
|
+
- lib/spriteful/optimizer.rb
|
117
132
|
- lib/spriteful/sprite.rb
|
118
133
|
- lib/spriteful/stylesheet.rb
|
119
134
|
- lib/spriteful/stylesheets/template.css.erb
|