spriteful 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -0
- data/lib/spriteful/cli.rb +3 -1
- data/lib/spriteful/stylesheet.rb +19 -2
- data/lib/spriteful/stylesheets/template.scss.erb +9 -4
- data/spec/sprite_spec.rb +14 -0
- data/spec/stylesheet_spec.rb +11 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f6cf5f6f9da3adc2537eedce271cdf44121395d5
|
4
|
+
data.tar.gz: 7986af3aacb58098b2ffd059631529f9d7446e71
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e30d010efaa8b3167dfabf53f4aeba3e76fcab957b644418d7a70abc180b744dcd5c3d066b951925088c34d116889ea940d4fec9cf39dddafa11cf924127bf6
|
7
|
+
data.tar.gz: 056140c5247449b352b092d5fbfe57da6e2cfb8c27f5cbdd3d85ef42dc11f353d2dc17bc8fc5e0bebee0d606bdcdd199790072414ce2be24d776335091c000ad
|
data/README.md
CHANGED
@@ -55,6 +55,22 @@ spriteful images/icons -f scss
|
|
55
55
|
}
|
56
56
|
```
|
57
57
|
|
58
|
+
You can also choose to genete the code using
|
59
|
+
[Mixin Directives](http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#mixins).
|
60
|
+
|
61
|
+
```bash
|
62
|
+
spriteful images/icons -f scss --mixin
|
63
|
+
# create icons.png
|
64
|
+
# copy icons.scss
|
65
|
+
```
|
66
|
+
|
67
|
+
```scss
|
68
|
+
// in your SCSS code...
|
69
|
+
.button {
|
70
|
+
@include icons-sprite-new;
|
71
|
+
}
|
72
|
+
```
|
73
|
+
|
58
74
|
### Multiple sprites
|
59
75
|
|
60
76
|
You can deal with multiple sprites in a single run. If `images/icons` has a set of images for one
|
@@ -100,6 +116,7 @@ you need to add a new source to an existing sprite.
|
|
100
116
|
* `--destination` (`-d`) - Directory to save the generated image(s).
|
101
117
|
* `--rails` (`-r`) - Forces rails specific settings, see [Spriteful and Rails](#spriteful-and-rails) for more info.
|
102
118
|
* `--format` (`-f`) - Format to generate the sprite(s) stylesheet(s). Either "css" or "scss".
|
119
|
+
* `--mixin` - Choose to use the Mixin Directives instead of Placeholder Selector.
|
103
120
|
* `--horizontal` - Changes the sprite orientation to horizontal, since all sprites are combined vertically by default.
|
104
121
|
* `--save` - Saves the provided arguments for later use.
|
105
122
|
* `--spacing` - Add some spacing between the images in the sprite.
|
data/lib/spriteful/cli.rb
CHANGED
@@ -13,6 +13,7 @@ module Spriteful
|
|
13
13
|
class_option :destination, aliases: '-d', banner: 'DESTINATION_DIR', type: :string, desc: 'Destination directory to save the combined image(s).', default: Dir.pwd
|
14
14
|
class_option :root, aliases: '-r', banner: 'ROOT_DIR', type: :string, desc: 'Root folder from where your static files will be served.'
|
15
15
|
|
16
|
+
class_option :mixin, type: :boolean, desc: 'Choose to use the Mixin Directives instead of Placeholder Selectors.'
|
16
17
|
class_option :rails, type: :boolean, desc: 'Follow default conventions for a Rails application with the Asset Pipeline.'
|
17
18
|
class_option :horizontal, type: :boolean, desc: 'Change the sprite orientation to "horizontal".'
|
18
19
|
class_option :save, type: :boolean, desc: 'Save the supplied arguments to ".spritefulrc".'
|
@@ -79,7 +80,8 @@ module Spriteful
|
|
79
80
|
{
|
80
81
|
root: options.root,
|
81
82
|
format: options.format,
|
82
|
-
rails: options.rails
|
83
|
+
rails: options.rails?,
|
84
|
+
mixin: options.mixin?
|
83
85
|
}
|
84
86
|
end
|
85
87
|
|
data/lib/spriteful/stylesheet.rb
CHANGED
@@ -20,6 +20,7 @@ module Spriteful
|
|
20
20
|
# destination - the directory where the Stylesheet will be created.
|
21
21
|
# options - additional Hash of options.
|
22
22
|
# :format - the Stylesheet format.
|
23
|
+
# :mixin - Use mixins instead of Placeholder selector in the SCSS format.
|
23
24
|
# :rails - A flag to generate Asset Pipeline compatible Stylesheets.
|
24
25
|
def initialize(sprite, destination, options = {})
|
25
26
|
@sprite = sprite
|
@@ -29,7 +30,8 @@ module Spriteful
|
|
29
30
|
@root = Pathname.new(File.expand_path(options[:root]))
|
30
31
|
end
|
31
32
|
@format = options[:format]
|
32
|
-
@
|
33
|
+
@mixin = options.fetch(:mixin, false)
|
34
|
+
@rails = options.fetch(:rails, false)
|
33
35
|
|
34
36
|
@path = @destination.join(name)
|
35
37
|
end
|
@@ -55,11 +57,26 @@ module Spriteful
|
|
55
57
|
|
56
58
|
protected
|
57
59
|
|
58
|
-
# Internal: returns the 'rails
|
60
|
+
# Internal: returns the 'rails' flag.
|
59
61
|
def rails?
|
60
62
|
@rails
|
61
63
|
end
|
62
64
|
|
65
|
+
# Internal: returns the 'mixin' flag.
|
66
|
+
def mixin?
|
67
|
+
@mixin
|
68
|
+
end
|
69
|
+
|
70
|
+
# Internal: select the extension prefix for the SCSS selector.
|
71
|
+
def extension_prefix
|
72
|
+
mixin? ? '@mixin ' : '%'
|
73
|
+
end
|
74
|
+
|
75
|
+
# Internal: select the extension strategy for the SCSS selector.
|
76
|
+
def extension_strategy
|
77
|
+
mixin? ? '@include ' : '@extend %'
|
78
|
+
end
|
79
|
+
|
63
80
|
# Internal: defines the file extension to be used with
|
64
81
|
# Rails applications, since we need to account for the ERB
|
65
82
|
# preprocessing of plain CSS files.
|
@@ -1,15 +1,20 @@
|
|
1
1
|
// ============================================================================
|
2
2
|
// This Stylesheet was generated by the 'spriteful' gem.
|
3
|
+
<%- if mixin? -%>
|
4
|
+
// Below there are several [Mixin Directives]
|
5
|
+
// (http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#mixins)
|
6
|
+
<%- else -%>
|
3
7
|
// Below there are several [Placeholder Selectors]
|
4
8
|
// (http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#placeholder_selectors_)
|
9
|
+
<%- end -%>
|
5
10
|
// to use the '<%= sprite.name %>' sprite on your SCSS code, as in:
|
6
11
|
//
|
7
12
|
// .my-thing {
|
8
|
-
//
|
13
|
+
// <%= extension_strategy %><%= class_name_for(sprite) %>-sprite-<%= class_name_for(sprite.images.first) %>;
|
9
14
|
// // Your styles here.
|
10
15
|
// }
|
11
16
|
|
12
|
-
|
17
|
+
<%= extension_prefix %><%= class_name_for(sprite) %>-sprite {
|
13
18
|
<%- if rails? -%>
|
14
19
|
background-image: image-url('<%= image_url(sprite) %>');
|
15
20
|
<%- else -%>
|
@@ -18,8 +23,8 @@
|
|
18
23
|
background-repeat: no-repeat;
|
19
24
|
}
|
20
25
|
<% sprite.each_image do |image| %>
|
21
|
-
|
22
|
-
|
26
|
+
<%= extension_prefix %><%= class_name_for(sprite) %>-sprite-<%= class_name_for(image) %> {
|
27
|
+
<%= extension_strategy %><%= class_name_for(sprite) %>-sprite;
|
23
28
|
background-position: <%= image.left %>px <%= image.top %>px;
|
24
29
|
}
|
25
30
|
<% end %>
|
data/spec/sprite_spec.rb
CHANGED
@@ -92,12 +92,26 @@ describe Spriteful::Sprite do
|
|
92
92
|
expect(red.left).to eq(0)
|
93
93
|
end
|
94
94
|
|
95
|
+
it 'accounts the spacing option when setting the "left" attribute of each image on a horizontal sprite' do
|
96
|
+
sprite = Spriteful::Sprite.new(source, destination, spacing: 10, horizontal: true)
|
97
|
+
blue, red = sprite.images.to_a
|
98
|
+
|
99
|
+
expect(blue.top).to eq(0)
|
100
|
+
expect(blue.left).to eq(0)
|
101
|
+
|
102
|
+
expect(red.top).to eq(0)
|
103
|
+
expect(red.left).to eq(-20)
|
104
|
+
end
|
105
|
+
|
95
106
|
it 'accounts the spacing option when setting the "top" attribute of each image' do
|
96
107
|
sprite = Spriteful::Sprite.new(source, destination, spacing: 10)
|
97
108
|
blue, red = sprite.images.to_a
|
98
109
|
|
99
110
|
expect(blue.top).to eq(0)
|
111
|
+
expect(blue.left).to eq(0)
|
112
|
+
|
100
113
|
expect(red.top).to eq(-20)
|
114
|
+
expect(red.left).to eq(0)
|
101
115
|
end
|
102
116
|
end
|
103
117
|
end
|
data/spec/stylesheet_spec.rb
CHANGED
@@ -24,5 +24,16 @@ describe Spriteful::Stylesheet do
|
|
24
24
|
expect(output).to match(/%simple-sprite-blue \{/)
|
25
25
|
expect(output).to match(/%simple-sprite-red \{/)
|
26
26
|
end
|
27
|
+
|
28
|
+
it 'renders the SCSS format using mixin' do
|
29
|
+
sprite = Spriteful::Sprite.new(source, destination)
|
30
|
+
stylesheet = Spriteful::Stylesheet.new(sprite, destination, format: 'scss', mixin: true)
|
31
|
+
output = stylesheet.render
|
32
|
+
|
33
|
+
expect(output).to match(/@mixin simple-sprite \{/)
|
34
|
+
expect(output).to match(/@mixin simple-sprite-blue \{/)
|
35
|
+
expect(output).to match(/@include simple-sprite;/)
|
36
|
+
expect(output).to match(/@mixin simple-sprite-red \{/)
|
37
|
+
end
|
27
38
|
end
|
28
39
|
end
|
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.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lucas Mazza
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-09-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|