spriteful 0.2.0 → 0.3.0.beta1
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.
- checksums.yaml +4 -4
- data/README.md +22 -0
- data/lib/spriteful.rb +1 -0
- data/lib/spriteful/cli.rb +36 -8
- data/lib/spriteful/stylesheet.rb +29 -59
- data/lib/spriteful/stylesheets/template.css.erb +1 -1
- data/lib/spriteful/stylesheets/template.scss.erb +1 -1
- data/lib/spriteful/template.rb +113 -0
- data/lib/spriteful/version.rb +1 -1
- data/spec/fixtures/template.erb +23 -0
- data/spec/spriteful/template_spec.rb +88 -0
- data/spec/stylesheet_spec.rb +13 -0
- metadata +9 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9cf879ad9e9e6ef6d5979c18ba95057105fbdb43
|
4
|
+
data.tar.gz: ba2e166801f3893946ecd53330a2fa72d5da26bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e051ba566bc763e3c05c0c17959f5c96b9547854946605d548d1bcccad288debd826d11be58eb51e39e3084038e574be68b3cf228fcdd53aace8faf13c44b4f
|
7
|
+
data.tar.gz: dce408ad68c9a3518496ff6a0ea8e02a08a1c6cd63b42dbc607189e4c5bbbff976e4048bdc98a3291594288c7221d6a0a8947b8ae3e38e10df809d54c2e13317
|
data/README.md
CHANGED
@@ -121,6 +121,27 @@ images under `icons` will generate the `icons.png` and `icons.css` files. This c
|
|
121
121
|
enforces previsibility over generated files and helps when regenating existing sprites whenever
|
122
122
|
you need to add a new source to an existing sprite.
|
123
123
|
|
124
|
+
## Custom templates
|
125
|
+
|
126
|
+
If you need further customization of the sprite CSS, you can use a custom ERB template
|
127
|
+
to be used instead of the builtin templates.
|
128
|
+
|
129
|
+
```bash
|
130
|
+
spriteful image/icons --template custom_template.erb
|
131
|
+
```
|
132
|
+
|
133
|
+
In this case, the `custom_template.erb` file will be evaluated in the context of a
|
134
|
+
`Spriteful::Template` instance. Please check this class documentation and source
|
135
|
+
to see all the available attributes and helpers.
|
136
|
+
|
137
|
+
You can copy one of the builtin templates to your working directory with the `template`
|
138
|
+
subcommand.
|
139
|
+
|
140
|
+
```bash
|
141
|
+
spriteful template
|
142
|
+
# create spriteful.css
|
143
|
+
```
|
144
|
+
|
124
145
|
## SVG Support
|
125
146
|
|
126
147
|
Spriteful has a basic support for dealing with SVG images (and not only PNGs). SVG images
|
@@ -161,6 +182,7 @@ If you are using SVG images, the embedded SVG as data URI will be optimized with
|
|
161
182
|
* `--destination` (`-d`) - Directory to save the generated image(s).
|
162
183
|
* `--rails` (`-r`) - Forces rails specific settings, see [Spriteful and Rails](#spriteful-and-rails) for more info.
|
163
184
|
* `--format` (`-f`) - Format to generate the sprite(s) stylesheet(s). Either "css" or "scss".
|
185
|
+
* `--template` (`-t`) - The path for a custom Stylesheet template.
|
164
186
|
* `--mixin` - Choose to use the Mixin Directives instead of Placeholder Selector.
|
165
187
|
* `--horizontal` - Changes the sprite orientation to horizontal, since all sprites are combined vertically by default.
|
166
188
|
* `--save` - Saves the provided arguments for later use.
|
data/lib/spriteful.rb
CHANGED
data/lib/spriteful/cli.rb
CHANGED
@@ -12,6 +12,7 @@ module Spriteful
|
|
12
12
|
class_option :stylesheets, aliases: '-s', banner: 'STYLESHEETS_DIR', type: :string, desc: 'Directory to save the generated stylesheet(s), instead of copying them to the clipboard.', default: Dir.pwd
|
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
|
+
class_option :template, aliases: '-t', banner: 'TEMPLATE', type: :string, desc: 'Custom template file in ERB format to be used instead of the default.'
|
15
16
|
|
16
17
|
class_option :mixin, type: :boolean, desc: 'Choose to use the Mixin Directives instead of Placeholder Selectors.'
|
17
18
|
class_option :rails, type: :boolean, desc: 'Follow default conventions for a Rails application with the Asset Pipeline.'
|
@@ -46,7 +47,6 @@ module Spriteful
|
|
46
47
|
end
|
47
48
|
|
48
49
|
prepare_options!
|
49
|
-
Spriteful.options = ARGV.dup.uniq
|
50
50
|
|
51
51
|
if sources.empty?
|
52
52
|
self.class.help(shell)
|
@@ -61,6 +61,20 @@ module Spriteful
|
|
61
61
|
save_options
|
62
62
|
end
|
63
63
|
|
64
|
+
def template
|
65
|
+
create_file "spriteful.#{options.format}", Spriteful::Stylesheet.read_template(options.format)
|
66
|
+
end
|
67
|
+
|
68
|
+
protected
|
69
|
+
def self.dispatch(command, args, opts, config)
|
70
|
+
if args.first == 'template'
|
71
|
+
command = args.shift
|
72
|
+
else
|
73
|
+
command = 'execute'
|
74
|
+
end
|
75
|
+
super(command, args, opts, config)
|
76
|
+
end
|
77
|
+
|
64
78
|
private
|
65
79
|
# Internal: Gets an instance of `Spriteful::Optimizer`.
|
66
80
|
def optimizer
|
@@ -92,19 +106,21 @@ module Spriteful
|
|
92
106
|
#
|
93
107
|
# Returns nothing.
|
94
108
|
def save_options
|
95
|
-
if
|
96
|
-
|
97
|
-
|
98
|
-
create_file '.spritefulrc', Shellwords.join(parts) + "\n", force: true
|
109
|
+
if save_options?
|
110
|
+
parts = Shellwords.join(Spriteful.options)
|
111
|
+
create_file '.spritefulrc', parts + "\n", force: true
|
99
112
|
end
|
100
113
|
end
|
101
114
|
|
102
115
|
def stylesheet_options
|
116
|
+
template = File.expand_path(options.template) if File.file?(options.template.to_s)
|
117
|
+
|
103
118
|
{
|
104
119
|
root: options.root,
|
105
120
|
format: options.format,
|
106
121
|
rails: options.rails?,
|
107
|
-
mixin: options.mixin
|
122
|
+
mixin: options.mixin?,
|
123
|
+
template: template
|
108
124
|
}
|
109
125
|
end
|
110
126
|
|
@@ -120,11 +136,15 @@ module Spriteful
|
|
120
136
|
}
|
121
137
|
end
|
122
138
|
|
123
|
-
# Internal:
|
124
|
-
# 'rails' flag
|
139
|
+
# Internal: Changes the `options` hash if necessary (based on the
|
140
|
+
# '--rails' flag) and store the original 'ARGV' array for further
|
141
|
+
# usage.
|
125
142
|
#
|
126
143
|
# Returns nothing.
|
127
144
|
def prepare_options!
|
145
|
+
Spriteful.options = ARGV.dup.uniq
|
146
|
+
@save_options = !!Spriteful.options.delete('--save')
|
147
|
+
|
128
148
|
if options.rails?
|
129
149
|
sources.concat(detect_sources)
|
130
150
|
set_rails_defaults
|
@@ -146,5 +166,13 @@ module Spriteful
|
|
146
166
|
options['stylesheets'] = File.expand_path('app/assets/stylesheets/sprites')
|
147
167
|
options['destination'] = File.expand_path('app/assets/images/sprites')
|
148
168
|
end
|
169
|
+
|
170
|
+
# Internal: Checks if we should save the supplied user arguments into
|
171
|
+
# the rcfile.
|
172
|
+
#
|
173
|
+
# Returns true or false.
|
174
|
+
def save_options?
|
175
|
+
@save_options
|
176
|
+
end
|
149
177
|
end
|
150
178
|
end
|
data/lib/spriteful/stylesheet.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'erb'
|
2
|
-
require 'pathname'
|
3
1
|
require 'base64'
|
4
2
|
|
5
3
|
module Spriteful
|
@@ -15,6 +13,9 @@ module Spriteful
|
|
15
13
|
# Public: returns the path where the Stylesheet should be stored.
|
16
14
|
attr_reader :path
|
17
15
|
|
16
|
+
# Public: returns the custom template path.
|
17
|
+
attr_reader :template_path
|
18
|
+
|
18
19
|
# Public: Initialize a Stylesheet
|
19
20
|
#
|
20
21
|
# sprite - a 'Sprite' object to create the Stylesheet.
|
@@ -25,16 +26,14 @@ module Spriteful
|
|
25
26
|
# :rails - A flag to generate Asset Pipeline compatible Stylesheets.
|
26
27
|
def initialize(sprite, destination, options = {})
|
27
28
|
@sprite = sprite
|
28
|
-
@
|
29
|
-
@
|
30
|
-
|
31
|
-
@root = Pathname.new(File.expand_path(options[:root]))
|
32
|
-
end
|
29
|
+
@options = options
|
30
|
+
@destination = destination
|
31
|
+
|
33
32
|
@format = options[:format]
|
34
|
-
@
|
35
|
-
@
|
33
|
+
@rails = !!options[:rails]
|
34
|
+
@template_path = options[:template] || self.class.expand_template_path(@format)
|
36
35
|
|
37
|
-
@path =
|
36
|
+
@path = File.join(@destination, name)
|
38
37
|
end
|
39
38
|
|
40
39
|
# Public: renders the CSS code for this Stylesheet.
|
@@ -43,8 +42,8 @@ module Spriteful
|
|
43
42
|
#
|
44
43
|
# Returns the CSS code as a 'String'.
|
45
44
|
def render
|
46
|
-
|
47
|
-
|
45
|
+
template = Template.new(@sprite, template_options)
|
46
|
+
template.render(File.read(template_path))
|
48
47
|
end
|
49
48
|
|
50
49
|
# Public: returns this Stylesheet name, based
|
@@ -56,26 +55,30 @@ module Spriteful
|
|
56
55
|
"#{sprite_name}.#{extension}"
|
57
56
|
end
|
58
57
|
|
59
|
-
|
60
|
-
|
61
|
-
#
|
62
|
-
def
|
63
|
-
|
58
|
+
# Internal: Reads the default template Stylesheet for the given format.
|
59
|
+
#
|
60
|
+
# Returns a String.
|
61
|
+
def self.read_template(format)
|
62
|
+
path = expand_template_path(format)
|
63
|
+
File.read(path)
|
64
64
|
end
|
65
65
|
|
66
|
-
# Internal:
|
67
|
-
|
68
|
-
|
66
|
+
# Internal: Expands the path to the default stylesheet for the given format.
|
67
|
+
#
|
68
|
+
# Returns the path as a String.
|
69
|
+
def self.expand_template_path(format)
|
70
|
+
File.expand_path("../stylesheets/template.#{format}.erb", __FILE__)
|
69
71
|
end
|
70
72
|
|
71
|
-
|
72
|
-
|
73
|
-
|
73
|
+
protected
|
74
|
+
|
75
|
+
def template_options
|
76
|
+
@options.merge(destination: @destination, cli_options: Spriteful.options)
|
74
77
|
end
|
75
78
|
|
76
|
-
# Internal:
|
77
|
-
def
|
78
|
-
|
79
|
+
# Internal: returns the 'rails' flag.
|
80
|
+
def rails?
|
81
|
+
@rails
|
79
82
|
end
|
80
83
|
|
81
84
|
# Internal: defines the file extension to be used with
|
@@ -100,38 +103,5 @@ module Spriteful
|
|
100
103
|
"_#{sprite.name}"
|
101
104
|
end
|
102
105
|
end
|
103
|
-
|
104
|
-
# Internal: sanitizes the 'name' of a given object to
|
105
|
-
# be used as a CSS selector class.
|
106
|
-
#
|
107
|
-
# Returns a 'String'.
|
108
|
-
def class_name_for(object)
|
109
|
-
object.name.split('.').first.downcase.tr('_', '-')
|
110
|
-
end
|
111
|
-
|
112
|
-
# Internal: computes a relative path between the sprite
|
113
|
-
# path and the stylesheet expected location.
|
114
|
-
#
|
115
|
-
# Returns a 'String'.
|
116
|
-
def image_url(sprite)
|
117
|
-
path = Pathname.new(sprite.path)
|
118
|
-
if @rails
|
119
|
-
"sprites/#{sprite.filename}"
|
120
|
-
elsif @root
|
121
|
-
"/#{path.relative_path_from(@root)}"
|
122
|
-
else
|
123
|
-
path.relative_path_from(@destination)
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
# Internal: Gets an embeddable Data URI of the image if it
|
128
|
-
# is a SVG image.
|
129
|
-
#
|
130
|
-
# Returns a String.
|
131
|
-
def data_uri(image)
|
132
|
-
if image.svg?
|
133
|
-
%['data:image/svg+xml;base64,#{Base64.encode64(image.blob).gsub(/\r?\n/, '')}']
|
134
|
-
end
|
135
|
-
end
|
136
106
|
end
|
137
107
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
/*
|
2
2
|
* This Stylesheet was generated by the 'spriteful' gem, with the following options:
|
3
3
|
<%- if Spriteful.options -%>
|
4
|
-
* 'spriteful <%=
|
4
|
+
* 'spriteful <%= cli_options.join(' ') %>'.
|
5
5
|
<%- end -%>
|
6
6
|
* Below there are several CSS classes to use the '<%= sprite.name %>'
|
7
7
|
* sprite on you HTML code, as in:
|
@@ -1,7 +1,7 @@
|
|
1
1
|
// ============================================================================
|
2
2
|
// This Stylesheet was generated by the 'spriteful' gem, with the following options:
|
3
3
|
<%- if Spriteful.options -%>
|
4
|
-
// 'spriteful <%=
|
4
|
+
// 'spriteful <%= cli_options.join(' ') %>'.
|
5
5
|
<%- end -%>
|
6
6
|
<%- if mixin? -%>
|
7
7
|
// Below there are several [Mixin Directives]
|
@@ -0,0 +1,113 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require 'pathname'
|
3
|
+
|
4
|
+
module Spriteful
|
5
|
+
# Public: The Template class is the public API available in the ERB templates
|
6
|
+
# that will render a CSS/SCSS stylesheet for a sprite.
|
7
|
+
class Template
|
8
|
+
# Public: Gets the sprite object that is being rendered with this template.
|
9
|
+
attr_reader :sprite
|
10
|
+
|
11
|
+
# Public: Gets the command line options used to create the current sprite.
|
12
|
+
attr_reader :cli_options
|
13
|
+
|
14
|
+
# Public: Initializes a Template object.
|
15
|
+
#
|
16
|
+
# sprite - A instance of the Spriteful::Sprite object associated to this
|
17
|
+
# template.
|
18
|
+
# options - The Hash options that configure this template (default: {}):
|
19
|
+
# :mixin - A flag marking if the template should generate SCSS
|
20
|
+
# mixins instead of placeholders.
|
21
|
+
# :rails - A flag marking if the template is being generated in a
|
22
|
+
# Rails app.
|
23
|
+
# :root - Root folder from where the generate stylesheets will be
|
24
|
+
# served.
|
25
|
+
# :destination - Folder where styleshee will live.
|
26
|
+
def initialize(sprite, options = {})
|
27
|
+
@sprite = sprite
|
28
|
+
@options = options
|
29
|
+
@destination = Pathname.new(options[:destination])
|
30
|
+
@cli_options = options[:cli_options]
|
31
|
+
|
32
|
+
if @options[:root]
|
33
|
+
@root = Pathname.new(File.expand_path(options[:root]))
|
34
|
+
else
|
35
|
+
@root = nil
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Public: sanitizes the 'name' of a given object to be used as a CSS selector
|
40
|
+
# class.
|
41
|
+
#
|
42
|
+
# object - A Spriteful::Sprite or Spriteful::Image instance.
|
43
|
+
#
|
44
|
+
# Returns a String.
|
45
|
+
def class_name_for(object)
|
46
|
+
object.name.split('.').first.downcase.tr('_', '-')
|
47
|
+
end
|
48
|
+
|
49
|
+
# Public: Gets the extension prefix for the SCSS selector, based on the
|
50
|
+
# ':mixin' option.
|
51
|
+
#
|
52
|
+
# Returns a String.
|
53
|
+
def extension_prefix
|
54
|
+
mixin? ? '@mixin ' : '%'
|
55
|
+
end
|
56
|
+
|
57
|
+
# Internal: Gets the extension strategy for the SCSS selector, based on the
|
58
|
+
# ':mixin' option.
|
59
|
+
#
|
60
|
+
# Returns a String.
|
61
|
+
def extension_strategy
|
62
|
+
mixin? ? '@include ' : '@extend %'
|
63
|
+
end
|
64
|
+
|
65
|
+
# Public: Gets the ':mixin' flag.
|
66
|
+
def mixin?
|
67
|
+
!!@options[:mixin]
|
68
|
+
end
|
69
|
+
|
70
|
+
# Public: Gets the ':rails' flag.
|
71
|
+
def rails?
|
72
|
+
!!@options[:rails]
|
73
|
+
end
|
74
|
+
|
75
|
+
# Public: computes a relative path between the sprite path and the stylesheet
|
76
|
+
# expected location.
|
77
|
+
#
|
78
|
+
# sprite - A Spriteful::Sprite instance.
|
79
|
+
#
|
80
|
+
# Returns a String.
|
81
|
+
def image_url(sprite)
|
82
|
+
path = Pathname.new(sprite.path)
|
83
|
+
if rails?
|
84
|
+
"sprites/#{sprite.filename}"
|
85
|
+
elsif @root
|
86
|
+
"/#{path.relative_path_from(@root)}"
|
87
|
+
else
|
88
|
+
path.relative_path_from(@destination).to_s
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
# Public: Gets an embeddable Data URI of the image if it is a SVG image.
|
93
|
+
#
|
94
|
+
# image - A Spriteful::Image instance.
|
95
|
+
#
|
96
|
+
# Returns a String.
|
97
|
+
def data_uri(image)
|
98
|
+
if image.svg?
|
99
|
+
"data:image/svg+xml;base64,#{Base64.encode64(image.blob).gsub(/\r?\n/, '')}"
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
# Public: Renders the given source ERB template string in the context of the
|
104
|
+
# template object.
|
105
|
+
#
|
106
|
+
# source - A String containing the ERB template.
|
107
|
+
#
|
108
|
+
# Returns a String.
|
109
|
+
def render(source)
|
110
|
+
ERB.new(source, nil, '-').result(binding)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
data/lib/spriteful/version.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
/*
|
2
|
+
* This is a custom template.
|
3
|
+
*/
|
4
|
+
|
5
|
+
.my-custom-template-<%= class_name_for(sprite) %> {
|
6
|
+
<% if rails? -%>
|
7
|
+
background-image: url(<%%= image_url('<%= image_url(sprite) %>') %>);
|
8
|
+
<% else -%>
|
9
|
+
background-image: url(<%= image_url(sprite) %>);
|
10
|
+
<% end -%>
|
11
|
+
background-repeat: no-repeat;
|
12
|
+
}
|
13
|
+
<% sprite.each_image do |image| %>
|
14
|
+
.my-custom-template-<%= class_name_for(sprite) %>.<%= class_name_for(image) %> {
|
15
|
+
background-position: <%= image.left %>px <%= image.top %>px;
|
16
|
+
}
|
17
|
+
<% if image.svg? %>
|
18
|
+
.svg .my-custom-template-<%= class_name_for(sprite) %>.<%= class_name_for(image) %> {
|
19
|
+
background-image: url(<%= data_uri(image) %>);
|
20
|
+
background-position: 0 0;
|
21
|
+
}
|
22
|
+
<% end -%>
|
23
|
+
<% end %>
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spriteful::Template do
|
4
|
+
let(:sprite) { double }
|
5
|
+
let(:options) { { destination: File.expand_path('tmp/output') } }
|
6
|
+
subject(:template) { Spriteful::Template.new(sprite, options) }
|
7
|
+
|
8
|
+
describe '#cli_options' do
|
9
|
+
it 'returns the cli_options provided in the options' do
|
10
|
+
options[:cli_options] = %w(one two three)
|
11
|
+
expect(template.cli_options).to eq(%w(one two three))
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#class_name_for' do
|
16
|
+
it 'formats the object name into a suitable CSS selector name' do
|
17
|
+
thing = double(name: 'Thing_name.jpg')
|
18
|
+
expect(template.class_name_for(thing)).to eq('thing-name')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#extension_prefix' do
|
23
|
+
it 'returns the prefix to be used when defining the sprite CSS selector' do
|
24
|
+
expect(template.extension_prefix).to eq('%')
|
25
|
+
options[:mixin] = true
|
26
|
+
expect(template.extension_prefix).to eq('@mixin ')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#extension_strategy' do
|
31
|
+
it 'returns prefix to be used when extending the SCSS selector' do
|
32
|
+
expect(template.extension_strategy).to eq('@extend %')
|
33
|
+
options[:mixin] = true
|
34
|
+
expect(template.extension_strategy).to eq('@include ')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#mixin?' do
|
39
|
+
it 'returns true when the :mixin flag is true' do
|
40
|
+
options[:mixin] = true
|
41
|
+
expect(template.mixin?).to be(true)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#rails?' do
|
46
|
+
it 'returns true when the :rails flag is true' do
|
47
|
+
options[:rails] = true
|
48
|
+
expect(template.rails?).to be(true)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '#image_url' do
|
53
|
+
it 'returns a path under sprites when the :rails flag is present' do
|
54
|
+
sprite = double(path: '/path', filename: 'icons.png')
|
55
|
+
options[:rails] = true
|
56
|
+
|
57
|
+
expect(template.image_url(sprite)).to eq('sprites/icons.png')
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'returns an absolute path when the :root option is given' do
|
61
|
+
sprite = double(path: File.expand_path('tmp/sprites/icons.png'))
|
62
|
+
options[:root] = Pathname.new(File.expand_path('tmp'))
|
63
|
+
|
64
|
+
expect(template.image_url(sprite)).to eq('/sprites/icons.png')
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'returns the sprite path relative to the destination path' do
|
68
|
+
sprite = double(path: File.expand_path('tmp/sprites/icons.png'))
|
69
|
+
|
70
|
+
expect(template.image_url(sprite)).to eq('../sprites/icons.png')
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe '#data_uri' do
|
75
|
+
it 'returns a Base64 encoded String for the SVG image' do
|
76
|
+
image = double(svg?: true, blob: '<svg />')
|
77
|
+
expect(template.data_uri(image)).to eq('data:image/svg+xml;base64,PHN2ZyAvPg==')
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe '#render' do
|
82
|
+
it 'renders the given ERB string in the template context' do
|
83
|
+
erb = 'ZOMG <%= self.class.name %>'
|
84
|
+
|
85
|
+
expect(template.render(erb)).to eq('ZOMG Spriteful::Template')
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
data/spec/stylesheet_spec.rb
CHANGED
@@ -4,6 +4,7 @@ describe Spriteful::Stylesheet do
|
|
4
4
|
let(:source) { File.expand_path('spec/fixtures/simple') }
|
5
5
|
let(:destination) { File.expand_path('tmp') }
|
6
6
|
let(:sprite) { Spriteful::Sprite.new(source, destination) }
|
7
|
+
let(:template) { File.expand_path('spec/fixtures/template.erb') }
|
7
8
|
|
8
9
|
describe '#render' do
|
9
10
|
it 'renders the CSS for the given sprite' do
|
@@ -71,5 +72,17 @@ describe Spriteful::Stylesheet do
|
|
71
72
|
expect(output).to match(/^ .svg & \{/)
|
72
73
|
end
|
73
74
|
end
|
75
|
+
|
76
|
+
describe 'Custom templates' do
|
77
|
+
it 'renders the CSS using a custom template' do
|
78
|
+
stylesheet = Spriteful::Stylesheet.new(sprite, destination, format: 'scss', template: template)
|
79
|
+
output = stylesheet.render
|
80
|
+
|
81
|
+
expect(output).to match('This is a custom template.')
|
82
|
+
expect(output).to match(/.my-custom-template-simple \{/)
|
83
|
+
expect(output).to match(/.my-custom-template-simple.blue \{/)
|
84
|
+
expect(output).to match(/.my-custom-template-simple.red \{/)
|
85
|
+
end
|
86
|
+
end
|
74
87
|
end
|
75
88
|
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.
|
4
|
+
version: 0.3.0.beta1
|
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-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -133,14 +133,17 @@ files:
|
|
133
133
|
- lib/spriteful/stylesheet.rb
|
134
134
|
- lib/spriteful/stylesheets/template.css.erb
|
135
135
|
- lib/spriteful/stylesheets/template.scss.erb
|
136
|
+
- lib/spriteful/template.rb
|
136
137
|
- lib/spriteful/version.rb
|
137
138
|
- spec/fixtures/simple/blue.png
|
138
139
|
- spec/fixtures/simple/red.png
|
139
140
|
- spec/fixtures/svg/green.svg
|
140
141
|
- spec/fixtures/svg/red.png
|
142
|
+
- spec/fixtures/template.erb
|
141
143
|
- spec/image_spec.rb
|
142
144
|
- spec/spec_helper.rb
|
143
145
|
- spec/sprite_spec.rb
|
146
|
+
- spec/spriteful/template_spec.rb
|
144
147
|
- spec/stylesheet_spec.rb
|
145
148
|
homepage: https://github.com/lucasmazza/spriteful
|
146
149
|
licenses:
|
@@ -157,9 +160,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
157
160
|
version: '0'
|
158
161
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
159
162
|
requirements:
|
160
|
-
- - "
|
163
|
+
- - ">"
|
161
164
|
- !ruby/object:Gem::Version
|
162
|
-
version:
|
165
|
+
version: 1.3.1
|
163
166
|
requirements: []
|
164
167
|
rubyforge_project:
|
165
168
|
rubygems_version: 2.2.2
|
@@ -171,7 +174,9 @@ test_files:
|
|
171
174
|
- spec/fixtures/simple/red.png
|
172
175
|
- spec/fixtures/svg/green.svg
|
173
176
|
- spec/fixtures/svg/red.png
|
177
|
+
- spec/fixtures/template.erb
|
174
178
|
- spec/image_spec.rb
|
175
179
|
- spec/spec_helper.rb
|
176
180
|
- spec/sprite_spec.rb
|
181
|
+
- spec/spriteful/template_spec.rb
|
177
182
|
- spec/stylesheet_spec.rb
|