spritely 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/generators/spritely/install_generator.rb +17 -0
- data/lib/spritely/generators/base.rb +1 -1
- data/lib/spritely/sass_functions.rb +1 -0
- data/lib/spritely/version.rb +1 -1
- data/lib/spritely.rb +5 -1
- data/spec/generators/spritely/install_generator_spec.rb +28 -0
- data/spec/integration/precompilation_spec.rb +9 -1
- data/spec/spec_helper.rb +2 -0
- data/spec/spritely/sass_functions_spec.rb +3 -2
- data/spec/spritely_spec.rb +6 -2
- data/spec/support/rails_app_helpers.rb +2 -2
- data/spec/support/shared_examples.rb +16 -4
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b00a4ad9457e4493951eac13ca827af28207421
|
4
|
+
data.tar.gz: 2d89d336b23c78c6c4db583aaf4e37bf0fe3f958
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e84f5a25f0a49cd6ea73f59efe0261f630163595bdb7099fda42e5aa01afbab3f3989ba77a4e10bb7c002b97034c6d76e4017a5afe2403dfb663b9a93512542f
|
7
|
+
data.tar.gz: 7392bd00d2d4e4d0029f07c16a26b5c5a359e8b23716a35192db62f54ae666f030f722312c2d128f515e5566330676de591745a04833ef63dea40cc947b23c6c
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rails/generators/base'
|
2
|
+
|
3
|
+
module Spritely
|
4
|
+
module Generators
|
5
|
+
class InstallGenerator < ::Rails::Generators::Base
|
6
|
+
def create_empty_sprites_folder
|
7
|
+
empty_directory Spritely.relative_folder_path
|
8
|
+
create_file "#{Spritely.relative_folder_path}/.keep"
|
9
|
+
end
|
10
|
+
|
11
|
+
def add_sprites_folder_to_gitignore
|
12
|
+
create_file '.gitignore', skip: true
|
13
|
+
inject_into_file '.gitignore', "\n#{Spritely.relative_folder_path.join('*.png')}\n", after: /\z/
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -10,7 +10,7 @@ module Spritely
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def ensure_directory_exists!
|
13
|
-
|
13
|
+
raise("'#{Spritely.relative_folder_path}' doesn't exist. Run `rails generate spritely:install`.") unless File.exist?(Spritely.directory)
|
14
14
|
end
|
15
15
|
|
16
16
|
def build!
|
@@ -5,6 +5,7 @@ module Spritely
|
|
5
5
|
def spritely_map(glob, kwargs = {})
|
6
6
|
SpriteMap.create(glob.value, kwargs).tap do |sprite_map|
|
7
7
|
reset_sprockets_directory_cache!
|
8
|
+
sprockets_context.depend_on(Spritely.directory)
|
8
9
|
sprite_map.files.each do |file|
|
9
10
|
sprockets_context.depend_on(file)
|
10
11
|
sprockets_context.depend_on_asset(file)
|
data/lib/spritely/version.rb
CHANGED
data/lib/spritely.rb
CHANGED
@@ -8,6 +8,10 @@ module Spritely
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def self.directory
|
11
|
-
::Rails.root.join(
|
11
|
+
::Rails.root.join(relative_folder_path)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.relative_folder_path
|
15
|
+
Pathname.new(File.join('app', 'assets', 'images', 'sprites'))
|
12
16
|
end
|
13
17
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'generators/spritely/install_generator'
|
3
|
+
|
4
|
+
describe Spritely::Generators::InstallGenerator, :generator do
|
5
|
+
destination File.expand_path("../../../../tmp", __FILE__)
|
6
|
+
|
7
|
+
before do
|
8
|
+
prepare_destination
|
9
|
+
run_generator
|
10
|
+
end
|
11
|
+
|
12
|
+
subject { destination_root }
|
13
|
+
|
14
|
+
it { is_expected.to have_structure {
|
15
|
+
directory 'app' do
|
16
|
+
directory 'assets' do
|
17
|
+
directory 'images' do
|
18
|
+
directory 'sprites' do
|
19
|
+
file '.keep'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
file '.gitignore' do
|
25
|
+
contains 'app/assets/images/sprites/*.png'
|
26
|
+
end
|
27
|
+
} }
|
28
|
+
end
|
@@ -4,7 +4,7 @@ require 'active_support/core_ext/string'
|
|
4
4
|
describe 'Precompilation', :integration do
|
5
5
|
it 'should create the sprite in the right location' do
|
6
6
|
render_asset('sprites.css')
|
7
|
-
expect(File.exist
|
7
|
+
expect(File).to exist(File.join('app', 'assets', 'images', 'sprites', 'application.png'))
|
8
8
|
end
|
9
9
|
|
10
10
|
it 'should compile the correct-looking sprite file' do
|
@@ -26,4 +26,12 @@ describe 'Precompilation', :integration do
|
|
26
26
|
sprite_files = Dir.glob(File.join('public', 'assets', 'sprites', 'application-*.png'))
|
27
27
|
expect(sprite_files.length).to eq(1)
|
28
28
|
end
|
29
|
+
|
30
|
+
it 'should compile even if the sprite files no longer exist' do
|
31
|
+
compile_assets
|
32
|
+
FileUtils.rm_rf(Dir.glob(File.join('app', 'assets', 'images', 'sprites', '*.png')))
|
33
|
+
compile_assets
|
34
|
+
expect(File).to exist(File.join('app', 'assets', 'images', 'sprites', 'application.png'))
|
35
|
+
expect(File).to exist(File.join('app', 'assets', 'images', 'sprites', 'foo.png'))
|
36
|
+
end
|
29
37
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'rspec'
|
2
2
|
require 'rspec/its'
|
3
|
+
require 'generator_spec/generator_example_group'
|
3
4
|
require 'spritely'
|
4
5
|
|
5
6
|
require 'pry-byebug'
|
@@ -12,5 +13,6 @@ RSpec.configure do |config|
|
|
12
13
|
end
|
13
14
|
|
14
15
|
config.include RailsAppHelpers, :integration
|
16
|
+
config.include GeneratorSpec::GeneratorExampleGroup, :generator
|
15
17
|
config.around(:each, :integration) { |example| within_rails_app(&example) }
|
16
18
|
end
|
@@ -7,11 +7,12 @@ describe Spritely::SassFunctions do
|
|
7
7
|
def files; []; end
|
8
8
|
end
|
9
9
|
|
10
|
+
let(:directory) { __dir__ }
|
10
11
|
let(:sprite_map) { SpriteMapDouble.new }
|
11
12
|
let(:image) { double(left: 10, top: 12, width: 25, height: 50) }
|
12
13
|
|
13
14
|
before do
|
14
|
-
allow(Spritely).to receive(:directory).and_return(
|
15
|
+
allow(Spritely).to receive(:directory).and_return(directory)
|
15
16
|
allow(Spritely::SpriteMap).to receive(:create).and_return(sprite_map)
|
16
17
|
allow(sprite_map).to receive(:find).with('bar').and_return(image)
|
17
18
|
end
|
@@ -27,7 +28,7 @@ describe Spritely::SassFunctions do
|
|
27
28
|
shared_examples "a sprite function that resets the sprockets directory cache" do
|
28
29
|
it 'should clear out the trail entries' do
|
29
30
|
subject
|
30
|
-
expect(environment.send(:trail).instance_variable_get(:@entries)).to_not have_key(
|
31
|
+
expect(environment.send(:trail).instance_variable_get(:@entries)).to_not have_key(directory)
|
31
32
|
end
|
32
33
|
end
|
33
34
|
|
data/spec/spritely_spec.rb
CHANGED
@@ -8,8 +8,12 @@ describe Spritely do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
describe '.directory' do
|
11
|
-
before { stub_const('::Rails', double(root:
|
11
|
+
before { stub_const('::Rails', double(root: Pathname.new('foo/bar'))) }
|
12
12
|
|
13
|
-
its(:directory) { should eq('app/assets/images/sprites') }
|
13
|
+
its(:directory) { should eq(Pathname.new('foo/bar/app/assets/images/sprites')) }
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '.relative_folder_path' do
|
17
|
+
its(:relative_folder_path) { should eq(Pathname.new('app/assets/images/sprites')) }
|
14
18
|
end
|
15
19
|
end
|
@@ -3,8 +3,7 @@ module RailsAppHelpers
|
|
3
3
|
'--skip-active-record',
|
4
4
|
'--skip-test-unit',
|
5
5
|
'--skip-javascript',
|
6
|
-
'--skip-spring'
|
7
|
-
'--skip-git'
|
6
|
+
'--skip-spring'
|
8
7
|
]
|
9
8
|
|
10
9
|
def within_rails_app(&block)
|
@@ -19,6 +18,7 @@ module RailsAppHelpers
|
|
19
18
|
f.write("gem 'spritely', path: '#{__dir__}/../../'\n")
|
20
19
|
end
|
21
20
|
%x(bundle install)
|
21
|
+
%x(rails generate spritely:install)
|
22
22
|
FileUtils.cp_r "#{__dir__}/../fixtures/rails-app/.", "."
|
23
23
|
yield
|
24
24
|
end
|
@@ -18,11 +18,23 @@ shared_examples "a generator" do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
describe '#ensure_directory_exists!' do
|
21
|
-
|
21
|
+
let(:directory_exists) { true }
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
before do
|
24
|
+
allow(Spritely).to receive(:directory).and_return('blah')
|
25
|
+
allow(File).to receive(:exist?).with('blah').and_return(directory_exists)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should not raise an exception' do
|
29
|
+
expect { subject.ensure_directory_exists! }.to_not raise_error
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'the sprites folder does not exist' do
|
33
|
+
let(:directory_exists) { false }
|
34
|
+
|
35
|
+
it 'should raise an exception' do
|
36
|
+
expect { subject.ensure_directory_exists! }.to raise_error("'app/assets/images/sprites' doesn't exist. Run `rails generate spritely:install`.")
|
37
|
+
end
|
26
38
|
end
|
27
39
|
end
|
28
40
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spritely
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Robbin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chunky_png
|
@@ -142,6 +142,20 @@ dependencies:
|
|
142
142
|
- - ">="
|
143
143
|
- !ruby/object:Gem::Version
|
144
144
|
version: '0'
|
145
|
+
- !ruby/object:Gem::Dependency
|
146
|
+
name: generator_spec
|
147
|
+
requirement: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
type: :development
|
153
|
+
prerelease: false
|
154
|
+
version_requirements: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - ">="
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '0'
|
145
159
|
description:
|
146
160
|
email:
|
147
161
|
- alex@robbinsweb.biz
|
@@ -149,6 +163,7 @@ executables: []
|
|
149
163
|
extensions: []
|
150
164
|
extra_rdoc_files: []
|
151
165
|
files:
|
166
|
+
- lib/generators/spritely/install_generator.rb
|
152
167
|
- lib/spritely.rb
|
153
168
|
- lib/spritely/cache.rb
|
154
169
|
- lib/spritely/collection.rb
|
@@ -170,6 +185,7 @@ files:
|
|
170
185
|
- spec/fixtures/rails-app/app/assets/stylesheets/sprites.css.scss
|
171
186
|
- spec/fixtures/rails-app/app/assets/stylesheets/sprites_2.css.scss
|
172
187
|
- spec/fixtures/test/foo.png
|
188
|
+
- spec/generators/spritely/install_generator_spec.rb
|
173
189
|
- spec/integration/precompilation_spec.rb
|
174
190
|
- spec/integration/stylesheet_spec.rb
|
175
191
|
- spec/spec_helper.rb
|
@@ -219,6 +235,7 @@ test_files:
|
|
219
235
|
- spec/fixtures/rails-app/app/assets/stylesheets/sprites.css.scss
|
220
236
|
- spec/fixtures/rails-app/app/assets/stylesheets/sprites_2.css.scss
|
221
237
|
- spec/fixtures/test/foo.png
|
238
|
+
- spec/generators/spritely/install_generator_spec.rb
|
222
239
|
- spec/integration/precompilation_spec.rb
|
223
240
|
- spec/integration/stylesheet_spec.rb
|
224
241
|
- spec/spec_helper.rb
|