spriteful 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +3 -1
- data/lib/spriteful/cli.rb +3 -1
- data/lib/spriteful/image.rb +15 -3
- data/lib/spriteful/sprite.rb +4 -2
- data/lib/spriteful/stylesheet.rb +2 -1
- data/lib/spriteful/version.rb +1 -1
- data/spec/image_spec.rb +16 -7
- data/spec/spec_helper.rb +0 -4
- metadata +27 -42
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 24c0ddd742490c912291926301cc0872049e1286
|
4
|
+
data.tar.gz: 0c2015c6fd3dcce48037df20ae06a6e42f12182f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4da9e340c10c380d934281d131051a22a3659cff93952e115b80d0c656d91f0876b8154890db8e770bfcf97cea396f61b694b3bf095cbe2077b5a54746ff72a8
|
7
|
+
data.tar.gz: 266ce80cbacfe0ba5e09e2f3f013f647f2d69923814e4fda9debde4bdca6d66ea479089633ffff72fc1516ddb40f78d47ef9039a02b379aa15e31ca06d7e8768
|
data/README.md
CHANGED
@@ -127,7 +127,8 @@ 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
|
+
We recommend that you install librsvg to improve ImageMagick support for SVG images.
|
131
132
|
|
132
133
|
```css
|
133
134
|
.images.update-icon {
|
@@ -154,6 +155,7 @@ Future versions of Spriteful could have support for generating composed images a
|
|
154
155
|
* `--horizontal` - Changes the sprite orientation to horizontal, since all sprites are combined vertically by default.
|
155
156
|
* `--save` - Saves the provided arguments for later use.
|
156
157
|
* `--spacing` - Add some spacing between the images in the sprite.
|
158
|
+
* `--no-optimize` - Skip optimizing SVG images.
|
157
159
|
|
158
160
|
You can add a `.spritefulrc` file with default options to your home directory or the current one that they will
|
159
161
|
be picked up whenever you run the `spriteful` command.
|
data/lib/spriteful/cli.rb
CHANGED
@@ -20,6 +20,7 @@ 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: 'Optimize SVG source before generating CSS.'
|
23
24
|
# Public: Gets the CLI banner for the Thor help message.
|
24
25
|
#
|
25
26
|
# Returns a String.
|
@@ -100,7 +101,8 @@ module Spriteful
|
|
100
101
|
def sprite_options
|
101
102
|
{
|
102
103
|
horizontal: options.horizontal?,
|
103
|
-
spacing: options.spacing
|
104
|
+
spacing: options.spacing,
|
105
|
+
optimize: options.optimize
|
104
106
|
}
|
105
107
|
end
|
106
108
|
|
data/lib/spriteful/image.rb
CHANGED
@@ -30,12 +30,13 @@ module Spriteful
|
|
30
30
|
# object that was initialized from the real image blob.
|
31
31
|
#
|
32
32
|
# magick_image - an 'Magick::Image' object.
|
33
|
-
def initialize(magick_image)
|
33
|
+
def initialize(magick_image, optimize=true)
|
34
34
|
@source = magick_image
|
35
|
-
@path = magick_image.
|
35
|
+
@path = magick_image.base_filename
|
36
36
|
@name = File.basename(@path)
|
37
37
|
@width = magick_image.columns
|
38
38
|
@height = magick_image.rows
|
39
|
+
@optimize = optimize
|
39
40
|
|
40
41
|
@top = 0
|
41
42
|
@left = 0
|
@@ -45,7 +46,7 @@ module Spriteful
|
|
45
46
|
#
|
46
47
|
# Returns a String.
|
47
48
|
def blob
|
48
|
-
@blob ||=
|
49
|
+
@blob ||= read_blob
|
49
50
|
end
|
50
51
|
|
51
52
|
# Public: detects if the source is a SVG image
|
@@ -55,5 +56,16 @@ module Spriteful
|
|
55
56
|
def svg?
|
56
57
|
File.extname(@path) == '.svg'
|
57
58
|
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def read_blob
|
63
|
+
contents = File.read(path)
|
64
|
+
if @optimize
|
65
|
+
SvgOptimizer.optimize(contents)
|
66
|
+
else
|
67
|
+
contents
|
68
|
+
end
|
69
|
+
end
|
58
70
|
end
|
59
71
|
end
|
data/lib/spriteful/sprite.rb
CHANGED
@@ -39,6 +39,7 @@ module Spriteful
|
|
39
39
|
# orientation.
|
40
40
|
# :spacing - spacing in pixels that should be placed between
|
41
41
|
# the images in the sprite. Defaults to 0.
|
42
|
+
# :optimize - flag to optimize SVG to be inlined
|
42
43
|
def initialize(source_dir, destination, options = {})
|
43
44
|
source_pattern = File.join(source_dir, '*{.png,.svg}')
|
44
45
|
sources = Dir[source_pattern].sort
|
@@ -49,11 +50,12 @@ module Spriteful
|
|
49
50
|
|
50
51
|
@vertical = !options[:horizontal]
|
51
52
|
@spacing = options[:spacing] || 0
|
53
|
+
@optimize = options[:optimize]
|
52
54
|
|
53
55
|
@name = File.basename(source_dir)
|
54
56
|
@filename = "#{name}.png"
|
55
57
|
@path = File.expand_path(File.join(destination, @filename))
|
56
|
-
@list = Magick::ImageList.new(*sources)
|
58
|
+
@list = Magick::ImageList.new(*sources) { self.background_color = 'none' }
|
57
59
|
@images = initialize_images(@list)
|
58
60
|
|
59
61
|
@height, @width = detect_dimensions
|
@@ -118,7 +120,7 @@ module Spriteful
|
|
118
120
|
images = []
|
119
121
|
|
120
122
|
list.to_a.each_with_index do |magick_image, index|
|
121
|
-
image = Image.new(magick_image)
|
123
|
+
image = Image.new(magick_image, @optimize)
|
122
124
|
|
123
125
|
if vertical?
|
124
126
|
image.top = sprite_position
|
data/lib/spriteful/stylesheet.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'erb'
|
2
2
|
require 'pathname'
|
3
|
+
require 'base64'
|
3
4
|
|
4
5
|
module Spriteful
|
5
6
|
# Public: class responsible for putting together the CSS code
|
@@ -129,7 +130,7 @@ module Spriteful
|
|
129
130
|
# Returns a String.
|
130
131
|
def data_uri(image)
|
131
132
|
if image.svg?
|
132
|
-
%['data:image/svg+xml;
|
133
|
+
%['data:image/svg+xml;base64,#{Base64.encode64(image.blob).gsub(/\r?\n/, '')}']
|
133
134
|
end
|
134
135
|
end
|
135
136
|
end
|
data/lib/spriteful/version.rb
CHANGED
data/spec/image_spec.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Spriteful::Image do
|
4
|
-
let(:
|
5
|
-
|
4
|
+
let(:filename) { 'path/to/image.png' }
|
5
|
+
let(:source_image) { double('Magick Image', base_filename: filename, columns: 10, rows: 5) }
|
6
|
+
let(:optimize) { true }
|
7
|
+
subject(:image) { Spriteful::Image.new(source_image, optimize) }
|
6
8
|
|
7
9
|
it { expect(image.name).to eq('image.png') }
|
8
10
|
it { expect(image.path).to eq('path/to/image.png') }
|
@@ -12,15 +14,22 @@ describe Spriteful::Image do
|
|
12
14
|
it { expect(image).to_not be_svg }
|
13
15
|
|
14
16
|
context 'SVG images' do
|
15
|
-
|
16
|
-
source_image.stub(filename: 'spec/fixtures/svg/green.svg')
|
17
|
-
end
|
17
|
+
let(:filename) { 'spec/fixtures/svg/green.svg' }
|
18
18
|
|
19
19
|
it { expect(image).to be_svg }
|
20
20
|
|
21
|
-
it 'returns the SVG XML as the #blob' do
|
22
|
-
xml = SvgOptimizer.optimize(File.read(source_image.
|
21
|
+
it 'returns the optimized SVG XML as the #blob' do
|
22
|
+
xml = SvgOptimizer.optimize(File.read(source_image.base_filename))
|
23
23
|
expect(image.blob).to eq(xml)
|
24
24
|
end
|
25
|
+
|
26
|
+
context 'skiping svg optimize' do
|
27
|
+
let(:optimize) { false }
|
28
|
+
|
29
|
+
it 'returns the unoptimized SVG XML as the #blob' do
|
30
|
+
xml = File.read(source_image.base_filename)
|
31
|
+
expect(image.blob).to eq(xml)
|
32
|
+
end
|
33
|
+
end
|
25
34
|
end
|
26
35
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,116 +1,103 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spriteful
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Lucas Mazza
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-04-16 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: thor
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: 0.18.1
|
22
|
-
- - <
|
20
|
+
- - "<"
|
23
21
|
- !ruby/object:Gem::Version
|
24
22
|
version: '2.0'
|
25
23
|
type: :runtime
|
26
24
|
prerelease: false
|
27
25
|
version_requirements: !ruby/object:Gem::Requirement
|
28
|
-
none: false
|
29
26
|
requirements:
|
30
|
-
- -
|
27
|
+
- - ">="
|
31
28
|
- !ruby/object:Gem::Version
|
32
29
|
version: 0.18.1
|
33
|
-
- - <
|
30
|
+
- - "<"
|
34
31
|
- !ruby/object:Gem::Version
|
35
32
|
version: '2.0'
|
36
33
|
- !ruby/object:Gem::Dependency
|
37
34
|
name: rmagick
|
38
35
|
requirement: !ruby/object:Gem::Requirement
|
39
|
-
none: false
|
40
36
|
requirements:
|
41
|
-
- - ~>
|
37
|
+
- - "~>"
|
42
38
|
- !ruby/object:Gem::Version
|
43
39
|
version: 2.13.2
|
44
40
|
type: :runtime
|
45
41
|
prerelease: false
|
46
42
|
version_requirements: !ruby/object:Gem::Requirement
|
47
|
-
none: false
|
48
43
|
requirements:
|
49
|
-
- - ~>
|
44
|
+
- - "~>"
|
50
45
|
- !ruby/object:Gem::Version
|
51
46
|
version: 2.13.2
|
52
47
|
- !ruby/object:Gem::Dependency
|
53
48
|
name: svg_optimizer
|
54
49
|
requirement: !ruby/object:Gem::Requirement
|
55
|
-
none: false
|
56
50
|
requirements:
|
57
|
-
- -
|
51
|
+
- - ">="
|
58
52
|
- !ruby/object:Gem::Version
|
59
53
|
version: '0'
|
60
54
|
type: :runtime
|
61
55
|
prerelease: false
|
62
56
|
version_requirements: !ruby/object:Gem::Requirement
|
63
|
-
none: false
|
64
57
|
requirements:
|
65
|
-
- -
|
58
|
+
- - ">="
|
66
59
|
- !ruby/object:Gem::Version
|
67
60
|
version: '0'
|
68
61
|
- !ruby/object:Gem::Dependency
|
69
62
|
name: rspec
|
70
63
|
requirement: !ruby/object:Gem::Requirement
|
71
|
-
none: false
|
72
64
|
requirements:
|
73
|
-
- -
|
65
|
+
- - '='
|
74
66
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
67
|
+
version: 3.0.0.beta2
|
76
68
|
type: :development
|
77
69
|
prerelease: false
|
78
70
|
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
none: false
|
80
71
|
requirements:
|
81
|
-
- -
|
72
|
+
- - '='
|
82
73
|
- !ruby/object:Gem::Version
|
83
|
-
version:
|
74
|
+
version: 3.0.0.beta2
|
84
75
|
- !ruby/object:Gem::Dependency
|
85
76
|
name: bundler
|
86
77
|
requirement: !ruby/object:Gem::Requirement
|
87
|
-
none: false
|
88
78
|
requirements:
|
89
|
-
- - ~>
|
79
|
+
- - "~>"
|
90
80
|
- !ruby/object:Gem::Version
|
91
|
-
version: '1.
|
81
|
+
version: '1.5'
|
92
82
|
type: :development
|
93
83
|
prerelease: false
|
94
84
|
version_requirements: !ruby/object:Gem::Requirement
|
95
|
-
none: false
|
96
85
|
requirements:
|
97
|
-
- - ~>
|
86
|
+
- - "~>"
|
98
87
|
- !ruby/object:Gem::Version
|
99
|
-
version: '1.
|
88
|
+
version: '1.5'
|
100
89
|
- !ruby/object:Gem::Dependency
|
101
90
|
name: rake
|
102
91
|
requirement: !ruby/object:Gem::Requirement
|
103
|
-
none: false
|
104
92
|
requirements:
|
105
|
-
- -
|
93
|
+
- - ">="
|
106
94
|
- !ruby/object:Gem::Version
|
107
95
|
version: '0'
|
108
96
|
type: :development
|
109
97
|
prerelease: false
|
110
98
|
version_requirements: !ruby/object:Gem::Requirement
|
111
|
-
none: false
|
112
99
|
requirements:
|
113
|
-
- -
|
100
|
+
- - ">="
|
114
101
|
- !ruby/object:Gem::Version
|
115
102
|
version: '0'
|
116
103
|
description: A sprite generation tool
|
@@ -123,6 +110,8 @@ extra_rdoc_files: []
|
|
123
110
|
files:
|
124
111
|
- LICENSE
|
125
112
|
- README.md
|
113
|
+
- bin/spriteful
|
114
|
+
- lib/spriteful.rb
|
126
115
|
- lib/spriteful/cli.rb
|
127
116
|
- lib/spriteful/image.rb
|
128
117
|
- lib/spriteful/sprite.rb
|
@@ -130,7 +119,6 @@ files:
|
|
130
119
|
- lib/spriteful/stylesheets/template.css.erb
|
131
120
|
- lib/spriteful/stylesheets/template.scss.erb
|
132
121
|
- lib/spriteful/version.rb
|
133
|
-
- lib/spriteful.rb
|
134
122
|
- spec/fixtures/simple/blue.png
|
135
123
|
- spec/fixtures/simple/red.png
|
136
124
|
- spec/fixtures/svg/green.svg
|
@@ -139,31 +127,29 @@ files:
|
|
139
127
|
- spec/spec_helper.rb
|
140
128
|
- spec/sprite_spec.rb
|
141
129
|
- spec/stylesheet_spec.rb
|
142
|
-
- bin/spriteful
|
143
130
|
homepage: https://github.com/lucasmazza/spriteful
|
144
131
|
licenses:
|
145
132
|
- Apache 2.0
|
133
|
+
metadata: {}
|
146
134
|
post_install_message:
|
147
135
|
rdoc_options: []
|
148
136
|
require_paths:
|
149
137
|
- lib
|
150
138
|
required_ruby_version: !ruby/object:Gem::Requirement
|
151
|
-
none: false
|
152
139
|
requirements:
|
153
|
-
- -
|
140
|
+
- - ">="
|
154
141
|
- !ruby/object:Gem::Version
|
155
142
|
version: '0'
|
156
143
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
157
|
-
none: false
|
158
144
|
requirements:
|
159
|
-
- -
|
145
|
+
- - ">="
|
160
146
|
- !ruby/object:Gem::Version
|
161
147
|
version: '0'
|
162
148
|
requirements: []
|
163
149
|
rubyforge_project:
|
164
|
-
rubygems_version:
|
150
|
+
rubygems_version: 2.2.2
|
165
151
|
signing_key:
|
166
|
-
specification_version:
|
152
|
+
specification_version: 4
|
167
153
|
summary: ''
|
168
154
|
test_files:
|
169
155
|
- spec/fixtures/simple/blue.png
|
@@ -174,4 +160,3 @@ test_files:
|
|
174
160
|
- spec/spec_helper.rb
|
175
161
|
- spec/sprite_spec.rb
|
176
162
|
- spec/stylesheet_spec.rb
|
177
|
-
has_rdoc:
|