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 +4 -4
- data/README.md +17 -9
- data/lib/sprockets/preload/directive_processor.rb +19 -6
- data/lib/sprockets/preload/version.rb +1 -1
- data/spec/helpers/assets/directory/directory.js +1 -0
- data/spec/helpers/assets/directory/test1.js +1 -0
- data/spec/helpers/assets/directory/test2.js +1 -0
- data/spec/helpers/boot.rb +1 -1
- data/spec/integrational/direct_spec.rb +2 -2
- data/spec/integrational/directory_spec.rb +29 -0
- data/spec/integrational/forced_spec.rb +3 -3
- data/spec/integrational/nested_spec.rb +2 -2
- metadata +9 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c109168d6d857d0d53ea555d65a80f4c6e6044fe
|
4
|
+
data.tar.gz: bd31241d93501635dae87cb3e284ebc4bd6862c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
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
|
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
|
-
##
|
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
|
-
|
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
|
-
|
9
|
-
|
10
|
-
|
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
|
@@ -0,0 +1 @@
|
|
1
|
+
//= preload_directory ./
|
@@ -0,0 +1 @@
|
|
1
|
+
test1
|
@@ -0,0 +1 @@
|
|
1
|
+
test2
|
data/spec/helpers/boot.rb
CHANGED
@@ -9,7 +9,7 @@ describe "Direct dependency" do
|
|
9
9
|
Sprockets::Preload.precompiles -= ["direct/direct.js"]
|
10
10
|
end
|
11
11
|
|
12
|
-
it "serves
|
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 "
|
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 "
|
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
|
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 "
|
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
|
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 "
|
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.
|
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
|