sprockets-preload 0.0.1 → 0.0.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: 9aa6c3e861748967179166f9e5eec2641432f274
4
- data.tar.gz: df369157c3ee8cefcda79d361c43fa5f26c5522f
3
+ metadata.gz: c109168d6d857d0d53ea555d65a80f4c6e6044fe
4
+ data.tar.gz: bd31241d93501635dae87cb3e284ebc4bd6862c8
5
5
  SHA512:
6
- metadata.gz: 724a9ba684c9a94d3ecea83615aa402fe54d7cbaf75df98553c3e306f876910c41b07e6bdbe8dd7d643f312af7ab783e15f1bd63bf6be31a1a889b44718ba795
7
- data.tar.gz: be1d272adb7cd4bfa2d77ae4528a04f64ad751c60fe78b5942588988228e7a9719159f5a544e4329c2f5ab417492d284052896b1864124a5b06f8354b6c406b5
6
+ metadata.gz: 88c35958ca2cd51ab0430b62c0a912c5f52283b84b74a07e5fac8f49e8bb00231a01fb5e925327f204ae11ddd9091e85e7430ecb936f1db7bcd7211a8b550831
7
+ data.tar.gz: 4e1d63162c5de636f99aeec6139cdbbe4db15451ccbc6f30fc390a8b2bb155d03d0c8c23b98f8b153ae745719aad5f8df4a845b2b2e6c58470376fde923fa747
data/README.md CHANGED
@@ -25,7 +25,7 @@ Let's make user experience smooth:
25
25
 
26
26
  1. Add `sprockets-preload` to your `Gemfile` and run `bundle install`
27
27
 
28
- 2. Change `//= include` to `//= preload` for the assets you want to detouch:
28
+ 2. Change `//= include` to `//= preload` for the assets you want to detach:
29
29
 
30
30
  ```javascript
31
31
  //= include helpers
@@ -37,7 +37,7 @@ Let's make user experience smooth:
37
37
  $ -> Front.start()
38
38
  ```
39
39
 
40
- 3. Delay initialization to the moment when detouched assets are loaded:
40
+ 3. Delay initialization to the moment when detached assets are loaded:
41
41
 
42
42
  ```javascript
43
43
  //= include helpers
@@ -71,7 +71,7 @@ Let's make user experience smooth:
71
71
  }
72
72
  ```
73
73
 
74
- 5. **IMPORTANT**: Rails development environment uses stub to ease debugging. Thus while things keep working, assets don't really get detouched. To force production-grade loading (just to make sure things work fine) add `//= preload!` to your manifest:
74
+ 5. **IMPORTANT**: Rails development environment uses stub to ease debugging. Thus while things keep working, assets don't really get detached. To force production-grade loading (just to make sure things work fine) add `//= preload!` to your manifest:
75
75
 
76
76
  ```javascript
77
77
  //= preload!
@@ -94,6 +94,10 @@ Let's make user experience smooth:
94
94
 
95
95
  Make sure to remove `//= preload!` when your tests are done.
96
96
 
97
+ -----------
98
+
99
+ By the way, there's also `//= preload_tree` directive that works similar to `//= require_tree`.
100
+
97
101
  ## Caching options
98
102
 
99
103
  To make loading progress tracking smooth and cache manually controllable, **Sprockets::Preload** uses `localStorage` to cache assets (it falls back to default browser cache automatically). **Sprockets** provides digests and logic-aware dependency system that work much better and much more predictable than more common default HTTP caching.
@@ -127,10 +131,14 @@ SprocketsPreload.progress = function(percent) {
127
131
 
128
132
  **Sprockets::Preload** does not depend on Rails. However it has proper rail-ties and is fully-functional on Rails out of box. If you want to use it outside of Rails with clean **Sprockets** – see `lib/sprockets/preload/engine.rb` for required initialization settings.
129
133
 
130
- ## Contributing
134
+ ## History
135
+
136
+ **Sprockets::Preload** is a mutated fork of [Joosy](http://joosy.ws) 1.x preloaders. For Node.js-based applications please refer to [Loada](https://github.com/inossidabile/loada).
137
+
138
+ ## Maintainers
139
+
140
+ * Boris Staal, [@inossidabile](http://staal.io)
141
+
142
+ ## License
131
143
 
132
- 1. Fork it
133
- 2. Create your feature branch (`git checkout -b my-new-feature`)
134
- 3. Commit your changes (`git commit -am 'Add some feature'`)
135
- 4. Push to the branch (`git push origin my-new-feature`)
136
- 5. Create new Pull Request
144
+ It is free software, and may be redistributed under the terms of MIT license.
@@ -4,22 +4,35 @@
4
4
  module Sprockets
5
5
  module Preload
6
6
  module DirectiveProcessor
7
- def process_preload_directive(path)
8
- if context.content_type != 'application/javascript'
9
- process_require_directive path
10
- else
7
+ def process_preload_directive(path, inherit=true)
8
+ # Other macroses like `#= preload_directory` can
9
+ # call require on their own behalf
10
+ process_require_directive path if inherit
11
+
12
+ if context.content_type == 'application/javascript'
11
13
  unless context._assets_to_preload
12
14
  process_require_directive 'sprockets/preload/load'
13
15
  context._assets_to_preload = []
14
16
  end
15
17
 
16
- context.require_asset path
17
18
  context.stub_asset path if context.preload?
18
-
19
19
  context._assets_to_preload.push path
20
20
  end
21
21
  end
22
22
 
23
+ def process_preload_directory_directive(path=".")
24
+ root = pathname.dirname.join(path).expand_path
25
+
26
+ process_require_directory_directive(path).each do |pathname|
27
+ pathname = root.join(pathname)
28
+ if pathname.to_s == self.file
29
+ next
30
+ elsif context.asset_requirable?(pathname)
31
+ process_preload_directive(context.environment.attributes_for(pathname).logical_path)
32
+ end
33
+ end
34
+ end
35
+
23
36
  define_method :"process_preload!_directive" do
24
37
  context._force_preload = true
25
38
  end
@@ -1,5 +1,5 @@
1
1
  module Sprockets
2
2
  module Preload
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -0,0 +1 @@
1
+ //= preload_directory ./
@@ -0,0 +1 @@
1
+ test1
@@ -0,0 +1 @@
1
+ test2
data/spec/helpers/boot.rb CHANGED
@@ -33,7 +33,7 @@ shared_context "inlined", inline: true do
33
33
  end
34
34
  end
35
35
 
36
- shared_context "detouched", inline: false do
36
+ shared_context "detached", inline: false do
37
37
  before(:all) do
38
38
  @inline_condition = Sprockets::Preload.inline
39
39
  Sprockets::Preload.inline = false
@@ -9,7 +9,7 @@ describe "Direct dependency" do
9
9
  Sprockets::Preload.precompiles -= ["direct/direct.js"]
10
10
  end
11
11
 
12
- it "serves detouched" do
12
+ it "serves detached" do
13
13
  Sprockets::Preload.environment['sprockets/preload/assets'].source.should == "test1\n;\ntest2\n;\n\n"
14
14
  end
15
15
 
@@ -20,7 +20,7 @@ describe "Direct dependency" do
20
20
  end
21
21
  end
22
22
 
23
- context "detouched", inline: false do
23
+ context "detached", inline: false do
24
24
  it "keeps inlines" do
25
25
  Sprockets::Preload.environment['direct/direct'].source.should_not include("test1", "test2")
26
26
  Sprockets::Preload.environment['direct/direct'].source.should_not include("SprocketsPreload.inline = true")
@@ -0,0 +1,29 @@
1
+ require 'helpers/boot'
2
+
3
+ describe "Self dependency" do
4
+ before(:all) do
5
+ Sprockets::Preload.precompiles += ["directory/directory.js"]
6
+ end
7
+
8
+ after(:all) do
9
+ Sprockets::Preload.precompiles -= ["directory/directory.js"]
10
+ end
11
+
12
+ it "serves detached" do
13
+ Sprockets::Preload.environment['sprockets/preload/assets'].source.should == "test1\n;\ntest2\n;\n\n"
14
+ end
15
+
16
+ context "inlined", inline: true do
17
+ it "keeps inlines" do
18
+ Sprockets::Preload.environment['directory/directory'].source.should include("test1", "test2")
19
+ Sprockets::Preload.environment['directory/directory'].source.should include("SprocketsPreload.inline = true")
20
+ end
21
+ end
22
+
23
+ context "detached", inline: false do
24
+ it "keeps inlines" do
25
+ Sprockets::Preload.environment['directory/directory'].source.should_not include("test1", "test2")
26
+ Sprockets::Preload.environment['directory/directory'].source.should_not include("SprocketsPreload.inline = true")
27
+ end
28
+ end
29
+ end
@@ -1,6 +1,6 @@
1
1
  require 'helpers/boot'
2
2
 
3
- describe "Direct dependency" do
3
+ describe "Forced dependency" do
4
4
  before(:all) do
5
5
  Sprockets::Preload.precompiles += ["forced/forced.js"]
6
6
  end
@@ -9,7 +9,7 @@ describe "Direct dependency" do
9
9
  Sprockets::Preload.precompiles -= ["forced/forced.js"]
10
10
  end
11
11
 
12
- it "serves detouched" do
12
+ it "serves detached" do
13
13
  Sprockets::Preload.environment['sprockets/preload/assets'].source.should == "test1\n;\ntest2\n;\n\n"
14
14
  end
15
15
 
@@ -20,7 +20,7 @@ describe "Direct dependency" do
20
20
  end
21
21
  end
22
22
 
23
- context "detouched", inline: false do
23
+ context "detached", inline: false do
24
24
  it "keeps inlines" do
25
25
  Sprockets::Preload.environment['forced/forced'].source.should_not include("test1", "test2")
26
26
  Sprockets::Preload.environment['forced/forced'].source.should_not include("SprocketsPreload.inline = true")
@@ -9,7 +9,7 @@ describe "Nested dependency" do
9
9
  Sprockets::Preload.precompiles -= ["nested/nested.js"]
10
10
  end
11
11
 
12
- it "serves detouched" do
12
+ it "serves detached" do
13
13
  Sprockets::Preload.environment['sprockets/preload/assets'].source.should == "test2\n;\n\n"
14
14
  end
15
15
 
@@ -20,7 +20,7 @@ describe "Nested dependency" do
20
20
  end
21
21
  end
22
22
 
23
- context "detouched", inline: false do
23
+ context "detached", inline: false do
24
24
  it "keeps inlines" do
25
25
  Sprockets::Preload.environment['nested/nested'].source.should include("test1")
26
26
  Sprockets::Preload.environment['nested/nested'].source.should_not include("test2")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sprockets-preload
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Boris Staal
@@ -78,6 +78,9 @@ files:
78
78
  - spec/helpers/assets/direct/direct.js
79
79
  - spec/helpers/assets/direct/test1.js
80
80
  - spec/helpers/assets/direct/test2.js
81
+ - spec/helpers/assets/directory/directory.js
82
+ - spec/helpers/assets/directory/test1.js
83
+ - spec/helpers/assets/directory/test2.js
81
84
  - spec/helpers/assets/forced/forced.js
82
85
  - spec/helpers/assets/forced/test1.js
83
86
  - spec/helpers/assets/forced/test2.js
@@ -87,6 +90,7 @@ files:
87
90
  - spec/helpers/boot.rb
88
91
  - spec/integrational/circular_spec.rb
89
92
  - spec/integrational/direct_spec.rb
93
+ - spec/integrational/directory_spec.rb
90
94
  - spec/integrational/forced_spec.rb
91
95
  - spec/integrational/nested_spec.rb
92
96
  - sprockets-preload.gemspec
@@ -122,6 +126,9 @@ test_files:
122
126
  - spec/helpers/assets/direct/direct.js
123
127
  - spec/helpers/assets/direct/test1.js
124
128
  - spec/helpers/assets/direct/test2.js
129
+ - spec/helpers/assets/directory/directory.js
130
+ - spec/helpers/assets/directory/test1.js
131
+ - spec/helpers/assets/directory/test2.js
125
132
  - spec/helpers/assets/forced/forced.js
126
133
  - spec/helpers/assets/forced/test1.js
127
134
  - spec/helpers/assets/forced/test2.js
@@ -131,5 +138,6 @@ test_files:
131
138
  - spec/helpers/boot.rb
132
139
  - spec/integrational/circular_spec.rb
133
140
  - spec/integrational/direct_spec.rb
141
+ - spec/integrational/directory_spec.rb
134
142
  - spec/integrational/forced_spec.rb
135
143
  - spec/integrational/nested_spec.rb