render-later 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +6 -6
- data/CHANGELOG.md +11 -0
- data/README.md +16 -2
- data/app/helpers/render_later/view_helper.rb +3 -3
- data/lib/render-later/version.rb +1 -1
- data/render-later.gemspec +3 -3
- metadata +13 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 55370f11139243c05ff90f7daf2c71d46fe1f20c
|
4
|
+
data.tar.gz: 70b2a0834e7502ea42de2525157eea36fc07fdb1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bfdd1c0a4dbda416582e61c88dbdf5da2d503c1908adff8f2ba2964020908514fe4d526d64105e069ad959ddd0d888eb345d1d0856e421646041d56b4bc3c508
|
7
|
+
data.tar.gz: 9f02642e7c9cc19d81c3d233d22cb08b153e067ae8160fea10005f86b56de54ee276dd15181da16aec924544f877981a69987794b4f951dbcfc144ff1be4b4b2
|
data/.travis.yml
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
language: ruby
|
2
2
|
cache: bundler
|
3
3
|
rvm:
|
4
|
-
- 2.
|
5
|
-
- 2.
|
6
|
-
- 2.3.0
|
4
|
+
- 2.3.4
|
5
|
+
- 2.4.1
|
7
6
|
gemfile:
|
8
|
-
- test/gemfiles/rails-4.1.gemfile
|
9
7
|
- test/gemfiles/rails-4.2.gemfile
|
8
|
+
- test/gemfiles/rails-5.0.gemfile
|
9
|
+
- test/gemfiles/rails-5.1.gemfile
|
10
10
|
matrix:
|
11
11
|
include:
|
12
|
-
- rvm: 2.3.
|
13
|
-
gemfile: test/gemfiles/rails-
|
12
|
+
- rvm: 2.3.4
|
13
|
+
gemfile: test/gemfiles/rails-4.1.gemfile
|
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -25,7 +25,14 @@ In your views, simply wrap a slow piece of code into a `render_later` block, and
|
|
25
25
|
<% end %>
|
26
26
|
</div>
|
27
27
|
```
|
28
|
-
It's important to use the `<%=` erb tag here, as the helper will render a hidden span tag.
|
28
|
+
It's important to use the `<%=` erb tag here, as the helper will render a hidden `span` tag. If a `span` tag doesn't work well for you (ex: in a table), you can customize the placeholder element with the `tag` keyword argument, ex:
|
29
|
+
```erb
|
30
|
+
<table>
|
31
|
+
<%= render_later "srv-uptime-#{server.id}", tag: :tr do %>
|
32
|
+
<tr><td><%= server.uptime %></td></tr>
|
33
|
+
<% end %>
|
34
|
+
</table>
|
35
|
+
```
|
29
36
|
|
30
37
|
In your layout, before the end of the body tag, add a call to `render_now`:
|
31
38
|
```erb
|
@@ -36,6 +43,14 @@ In your layout, before the end of the body tag, add a call to `render_now`:
|
|
36
43
|
```
|
37
44
|
This is where the deferred blocks will be rendered and injected into the page using inline javascript.
|
38
45
|
|
46
|
+
And finally in your controller, you need to render with the `stream` option:
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
def index
|
50
|
+
render stream: true
|
51
|
+
end
|
52
|
+
```
|
53
|
+
|
39
54
|
## Performance
|
40
55
|
|
41
56
|
Performance-wise, this approach is quite interesting, let me explain why:
|
@@ -140,7 +155,6 @@ After checking out the repo, run `bundle install` to install dependencies. Then,
|
|
140
155
|
- Wider test coverage across browsers using [Sauce Labs](https://saucelabs.com/opensauce/)
|
141
156
|
- Parallel rendering (I tried quickly but the `capture` helper isn't thread-safe)
|
142
157
|
- Add options to do caching at the same time (with the same key)
|
143
|
-
- Add options to customize the generated temporary element (could be used for loading indication or to avoid CSS conflict)
|
144
158
|
|
145
159
|
## License
|
146
160
|
|
@@ -3,7 +3,7 @@ module RenderLater
|
|
3
3
|
INSERT_FUNCTION = <<-JAVASCRIPT.freeze
|
4
4
|
function rl_insert(name, data) {
|
5
5
|
if (node = document.getElementById(name)) {
|
6
|
-
var div = document.createElement('div');
|
6
|
+
var div = document.createElement(node.parentNode.tagName || 'div');
|
7
7
|
div.innerHTML = data;
|
8
8
|
var elements = div.childNodes;
|
9
9
|
for (var i = elements.length; i > 0; i--) {
|
@@ -14,9 +14,9 @@ module RenderLater
|
|
14
14
|
};
|
15
15
|
JAVASCRIPT
|
16
16
|
|
17
|
-
def render_later key, &block
|
17
|
+
def render_later key, tag: :span, class: "rl-placeholder", &block
|
18
18
|
store_object(key, &block)
|
19
|
-
content_tag(
|
19
|
+
content_tag(tag, nil, id: "rl-#{key}", class: binding.local_variable_get(:class), style: 'display: none')
|
20
20
|
end
|
21
21
|
|
22
22
|
def render_now
|
data/lib/render-later/version.rb
CHANGED
data/render-later.gemspec
CHANGED
@@ -20,9 +20,9 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
22
|
spec.add_development_dependency "bundler", "~> 1.11"
|
23
|
-
spec.add_development_dependency "rake"
|
24
|
-
spec.add_development_dependency "minitest"
|
25
|
-
spec.add_development_dependency "rails", "~>
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
spec.add_development_dependency "minitest"
|
25
|
+
spec.add_development_dependency "rails", "~> 5.1"
|
26
26
|
spec.add_development_dependency "puma"
|
27
27
|
spec.add_development_dependency "poltergeist"
|
28
28
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: render-later
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adrien Jarthon
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-08-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -28,44 +28,44 @@ dependencies:
|
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: minitest
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rails
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '5.1'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '5.1'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: puma
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -105,6 +105,7 @@ extra_rdoc_files: []
|
|
105
105
|
files:
|
106
106
|
- ".gitignore"
|
107
107
|
- ".travis.yml"
|
108
|
+
- CHANGELOG.md
|
108
109
|
- Gemfile
|
109
110
|
- LICENSE.txt
|
110
111
|
- README.md
|
@@ -139,4 +140,3 @@ signing_key:
|
|
139
140
|
specification_version: 4
|
140
141
|
summary: Defer rendering of slow parts to the end of the page
|
141
142
|
test_files: []
|
142
|
-
has_rdoc:
|