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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 41e28bf3c683cf51ded0b5bf335e09274ba130c0
4
- data.tar.gz: 0f2b23688154ab07300b3d14d7184d84af3d2eec
3
+ metadata.gz: 5b00a4ad9457e4493951eac13ca827af28207421
4
+ data.tar.gz: 2d89d336b23c78c6c4db583aaf4e37bf0fe3f958
5
5
  SHA512:
6
- metadata.gz: 95f01f44df4c8d559fa3f2fbffa5cd5d972354d3471b025507747d99fc2d2e09cf9774062665e22586417c032f1763754779f4bfca9c1a3662b1cf1621166211
7
- data.tar.gz: a23a5f9d76f0a8c34d127c2963ce740174c54b8efff1c633c3693c1b17e6b3d184404feb03b6f0de0c181a9e5c4c89d05d1ead3b049f9af3c949bc3bd8a813f0
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
- FileUtils.mkdir_p(Spritely.directory)
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)
@@ -1,3 +1,3 @@
1
1
  module Spritely
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
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('app', 'assets', 'images', 'sprites')
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?(File.join('app', 'assets', 'images', 'sprites', 'application.png'))).to be_truthy
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('spritely-directory')
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('spritely-directory')
31
+ expect(environment.send(:trail).instance_variable_get(:@entries)).to_not have_key(directory)
31
32
  end
32
33
  end
33
34
 
@@ -8,8 +8,12 @@ describe Spritely do
8
8
  end
9
9
 
10
10
  describe '.directory' do
11
- before { stub_const('::Rails', double(root: File)) }
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
- before { allow(Spritely).to receive(:directory).and_return('blah') }
21
+ let(:directory_exists) { true }
22
22
 
23
- it 'should mkdir -p' do
24
- expect(FileUtils).to receive(:mkdir_p).with('blah')
25
- subject.ensure_directory_exists!
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.1
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-08 00:00:00.000000000 Z
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