spritely 0.2.6 → 0.2.7

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: 90447c2da39a04f55744534835e457eb6ccef146
4
- data.tar.gz: b7e5df3bc4fc4133124b4ba24ca73c7bf015320b
3
+ metadata.gz: 547b537b0bb23044c585abf41002bf689d94d3af
4
+ data.tar.gz: dede178e411e13338852a0e331fab4ca7da38049
5
5
  SHA512:
6
- metadata.gz: 7b62886dded040842efeabc170544813946e89d7fb5664f432bacde4919ae1f9f1495dcedd6e8d59a390821bebc84e1be8052bd71306a98a5c35588a9294515d
7
- data.tar.gz: 42cfd290b76bbab9092ea2a646718d4d16e9319c0b92c2f5695c5b2199fafc471b7f0d1eda8d5c1b5c7444509e13327a69a36a4b599ca4b0d4ae8ee6f43ba367
6
+ metadata.gz: bd3f6cb6c50ef2404ac88f22ce1ac523388d0ab5a20b2d36923c3a958a44f02a6cc8ebca4b3b0d260345afe7efa999baecfa227d143fd09cbc6dd877baabc457
7
+ data.tar.gz: cd38facbc1ac5ce4a817300633b8a80ad8e193e08e8597ce65eb88d51894ffd51d502aa379952c1c3f795966f47bbc367a5c7bfe1013176404c7c8e3eaf104b1
@@ -4,7 +4,7 @@ module Spritely
4
4
  module SassFunctions
5
5
  def spritely_map(glob, kwargs = {})
6
6
  SpriteMap.create(glob.value, kwargs).tap do |sprite_map|
7
- reset_sprockets_directory_cache!
7
+ reset_sprockets_caches!(sprite_map)
8
8
  sprockets_context.depend_on(Spritely.directory)
9
9
  sprite_map.files.each do |file|
10
10
  sprockets_context.depend_on(file)
@@ -60,8 +60,12 @@ module Spritely
60
60
  sprite_map.find(image_name.value) || raise(Sass::SyntaxError, "No image '#{image_name.value}' found in sprite map '#{sprite_map.name}'.")
61
61
  end
62
62
 
63
- def reset_sprockets_directory_cache!
64
- sprockets_context.environment.send(:trail).instance_variable_get(:@entries).delete(Spritely.directory.to_s)
63
+ def reset_sprockets_caches!(sprite_map)
64
+ sprockets_environment.instance_variable_get(:@assets).delete_if { |_, asset| asset.pathname == sprite_map.filename }
65
+ sprockets_environment.send(:trail).tap do |trail|
66
+ trail.instance_variable_get(:@entries).delete(Spritely.directory.to_s)
67
+ trail.instance_variable_get(:@stats).delete(sprite_map.filename.to_s)
68
+ end
65
69
  end
66
70
  end
67
71
  end
@@ -9,7 +9,7 @@ module Sprockets
9
9
  class Manifest
10
10
  def compile_with_sprites(*args)
11
11
  compile_without_sprites(*args)
12
- Dir.glob(Spritely.directory.join('*.png')).each(&method(:compile_without_sprites))
12
+ compile_without_sprites(*Dir.glob(Spritely.directory.join('*.png')))
13
13
  end
14
14
 
15
15
  alias_method_chain :compile, :sprites
@@ -1,3 +1,3 @@
1
1
  module Spritely
2
- VERSION = "0.2.6"
2
+ VERSION = "0.2.7"
3
3
  end
@@ -0,0 +1,26 @@
1
+ $application-sprite: spritely-map("application/*.png",
2
+ $background-repeat: true,
3
+ $football-spacing: 100px,
4
+ $mario-spacing: 10px,
5
+ $mario-position: right,
6
+ $spacing: 5px
7
+ );
8
+
9
+ body {
10
+ background-image: spritely-url($application-sprite);
11
+ background-position: spritely-position($application-sprite, "background");
12
+ }
13
+
14
+ #mario {
15
+ background-image: spritely-url($application-sprite);
16
+ background-position: spritely-position($application-sprite, "mario");
17
+ width: spritely-width($application-sprite, "mario");
18
+ height: spritely-height($application-sprite, "mario");
19
+ }
20
+
21
+ #arrow {
22
+ background-image: spritely-url($application-sprite);
23
+ background-position: spritely-position($application-sprite, "dropdown-arrow");
24
+ width: spritely-width($application-sprite, "dropdown-arrow");
25
+ height: spritely-height($application-sprite, "dropdown-arrow");
26
+ }
@@ -34,4 +34,12 @@ describe 'Precompilation', :integration do
34
34
  expect(File).to exist(File.join('app', 'assets', 'images', 'sprites', 'application.png'))
35
35
  expect(File).to exist(File.join('app', 'assets', 'images', 'sprites', 'foo.png'))
36
36
  end
37
+
38
+ it 'should correctly compile a new sprite image and CSS when files change' do
39
+ compile_assets
40
+ FileUtils.cp_r "#{__dir__}/../fixtures/rails-app-changes/.", "."
41
+ compile_assets
42
+ sprite_files = Dir.glob(File.join('public', 'assets', 'sprites', 'application-*.png'))
43
+ expect(sprite_files.length).to eq(2)
44
+ end
37
45
  end
@@ -1,9 +1,11 @@
1
1
  require 'spec_helper'
2
2
  require 'sprockets'
3
+ require 'ostruct'
3
4
 
4
5
  describe Spritely::SassFunctions do
5
6
  class SpriteMapDouble < Sass::Script::Literal
6
7
  def name; 'test'; end
8
+ def filename; 'test.png'; end
7
9
  def files; []; end
8
10
  end
9
11
 
@@ -25,17 +27,19 @@ describe Spritely::SassFunctions do
25
27
  end
26
28
  end
27
29
 
28
- shared_examples "a sprite function that resets the sprockets directory cache" do
29
- it 'should clear out the trail entries' do
30
+ shared_examples "a sprite function that resets the sprockets directory caches" do
31
+ it 'should clear out the trail caches' do
30
32
  subject
33
+ expect(environment.instance_variable_get(:@assets).length).to eq(0)
31
34
  expect(environment.send(:trail).instance_variable_get(:@entries)).to_not have_key(directory)
35
+ expect(environment.send(:trail).instance_variable_get(:@stats)).to_not have_key('test.png')
32
36
  end
33
37
  end
34
38
 
35
39
  describe '#spritely_url' do
36
40
  subject { evaluate(".background-image { background-image: spritely-url(spritely-map('test/*.png')); }") }
37
41
 
38
- it_should_behave_like "a sprite function that resets the sprockets directory cache"
42
+ it_should_behave_like "a sprite function that resets the sprockets directory caches"
39
43
 
40
44
  it { should eq(".background-image {\n background-image: url(sprites/test.png); }\n") }
41
45
  end
@@ -44,7 +48,7 @@ describe Spritely::SassFunctions do
44
48
  subject { evaluate(".background-position { background-position: spritely-position(spritely-map('test/*.png'), 'bar'); }") }
45
49
 
46
50
  it_should_behave_like "a sprite function that checks image existence"
47
- it_should_behave_like "a sprite function that resets the sprockets directory cache"
51
+ it_should_behave_like "a sprite function that resets the sprockets directory caches"
48
52
 
49
53
  it { should eq(".background-position {\n background-position: -10px -12px; }\n") }
50
54
 
@@ -59,7 +63,7 @@ describe Spritely::SassFunctions do
59
63
  subject { evaluate(".background { background: spritely-background(spritely-map('test/*.png'), 'bar'); }") }
60
64
 
61
65
  it_should_behave_like "a sprite function that checks image existence"
62
- it_should_behave_like "a sprite function that resets the sprockets directory cache"
66
+ it_should_behave_like "a sprite function that resets the sprockets directory caches"
63
67
 
64
68
  it { should eq(".background {\n background: url(sprites/test.png) -10px -12px; }\n") }
65
69
  end
@@ -68,7 +72,7 @@ describe Spritely::SassFunctions do
68
72
  subject { evaluate(".width { width: spritely-width(spritely-map('test/*.png'), 'bar'); }") }
69
73
 
70
74
  it_should_behave_like "a sprite function that checks image existence"
71
- it_should_behave_like "a sprite function that resets the sprockets directory cache"
75
+ it_should_behave_like "a sprite function that resets the sprockets directory caches"
72
76
 
73
77
  it { should eq(".width {\n width: 25px; }\n") }
74
78
  end
@@ -77,7 +81,7 @@ describe Spritely::SassFunctions do
77
81
  subject { evaluate(".height { height: spritely-height(spritely-map('test/*.png'), 'bar'); }") }
78
82
 
79
83
  it_should_behave_like "a sprite function that checks image existence"
80
- it_should_behave_like "a sprite function that resets the sprockets directory cache"
84
+ it_should_behave_like "a sprite function that resets the sprockets directory caches"
81
85
 
82
86
  it { should eq(".height {\n height: 50px; }\n") }
83
87
  end
@@ -88,7 +92,9 @@ describe Spritely::SassFunctions do
88
92
 
89
93
  def environment
90
94
  @environment ||= Sprockets::Environment.new.tap do |environment|
95
+ environment.instance_variable_set(:@assets, {'test' => OpenStruct.new(pathname: 'test.png')})
91
96
  environment.send(:trail).instance_variable_set(:@entries, {'spritely-directory' => 'blah'})
97
+ environment.send(:trail).instance_variable_set(:@stats, {'test.png' => 'blah'})
92
98
  environment.context_class.class_eval do
93
99
  def asset_path(path, options = {})
94
100
  path
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.6
4
+ version: 0.2.7
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-19 00:00:00.000000000 Z
11
+ date: 2014-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chunky_png
@@ -177,6 +177,8 @@ files:
177
177
  - lib/spritely/sprockets/manifest.rb
178
178
  - lib/spritely/version.rb
179
179
  - spec/fixtures/correct-sprite.png
180
+ - spec/fixtures/rails-app-changes/app/assets/images/application/dropdown-arrow.png
181
+ - spec/fixtures/rails-app-changes/app/assets/stylesheets/sprites.css.scss
180
182
  - spec/fixtures/rails-app/app/assets/images/application/background.png
181
183
  - spec/fixtures/rails-app/app/assets/images/application/fool.png
182
184
  - spec/fixtures/rails-app/app/assets/images/application/football.png
@@ -234,6 +236,8 @@ test_files:
234
236
  - spec/fixtures/rails-app/app/assets/images/foo/fool.png
235
237
  - spec/fixtures/rails-app/app/assets/stylesheets/sprites.css.scss
236
238
  - spec/fixtures/rails-app/app/assets/stylesheets/sprites_2.css.scss
239
+ - spec/fixtures/rails-app-changes/app/assets/images/application/dropdown-arrow.png
240
+ - spec/fixtures/rails-app-changes/app/assets/stylesheets/sprites.css.scss
237
241
  - spec/fixtures/test/foo.png
238
242
  - spec/generators/spritely/install_generator_spec.rb
239
243
  - spec/integration/precompilation_spec.rb