render_async 1.1.3 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.all-contributorsrc +22 -2
- data/.gitmodules +4 -0
- data/README.md +63 -5
- data/app/views/render_async/_render_async.html.erb +7 -35
- data/app/views/render_async/_request.js.erb +37 -0
- data/bin/integration-tests +13 -0
- data/lib/render_async/version.rb +1 -1
- data/lib/render_async/view_helper.rb +3 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1e55f1d2d9bd896fcb28007fb3bfe42752d4d90
|
4
|
+
data.tar.gz: ac66f3e90a93a3952b0b5f690ab1d79e85b2284c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 43ffe5cf4db879ec44baf27f68435ef275206ce725085ae6c6f1f139c44fcafd215e41b79ce0b44c471698a4b2cf21353e6ae9f07bd95620321f121551d0c49b
|
7
|
+
data.tar.gz: 089b856889e18dd218372284ee4cfe86dd8aa08260ad55b58e39334a694e981de7c407a237a3686bbe69c71109bbc36c29bfb90163404b0d7efeaefa1db34389
|
data/.all-contributorsrc
CHANGED
@@ -28,7 +28,8 @@
|
|
28
28
|
"profile": "http://www.colinxfleming.com",
|
29
29
|
"contributions": [
|
30
30
|
"code",
|
31
|
-
"doc"
|
31
|
+
"doc",
|
32
|
+
"example"
|
32
33
|
]
|
33
34
|
},
|
34
35
|
{
|
@@ -65,7 +66,8 @@
|
|
65
66
|
"avatar_url": "https://avatars3.githubusercontent.com/u/107798?v=4",
|
66
67
|
"profile": "https://eladshahar.com",
|
67
68
|
"contributions": [
|
68
|
-
"code"
|
69
|
+
"code",
|
70
|
+
"example"
|
69
71
|
]
|
70
72
|
},
|
71
73
|
{
|
@@ -86,6 +88,24 @@
|
|
86
88
|
"contributions": [
|
87
89
|
"code"
|
88
90
|
]
|
91
|
+
},
|
92
|
+
{
|
93
|
+
"login": "krainboltgreene",
|
94
|
+
"name": "Kurtis Rainbolt-Greene",
|
95
|
+
"avatar_url": "https://avatars1.githubusercontent.com/u/334809?v=4",
|
96
|
+
"profile": "https://kurtis.rainbolt-greene.online",
|
97
|
+
"contributions": [
|
98
|
+
"code"
|
99
|
+
]
|
100
|
+
},
|
101
|
+
{
|
102
|
+
"login": "schneems",
|
103
|
+
"name": "Richard Schneeman",
|
104
|
+
"avatar_url": "https://avatars2.githubusercontent.com/u/59744?v=4",
|
105
|
+
"profile": "https://www.schneems.com",
|
106
|
+
"contributions": [
|
107
|
+
"doc"
|
108
|
+
]
|
89
109
|
}
|
90
110
|
]
|
91
111
|
}
|
data/.gitmodules
ADDED
data/README.md
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
[![Build Status](https://semaphoreci.com/api/v1/renderedtext/render_async/branches/master/shields_badge.svg)](https://semaphoreci.com/renderedtext/render_async)
|
2
|
-
[![All Contributors](https://img.shields.io/badge/all_contributors-
|
2
|
+
[![All Contributors](https://img.shields.io/badge/all_contributors-10-orange.svg?style=flat-square)](#contributors)
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/render_async.svg)](https://badge.fury.io/rb/render_async)
|
4
4
|
[![Code Climate](https://codeclimate.com/github/renderedtext/render_async/badges/gpa.svg)](https://codeclimate.com/github/renderedtext/render_async)
|
5
5
|
[![Test Coverage](https://codeclimate.com/github/renderedtext/render_async/badges/coverage.svg)](https://codeclimate.com/github/renderedtext/render_async/coverage)
|
6
|
+
[![Help Contribute to Open Source](https://www.codetriage.com/renderedtext/render_async/badges/users.svg)](https://www.codetriage.com/renderedtext/render_async)
|
6
7
|
|
7
8
|
![render_async](https://semaphoreci.com/blog/assets/images/2017-06-08/speed-up-rendering-rails-pages-with-render-async-6c40eb39.png)
|
8
9
|
|
@@ -71,6 +72,16 @@ And then execute:
|
|
71
72
|
|
72
73
|
## Advanced usage
|
73
74
|
|
75
|
+
Advanced usage includes information on different options, such as:
|
76
|
+
|
77
|
+
- [Passing in HTML options](#passing-in-html-options)
|
78
|
+
- [Passing in an HTML element name](#passing-in-an-html-element-name)
|
79
|
+
- [Passing in a placeholder](#passing-in-a-placeholder)
|
80
|
+
- [Passing in an event name](#passing-in-an-event-name)
|
81
|
+
- [Caching](#caching)
|
82
|
+
- [Using with Turbolinks](#using-with-turbolinks)
|
83
|
+
- [Nested Async Renders](#nested-async-renders)
|
84
|
+
|
74
85
|
### Passing in HTML options
|
75
86
|
|
76
87
|
`render_async` takes two arguments, `path` and `html_options`.
|
@@ -97,6 +108,26 @@ Rendered code in the view:
|
|
97
108
|
</script>
|
98
109
|
```
|
99
110
|
|
111
|
+
### Passing in an HTML element name
|
112
|
+
|
113
|
+
`render_async` can take in an HTML element name, allowing you to control
|
114
|
+
what type of container gets rendered. This can be useful when you're using
|
115
|
+
[`render_async` inside a table](https://github.com/renderedtext/render_async/issues/12)
|
116
|
+
and you need it to render a `tr` element before your request gets loaded, so
|
117
|
+
your content doesn't get pushed out of the table.
|
118
|
+
|
119
|
+
Example of using HTML element name:
|
120
|
+
```erb
|
121
|
+
<%= render_async users_path, html_element_name: 'tr' %>
|
122
|
+
```
|
123
|
+
|
124
|
+
Rendered code in the view:
|
125
|
+
```html
|
126
|
+
<tr id="render_async_04229e7abe1507987376">
|
127
|
+
</tr>
|
128
|
+
...
|
129
|
+
```
|
130
|
+
|
100
131
|
### Passing in a placeholder
|
101
132
|
|
102
133
|
`render_async` can be called with a block that will act as a placeholder before
|
@@ -160,7 +191,7 @@ document.addEventListener("users-loaded", function() {
|
|
160
191
|
});
|
161
192
|
```
|
162
193
|
|
163
|
-
|
194
|
+
### Caching
|
164
195
|
|
165
196
|
`render_async` can utilize view fragment caching to avoid extra AJAX calls.
|
166
197
|
|
@@ -185,7 +216,7 @@ Then, in the partial (e.g. `app/views/comments/_comment_stats.html.erb`):
|
|
185
216
|
* You can expire cache simply by passing `:expires_in` in your view where
|
186
217
|
you cache the partial
|
187
218
|
|
188
|
-
|
219
|
+
### Using with Turbolinks
|
189
220
|
|
190
221
|
On Turbolinks applications, you may experience caching issues when navigating
|
191
222
|
away from, and then back to, a page with a `render_async` call on it. This will
|
@@ -197,6 +228,33 @@ To resolve, tell turbolinks to reload your `render_async` call as follows:
|
|
197
228
|
<%= render_async events_path, 'data-turbolinks-track': 'reload' %>
|
198
229
|
```
|
199
230
|
|
231
|
+
### Nested Async Renders
|
232
|
+
|
233
|
+
It is possible to nest async templates within other async templates. When doing
|
234
|
+
so, another `content_for` is required to ensure the JavaScript needed to load
|
235
|
+
nested templates is included.
|
236
|
+
|
237
|
+
For example:
|
238
|
+
```erb
|
239
|
+
<%# app/views/comments/show.html.erb %>
|
240
|
+
|
241
|
+
<%= render_async comment_stats_path %>
|
242
|
+
```
|
243
|
+
|
244
|
+
```erb
|
245
|
+
<%# app/views/comments/_comment_stats.html.erb %>
|
246
|
+
|
247
|
+
<div class="col-md-6">
|
248
|
+
<%= @stats %>
|
249
|
+
</div>
|
250
|
+
|
251
|
+
<div class="col-md-6">
|
252
|
+
<%= render_async comment_advanced_stats_path %>
|
253
|
+
</div>
|
254
|
+
|
255
|
+
<%= content_for :render_async %>
|
256
|
+
```
|
257
|
+
|
200
258
|
## Development
|
201
259
|
|
202
260
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
@@ -216,9 +274,9 @@ The gem is available as open source under the terms of the [MIT License](http://
|
|
216
274
|
Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):
|
217
275
|
|
218
276
|
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
|
219
|
-
| [<img src="https://avatars2.githubusercontent.com/u/3028124?v=4" width="100px;"/><br /><sub>Nikola Đuza</sub>](http://nikoladjuza.me/)<br />[💬](#question-nikolalsvk "Answering Questions") [🐛](https://github.com/renderedtext/render_async/issues?q=author%3Anikolalsvk "Bug reports") [💻](https://github.com/renderedtext/render_async/commits?author=nikolalsvk "Code") [📖](https://github.com/renderedtext/render_async/commits?author=nikolalsvk "Documentation") [💡](#example-nikolalsvk "Examples") [👀](#review-nikolalsvk "Reviewed Pull Requests") | [<img src="https://avatars0.githubusercontent.com/u/3866868?v=4" width="100px;"/><br /><sub>Colin</sub>](http://www.colinxfleming.com)<br />[💻](https://github.com/renderedtext/render_async/commits?author=colinxfleming "Code") [📖](https://github.com/renderedtext/render_async/commits?author=colinxfleming "Documentation") | [<img src="https://avatars2.githubusercontent.com/u/334273?v=4" width="100px;"/><br /><sub>Kasper Grubbe</sub>](http://kaspergrubbe.com)<br />[💻](https://github.com/renderedtext/render_async/commits?author=kaspergrubbe "Code") | [<img src="https://avatars2.githubusercontent.com/u/163584?v=4" width="100px;"/><br /><sub>Sai Ram Kunala</sub>](https://sairam.xyz/)<br />[📖](https://github.com/renderedtext/render_async/commits?author=sairam "Documentation") | [<img src="https://avatars2.githubusercontent.com/u/3065882?v=4" width="100px;"/><br /><sub>Josh Arnold</sub>](https://github.com/nightsurge)<br />[💻](https://github.com/renderedtext/render_async/commits?author=nightsurge "Code") [📖](https://github.com/renderedtext/render_async/commits?author=nightsurge "Documentation") | [<img src="https://avatars3.githubusercontent.com/u/107798?v=4" width="100px;"/><br /><sub>Elad Shahar</sub>](https://eladshahar.com)<br />[💻](https://github.com/renderedtext/render_async/commits?author=SaladFork "Code") | [<img src="https://avatars3.githubusercontent.com/u/232392?v=4" width="100px;"/><br /><sub>Sasha</sub>](http://www.revzin.co.il)<br />[💻](https://github.com/renderedtext/render_async/commits?author=sasharevzin "Code") [📖](https://github.com/renderedtext/render_async/commits?author=sasharevzin "Documentation") |
|
277
|
+
| [<img src="https://avatars2.githubusercontent.com/u/3028124?v=4" width="100px;"/><br /><sub>Nikola Đuza</sub>](http://nikoladjuza.me/)<br />[💬](#question-nikolalsvk "Answering Questions") [🐛](https://github.com/renderedtext/render_async/issues?q=author%3Anikolalsvk "Bug reports") [💻](https://github.com/renderedtext/render_async/commits?author=nikolalsvk "Code") [📖](https://github.com/renderedtext/render_async/commits?author=nikolalsvk "Documentation") [💡](#example-nikolalsvk "Examples") [👀](#review-nikolalsvk "Reviewed Pull Requests") | [<img src="https://avatars0.githubusercontent.com/u/3866868?v=4" width="100px;"/><br /><sub>Colin</sub>](http://www.colinxfleming.com)<br />[💻](https://github.com/renderedtext/render_async/commits?author=colinxfleming "Code") [📖](https://github.com/renderedtext/render_async/commits?author=colinxfleming "Documentation") [💡](#example-colinxfleming "Examples") | [<img src="https://avatars2.githubusercontent.com/u/334273?v=4" width="100px;"/><br /><sub>Kasper Grubbe</sub>](http://kaspergrubbe.com)<br />[💻](https://github.com/renderedtext/render_async/commits?author=kaspergrubbe "Code") | [<img src="https://avatars2.githubusercontent.com/u/163584?v=4" width="100px;"/><br /><sub>Sai Ram Kunala</sub>](https://sairam.xyz/)<br />[📖](https://github.com/renderedtext/render_async/commits?author=sairam "Documentation") | [<img src="https://avatars2.githubusercontent.com/u/3065882?v=4" width="100px;"/><br /><sub>Josh Arnold</sub>](https://github.com/nightsurge)<br />[💻](https://github.com/renderedtext/render_async/commits?author=nightsurge "Code") [📖](https://github.com/renderedtext/render_async/commits?author=nightsurge "Documentation") | [<img src="https://avatars3.githubusercontent.com/u/107798?v=4" width="100px;"/><br /><sub>Elad Shahar</sub>](https://eladshahar.com)<br />[💻](https://github.com/renderedtext/render_async/commits?author=SaladFork "Code") [💡](#example-SaladFork "Examples") | [<img src="https://avatars3.githubusercontent.com/u/232392?v=4" width="100px;"/><br /><sub>Sasha</sub>](http://www.revzin.co.il)<br />[💻](https://github.com/renderedtext/render_async/commits?author=sasharevzin "Code") [📖](https://github.com/renderedtext/render_async/commits?author=sasharevzin "Documentation") |
|
220
278
|
| :---: | :---: | :---: | :---: | :---: | :---: | :---: |
|
221
|
-
| [<img src="https://avatars3.githubusercontent.com/u/50223?v=4" width="100px;"/><br /><sub>Ernest Surudo</sub>](http://elsurudo.com)<br />[💻](https://github.com/renderedtext/render_async/commits?author=elsurudo "Code") |
|
279
|
+
| [<img src="https://avatars3.githubusercontent.com/u/50223?v=4" width="100px;"/><br /><sub>Ernest Surudo</sub>](http://elsurudo.com)<br />[💻](https://github.com/renderedtext/render_async/commits?author=elsurudo "Code") | [<img src="https://avatars1.githubusercontent.com/u/334809?v=4" width="100px;"/><br /><sub>Kurtis Rainbolt-Greene</sub>](https://kurtis.rainbolt-greene.online)<br />[💻](https://github.com/renderedtext/render_async/commits?author=krainboltgreene "Code") | [<img src="https://avatars2.githubusercontent.com/u/59744?v=4" width="100px;"/><br /><sub>Richard Schneeman</sub>](https://www.schneems.com)<br />[📖](https://github.com/renderedtext/render_async/commits?author=schneems "Documentation") |
|
222
280
|
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
223
281
|
|
224
282
|
This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!
|
@@ -1,41 +1,13 @@
|
|
1
|
-
|
1
|
+
<<%= html_element_name %> id="<%= container_id %>">
|
2
2
|
<%= placeholder %>
|
3
|
-
|
3
|
+
</<%= html_element_name %>>
|
4
4
|
|
5
5
|
<% content_for :render_async do %>
|
6
6
|
<%= javascript_tag html_options do %>
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
<% if event_name.present? %>
|
13
|
-
document.dispatchEvent(new Event("<%= event_name %>"));
|
14
|
-
<% end %>
|
15
|
-
});
|
16
|
-
}(jQuery));
|
17
|
-
} else {
|
18
|
-
(function() {
|
19
|
-
var request = new XMLHttpRequest();
|
20
|
-
var asyncRequest = true;
|
21
|
-
var SUCCESS = 200;
|
22
|
-
var ERROR = 400;
|
23
|
-
|
24
|
-
request.open("GET", "<%= path.html_safe %>", asyncRequest);
|
25
|
-
|
26
|
-
request.onload = function() {
|
27
|
-
if (request.status >= SUCCESS && request.status < ERROR) {
|
28
|
-
var container = document.getElementById("<%= container_id %>");
|
29
|
-
container.outerHTML = request.response;
|
30
|
-
|
31
|
-
<% if event_name.present? %>
|
32
|
-
document.dispatchEvent(new Event("<%= event_name %>"));
|
33
|
-
<% end %>
|
34
|
-
}
|
35
|
-
};
|
36
|
-
|
37
|
-
request.send();
|
38
|
-
})();
|
39
|
-
}
|
7
|
+
<%= render partial: 'render_async/request',
|
8
|
+
formats: [:js],
|
9
|
+
locals: { container_id: container_id,
|
10
|
+
path: path,
|
11
|
+
event_name: event_name } %>
|
40
12
|
<% end %>
|
41
13
|
<% end %>
|
@@ -0,0 +1,37 @@
|
|
1
|
+
if (window.jQuery) {
|
2
|
+
(function($) {
|
3
|
+
$(document).ready(function() {
|
4
|
+
$.ajax({ url: "<%= path.html_safe %>" }).always(function(response) {
|
5
|
+
$("#<%= container_id %>").replaceWith(response);
|
6
|
+
|
7
|
+
<% if event_name.present? %>
|
8
|
+
document.dispatchEvent(new Event("<%= event_name %>"));
|
9
|
+
<% end %>
|
10
|
+
});
|
11
|
+
});
|
12
|
+
}(jQuery));
|
13
|
+
} else {
|
14
|
+
(function() {
|
15
|
+
document.addEventListener("DOMContentLoaded", function() {
|
16
|
+
var request = new XMLHttpRequest();
|
17
|
+
var asyncRequest = true;
|
18
|
+
var SUCCESS = 200;
|
19
|
+
var ERROR = 400;
|
20
|
+
|
21
|
+
request.open("GET", "<%= path.html_safe %>", asyncRequest);
|
22
|
+
|
23
|
+
request.onload = function() {
|
24
|
+
if (request.status >= SUCCESS && request.status < ERROR) {
|
25
|
+
var container = document.getElementById("<%= container_id %>");
|
26
|
+
container.outerHTML = request.response;
|
27
|
+
|
28
|
+
<% if event_name.present? %>
|
29
|
+
document.dispatchEvent(new Event("<%= event_name %>"));
|
30
|
+
<% end %>
|
31
|
+
}
|
32
|
+
};
|
33
|
+
|
34
|
+
request.send();
|
35
|
+
});
|
36
|
+
})();
|
37
|
+
}
|
data/lib/render_async/version.rb
CHANGED
@@ -18,11 +18,13 @@ module RenderAsync
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def render_async(path, options = {}, &placeholder)
|
21
|
+
html_element_name = options.delete(:html_element_name) || "div"
|
21
22
|
container_id = "render_async_#{SecureRandom.hex(5)}#{Time.now.to_i}"
|
22
23
|
event_name = options.delete(:event_name)
|
23
24
|
placeholder = capture(&placeholder) if block_given?
|
24
25
|
|
25
|
-
render 'render_async/render_async',
|
26
|
+
render 'render_async/render_async', html_element_name: html_element_name,
|
27
|
+
container_id: container_id,
|
26
28
|
path: path,
|
27
29
|
html_options: options,
|
28
30
|
event_name: event_name,
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: render_async
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kasper Grubbe
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2018-01-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -76,13 +76,16 @@ extra_rdoc_files: []
|
|
76
76
|
files:
|
77
77
|
- ".all-contributorsrc"
|
78
78
|
- ".gitignore"
|
79
|
+
- ".gitmodules"
|
79
80
|
- ".rspec"
|
80
81
|
- Gemfile
|
81
82
|
- LICENSE
|
82
83
|
- README.md
|
83
84
|
- Rakefile
|
84
85
|
- app/views/render_async/_render_async.html.erb
|
86
|
+
- app/views/render_async/_request.js.erb
|
85
87
|
- bin/console
|
88
|
+
- bin/integration-tests
|
86
89
|
- bin/setup
|
87
90
|
- lib/render_async.rb
|
88
91
|
- lib/render_async/engine.rb
|