render_async 0.1.3 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +43 -0
- data/app/views/render_async/_render_async.html.erb +2 -2
- data/lib/render_async/version.rb +1 -1
- data/lib/render_async/view_helper.rb +3 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8461015b342c8c89a38e651abb80209822fdfba3
|
4
|
+
data.tar.gz: ae3bc61fcc548109b5604b6add34152445378b39
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: acb2d229f1eb40b5174e6040ec5428ab122f90a2dc6e22b4bce4f63b5a3211979758db5c6360ae3900a0a7eb64c8eb014e9c66c23d85ab62dc2617f5be61bfe9
|
7
|
+
data.tar.gz: 3ff571c164dcb8cbb7e0cf5a5b71e6ed6481978629d070f328c3b5125918ab7898e7e73f9bf0e4da8799057df99caa4280fa6c7d05c19978c527a1afa101ca54
|
data/README.md
CHANGED
@@ -75,6 +75,49 @@ And then execute:
|
|
75
75
|
<%= content_for :render_async %>
|
76
76
|
```
|
77
77
|
|
78
|
+
## Advanced usage
|
79
|
+
|
80
|
+
`render_async` takes two arguments, `path` and `html_options`.
|
81
|
+
|
82
|
+
* `path` is the ajax-capable controller action you're looking to call via `get`. e.g. `comments_stats_path`, `posts_path`, etc.
|
83
|
+
* `html_options` is an optional hash that gets passed to a rails `javascript_tag`, to drop html tags into the `script` element.
|
84
|
+
|
85
|
+
Example utilizing `html_options` with a `nonce`:
|
86
|
+
```erb
|
87
|
+
<%= render_async users_path, nonce: 'lWaaV6eYicpt+oyOfcShYINsz0b70iR+Q1mohZqNaag=' %>
|
88
|
+
```
|
89
|
+
|
90
|
+
Rendered code in the view:
|
91
|
+
```html
|
92
|
+
<div id="render_async_18b8a6cd161499117471">
|
93
|
+
<div id="render_async_18b8a6cd161499117471_spinner" class="sk-spinner sk-spinner-double-bounce">
|
94
|
+
<div class="sk-double-bounce1"></div>
|
95
|
+
<div class="sk-double-bounce2"></div>
|
96
|
+
</div>
|
97
|
+
</div>
|
98
|
+
|
99
|
+
<script nonce="lWaaV6eYicpt+oyOfcShYINsz0b70iR+Q1mohZqNaag=">
|
100
|
+
//<![CDATA[
|
101
|
+
|
102
|
+
(function($){
|
103
|
+
$.ajax({
|
104
|
+
url: "/users",
|
105
|
+
})
|
106
|
+
.done(function(response, status) {
|
107
|
+
$("#render_async_18b8a6cd161499117471").html(response);
|
108
|
+
})
|
109
|
+
.fail(function(response, status) {
|
110
|
+
$("#render_async_18b8a6cd161499117471").html(response);
|
111
|
+
})
|
112
|
+
.always(function(response, status) {
|
113
|
+
$("#render_async_18b8a6cd161499117471_spinner").hide();
|
114
|
+
});
|
115
|
+
}(jQuery));
|
116
|
+
|
117
|
+
//]]>
|
118
|
+
</script>
|
119
|
+
```
|
120
|
+
|
78
121
|
## Development
|
79
122
|
|
80
123
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
@@ -6,7 +6,7 @@
|
|
6
6
|
</div>
|
7
7
|
|
8
8
|
<% content_for :render_async do %>
|
9
|
-
|
9
|
+
<%= javascript_tag html_options do %>
|
10
10
|
(function($){
|
11
11
|
$.ajax({
|
12
12
|
url: "<%= path %>",
|
@@ -21,5 +21,5 @@
|
|
21
21
|
$("#<%= container_name %>_spinner").hide();
|
22
22
|
});
|
23
23
|
}(jQuery));
|
24
|
-
|
24
|
+
<% end %>
|
25
25
|
<% end %>
|
data/lib/render_async/version.rb
CHANGED
@@ -3,11 +3,12 @@ require 'securerandom'
|
|
3
3
|
module RenderAsync
|
4
4
|
module ViewHelper
|
5
5
|
|
6
|
-
def render_async(path)
|
6
|
+
def render_async(path, html_options = {})
|
7
7
|
container_name = "render_async_#{SecureRandom.hex(5)}#{Time.now.to_i}"
|
8
8
|
|
9
9
|
render "render_async/render_async", :container_name => container_name,
|
10
|
-
:path => path
|
10
|
+
:path => path,
|
11
|
+
:html_options => html_options
|
11
12
|
end
|
12
13
|
|
13
14
|
end
|
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: 0.
|
4
|
+
version: 0.2.3
|
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: 2017-
|
12
|
+
date: 2017-07-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|