render_async 0.1.3 → 0.2.3

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: 8c70691a62b5d47023c92ed34bf99fa601a2225a
4
- data.tar.gz: dfd318ae355aae16e66cb6f54f3f278a6fe3acbc
3
+ metadata.gz: 8461015b342c8c89a38e651abb80209822fdfba3
4
+ data.tar.gz: ae3bc61fcc548109b5604b6add34152445378b39
5
5
  SHA512:
6
- metadata.gz: 57655b60c806ca621cb2cd8e5be2084cf1c94293de75aeac3db279e8df6d5422ba2e7fdc06494c410b0cbec60a8b8aded087b92615df14883f596c625cd4af0e
7
- data.tar.gz: eff5ef88ea6b2dd12f881c627d1a56d94d00289ef624069f25a0f536b8e4dddfaf772da85cc807afc42b594eaaadb18df81425027cb3418d7d2f6eb38d8f44e7
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
- <script type="text/javascript">
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
- </script>
24
+ <% end %>
25
25
  <% end %>
@@ -1,3 +1,3 @@
1
1
  module RenderAsync
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.3"
3
3
  end
@@ -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.1.3
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-06-28 00:00:00.000000000 Z
12
+ date: 2017-07-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler