spritely 0.3.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/spritely.rb +11 -34
- data/lib/spritely/collection.rb +12 -11
- data/lib/spritely/engine.rb +4 -0
- data/lib/spritely/generators/base.rb +0 -16
- data/lib/spritely/generators/chunky_png.rb +1 -4
- data/lib/spritely/image_set.rb +2 -2
- data/lib/spritely/sass_functions.rb +30 -29
- data/lib/spritely/sprite_map.rb +14 -31
- data/lib/spritely/sprockets/preprocessor.rb +65 -0
- data/lib/spritely/sprockets/transformer.rb +43 -0
- data/lib/spritely/version.rb +1 -1
- data/spec/fixtures/rails-app-changes/app/assets/stylesheets/sprites.css.scss +10 -18
- data/spec/fixtures/rails-app/app/assets/images/sprites/application.png.sprite +5 -0
- data/spec/fixtures/rails-app/app/assets/images/sprites/foo.png.sprite +1 -0
- data/spec/fixtures/rails-app/app/assets/stylesheets/sprites.css.scss +6 -14
- data/spec/fixtures/rails-app/app/assets/stylesheets/sprites_2.css.scss +4 -6
- data/spec/integration/precompilation_spec.rb +2 -14
- data/spec/spec_helper.rb +0 -4
- data/spec/spritely/collection_spec.rb +9 -8
- data/spec/spritely/generators/chunky_png_spec.rb +8 -13
- data/spec/spritely/image_set_spec.rb +2 -8
- data/spec/spritely/sass_functions_spec.rb +38 -37
- data/spec/spritely/sprite_map_spec.rb +16 -52
- data/spec/spritely/sprockets/preprocessor_spec.rb +33 -0
- data/spec/support/rails_app_helpers.rb +4 -5
- metadata +38 -49
- data/lib/generators/spritely/install_generator.rb +0 -17
- data/lib/spritely/adapters/sprockets_2.rb +0 -13
- data/lib/spritely/adapters/sprockets_3.rb +0 -11
- data/lib/spritely/cache.rb +0 -51
- data/lib/spritely/options.rb +0 -59
- data/lib/spritely/sprockets/manifest.rb +0 -20
- data/spec/generators/spritely/install_generator_spec.rb +0 -28
- data/spec/spritely/cache_spec.rb +0 -24
- data/spec/spritely/options_spec.rb +0 -29
- data/spec/spritely_spec.rb +0 -41
- data/spec/support/shared_examples.rb +0 -40
- data/spec/support/shared_examples/sprockets_2_sass_functions_helpers.rb +0 -13
- data/spec/support/shared_examples/sprockets_3_sass_functions_helpers.rb +0 -15
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'sprockets/manifest'
|
2
|
-
|
3
|
-
module Spritely
|
4
|
-
# In order to hook into Sprockets' asset compilation appropriately, we must
|
5
|
-
# chain our own implementation of `compile`. Our extension calls up to the
|
6
|
-
# original, and then performs the same action on the generated sprite images,
|
7
|
-
# forcing the sprites to be part of the compiled asset manifest.
|
8
|
-
module Sprockets
|
9
|
-
module Manifest
|
10
|
-
def compile(*args)
|
11
|
-
super
|
12
|
-
super(*Dir.glob(Spritely.directory.join('*.png')))
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
# TODO: Once we drop support for Ruby 2.0, stop using `send`.
|
17
|
-
# `Module#prepend` was made public in Ruby 2.1.
|
18
|
-
::Sprockets::Manifest.send(:prepend, Manifest)
|
19
|
-
end
|
20
|
-
end
|
@@ -1,28 +0,0 @@
|
|
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
|
data/spec/spritely/cache_spec.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Spritely::Cache do
|
4
|
-
let(:filename) { File.join(__dir__, '..', 'fixtures', 'test', 'foo.png') }
|
5
|
-
|
6
|
-
subject { Spritely::Cache.new(filename) }
|
7
|
-
|
8
|
-
before { stub_const('Spritely::VERSION', 'foobar') }
|
9
|
-
|
10
|
-
its(:filename) { should eq(filename) }
|
11
|
-
its(:key) { should eq('527272411fe99a8b5e9da254ac0aae88') }
|
12
|
-
|
13
|
-
describe '.generate' do
|
14
|
-
it 'should collect the cache_key values and digest them' do
|
15
|
-
expect(Spritely::Cache.generate(double(cache_key: 'asdf'), double(cache_key: 'hjkl'))).to eq('566ddc3d81de1f58fb37ecf29082d0f5')
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
describe '.busted?' do
|
20
|
-
it 'should check the expected value against the real value' do
|
21
|
-
expect(Spritely::Cache).to be_busted(filename, 'asdf')
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Spritely::Options do
|
4
|
-
let(:hash) { {
|
5
|
-
'some_new_image_spacing' => Sass::Script::Number.new(789),
|
6
|
-
'some_new_image_x' => Sass::Script::Number.new(123),
|
7
|
-
'some_new_image_y' => Sass::Script::Number.new(456),
|
8
|
-
'some_new_image_position' => Sass::Script::String.new('right'),
|
9
|
-
'another_image_repeat' => Sass::Script::Bool.new(true),
|
10
|
-
'yet_another_image_repeat' => Sass::Script::Bool.new(false),
|
11
|
-
'spacing' => Sass::Script::Number.new(901),
|
12
|
-
'position' => Sass::Script::String.new('left')
|
13
|
-
} }
|
14
|
-
|
15
|
-
subject(:options) { Spritely::Options.new(hash) }
|
16
|
-
|
17
|
-
its(:inspect) { should eq("#<Spritely::Options global_options=#{{spacing: 901, position: 'left'}} options=#{{'some_new_image' => {spacing: 789, position: 'right', x: 123, y: 456}, 'another_image' => {spacing: 901, position: 'left', repeat: true}, 'yet_another_image' => {spacing: 901, position: 'left', repeat: false}}}>") }
|
18
|
-
its(:cache_key) { should eq({"some_new_image_spacing" => 789, "some_new_image_x" => 123, "some_new_image_y" => 456, "some_new_image_position" => 'right', "another_image_repeat" => true, "yet_another_image_repeat" => false, "spacing" => 901, "position" => 'left'}.to_s) }
|
19
|
-
|
20
|
-
its(['some-new-image']) { should eq({spacing: 789, position: 'right', x: 123, y: 456}) }
|
21
|
-
its(['another-image']) { should eq({spacing: 901, repeat: true, position: 'left'}) }
|
22
|
-
its(['yet-another-image']) { should eq({spacing: 901, repeat: false, position: 'left'}) }
|
23
|
-
|
24
|
-
describe '#[]' do
|
25
|
-
it 'should fall back to an empty hash' do
|
26
|
-
expect(options['unknown']).to eq({spacing: 901, position: 'left'})
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
data/spec/spritely_spec.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Spritely do
|
4
|
-
describe '.environment' do
|
5
|
-
let(:application) { double(assets: 'assets environment') }
|
6
|
-
|
7
|
-
before { stub_const('::Rails', double(application: application)) }
|
8
|
-
|
9
|
-
its(:environment) { should eq('assets environment') }
|
10
|
-
|
11
|
-
context 'sprockets-rails version 3' do
|
12
|
-
before { stub_const('Sprockets::Rails::VERSION', '3.0.0') }
|
13
|
-
|
14
|
-
its(:environment) { should eq('assets environment') }
|
15
|
-
|
16
|
-
context 'the Rails application assets environment is nil' do
|
17
|
-
let(:application) { double(assets: nil) }
|
18
|
-
|
19
|
-
before { allow(::Sprockets::Railtie).to receive(:build_environment).with(application).and_return('new assets environment') }
|
20
|
-
|
21
|
-
its(:environment) { should eq('new assets environment') }
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
describe '.directory' do
|
27
|
-
before { stub_const('::Rails', double(root: Pathname.new('foo/bar'))) }
|
28
|
-
|
29
|
-
its(:directory) { should eq(Pathname.new('foo/bar/app/assets/images/sprites')) }
|
30
|
-
end
|
31
|
-
|
32
|
-
describe '.relative_folder_path' do
|
33
|
-
its(:relative_folder_path) { should eq(Pathname.new('app/assets/images/sprites')) }
|
34
|
-
end
|
35
|
-
|
36
|
-
describe '.sprockets_version' do
|
37
|
-
before { stub_const('Sprockets::VERSION', '1.0') }
|
38
|
-
|
39
|
-
its(:sprockets_version) { should eq(1) }
|
40
|
-
end
|
41
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
shared_examples "a generator" do
|
2
|
-
let(:images) { [OpenStruct.new(data: 'first image data', left: 1, top: 10), OpenStruct.new(data: 'second image data', left: 2, top: 20)] }
|
3
|
-
let(:sprite_map) { double(images: images, width: 100, height: 200, filename: 'blah.png', cache_key: 'cachevalue') }
|
4
|
-
|
5
|
-
its(:sprite_map) { should eq(sprite_map) }
|
6
|
-
|
7
|
-
describe '.create!' do
|
8
|
-
let(:generator) { double }
|
9
|
-
|
10
|
-
before { allow(described_class).to receive(:new).with(sprite_map).and_return(generator) }
|
11
|
-
|
12
|
-
it 'should work some magic' do
|
13
|
-
expect(generator).to receive(:build!)
|
14
|
-
expect(generator).to receive(:ensure_directory_exists!)
|
15
|
-
expect(generator).to receive(:save!)
|
16
|
-
described_class.create!(sprite_map)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
describe '#ensure_directory_exists!' do
|
21
|
-
let(:directory_exists) { true }
|
22
|
-
|
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
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
module Sprockets2SassFunctionsHelpers
|
2
|
-
def evaluate(value)
|
3
|
-
Sprockets::ScssTemplate.new { value }.evaluate(sprockets_environment.context_class.new(sprockets_environment, nil, nil), nil)
|
4
|
-
end
|
5
|
-
|
6
|
-
def sprockets_environment
|
7
|
-
@sprockets_environment ||= Sprockets::Environment.new.tap do |sprockets_environment|
|
8
|
-
sprockets_environment.context_class.class_eval do
|
9
|
-
def asset_path(path, options = {}); path; end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module Sprockets3SassFunctionsHelpers
|
2
|
-
def evaluate(value)
|
3
|
-
Sprockets::ScssProcessor.call(environment: sprockets_environment, data: value, filename: "test.scss", metadata: {}, cache: Sprockets::Cache.new)[:data]
|
4
|
-
end
|
5
|
-
|
6
|
-
def sprockets_environment
|
7
|
-
@sprockets_environment ||= Sprockets::CachedEnvironment.new(Sprockets::Environment.new).tap do |sprockets_environment|
|
8
|
-
sprockets_environment.context_class.class_eval do
|
9
|
-
def depend_on(path); end
|
10
|
-
def depend_on_asset(path); end
|
11
|
-
def asset_path(path, options = {}); path; end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|