render_async 0.2.3 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8461015b342c8c89a38e651abb80209822fdfba3
4
- data.tar.gz: ae3bc61fcc548109b5604b6add34152445378b39
3
+ metadata.gz: ff5ddd05eefc4d2931599f33cda3f3adf6cd8702
4
+ data.tar.gz: 8471ebb95b278aaad261e124cc3c3ee738b87b63
5
5
  SHA512:
6
- metadata.gz: acb2d229f1eb40b5174e6040ec5428ab122f90a2dc6e22b4bce4f63b5a3211979758db5c6360ae3900a0a7eb64c8eb014e9c66c23d85ab62dc2617f5be61bfe9
7
- data.tar.gz: 3ff571c164dcb8cbb7e0cf5a5b71e6ed6481978629d070f328c3b5125918ab7898e7e73f9bf0e4da8799057df99caa4280fa6c7d05c19978c527a1afa101ca54
6
+ metadata.gz: 0b4f56f6dae23a8f4fc863ec279be4b62e3e122937e76c720bfebcef9d1a0b722819c2e861558e837243721fe6f72f7a5e88824af66d03adccb1ea44d8624fa5
7
+ data.tar.gz: 66cb39569968eb5aeaad75f0f5d47989a03bcc4c36ab1d254b36a85e764d78aa04214fc62a118b8fb613538f54c0f9e9c335e130abb716bd58849dcf2a6c51a3
@@ -0,0 +1,53 @@
1
+ {
2
+ "projectName": "render_async",
3
+ "projectOwner": "renderedtext",
4
+ "files": [
5
+ "README.md"
6
+ ],
7
+ "imageSize": 100,
8
+ "commit": true,
9
+ "contributors": [
10
+ {
11
+ "login": "nikolalsvk",
12
+ "name": "Nikola Đuza",
13
+ "avatar_url": "https://avatars2.githubusercontent.com/u/3028124?v=4",
14
+ "profile": "http://nikoladjuza.me/",
15
+ "contributions": [
16
+ "question",
17
+ "bug",
18
+ "code",
19
+ "doc",
20
+ "example",
21
+ "review"
22
+ ]
23
+ },
24
+ {
25
+ "login": "colinxfleming",
26
+ "name": "Colin",
27
+ "avatar_url": "https://avatars0.githubusercontent.com/u/3866868?v=4",
28
+ "profile": "http://www.colinxfleming.com",
29
+ "contributions": [
30
+ "code",
31
+ "doc"
32
+ ]
33
+ },
34
+ {
35
+ "login": "kaspergrubbe",
36
+ "name": "Kasper Grubbe",
37
+ "avatar_url": "https://avatars2.githubusercontent.com/u/334273?v=4",
38
+ "profile": "http://kaspergrubbe.com",
39
+ "contributions": [
40
+ "code"
41
+ ]
42
+ },
43
+ {
44
+ "login": "sairam",
45
+ "name": "Sai Ram Kunala",
46
+ "avatar_url": "https://avatars2.githubusercontent.com/u/163584?v=4",
47
+ "profile": "https://sairam.xyz/",
48
+ "contributions": [
49
+ "doc"
50
+ ]
51
+ }
52
+ ]
53
+ }
data/README.md CHANGED
@@ -1,4 +1,5 @@
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-4-orange.svg?style=flat-square)](#contributors)
2
3
  [![Gem Version](https://badge.fury.io/rb/render_async.svg)](https://badge.fury.io/rb/render_async)
3
4
 
4
5
  ![render_async](https://semaphoreci.com/blog/assets/images/2017-06-08/speed-up-rendering-rails-pages-with-render-async-6c40eb39.png)
@@ -34,7 +35,6 @@ And then execute:
34
35
  ## Usage
35
36
 
36
37
  1. Include `render_async` view helper somewhere in your views:
37
-
38
38
  ```erb
39
39
  # app/views/comments/show.html.erb
40
40
 
@@ -118,6 +118,34 @@ Rendered code in the view:
118
118
  </script>
119
119
  ```
120
120
 
121
+ ## Caching
122
+
123
+ `render_async` can utilize view fragment caching to avoid extra AJAX calls.
124
+
125
+ In your views:
126
+ ```erb
127
+ # app/views/comments/show.html.erb
128
+
129
+ # note 'render_async_cache' instead of standard 'render_async'
130
+ <%= render_async_cache comment_stats_path %>
131
+ ```
132
+
133
+ ```erb
134
+ # app/views/comments/_comment_stats.html.erb
135
+
136
+ <% cache render_async_cache_key(request.path), :skip_digest => true do %>
137
+ <div class="col-md-6">
138
+ <%= @stats %>
139
+ </div>
140
+ <% end %>
141
+ ```
142
+
143
+ * The first time the page renders, it will make the AJAX call.
144
+ * Any other times (until the cache expires), it will render from cache
145
+ instantly, without making the AJAX call.
146
+ * You can expire cache simply by passing `:expires_in` in your view where
147
+ you cache the partial
148
+
121
149
  ## Development
122
150
 
123
151
  After checking out the repo, run `bin/setup` to install dependencies. Then, run
@@ -137,3 +165,14 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/render
137
165
  ## License
138
166
 
139
167
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
168
+
169
+ ## Contributors
170
+
171
+ Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):
172
+
173
+ <!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
174
+ | [<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") |
175
+ | :---: | :---: | :---: | :---: |
176
+ <!-- ALL-CONTRIBUTORS-LIST:END -->
177
+
178
+ This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!
@@ -1,3 +1,3 @@
1
1
  module RenderAsync
2
- VERSION = "0.2.3"
2
+ VERSION = "0.3.3"
3
3
  end
@@ -3,6 +3,19 @@ require 'securerandom'
3
3
  module RenderAsync
4
4
  module ViewHelper
5
5
 
6
+ def render_async_cache_key(path)
7
+ "render_async_#{path}"
8
+ end
9
+
10
+ def render_async_cache(path, html_options = {})
11
+ cached_view = Rails.cache.read("views/#{render_async_cache_key(path)}")
12
+ if cached_view.present?
13
+ render :html => cached_view.html_safe
14
+ else
15
+ render_async(path, html_options)
16
+ end
17
+ end
18
+
6
19
  def render_async(path, html_options = {})
7
20
  container_name = "render_async_#{SecureRandom.hex(5)}#{Time.now.to_i}"
8
21
 
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.2.3
4
+ version: 0.3.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-07-11 00:00:00.000000000 Z
12
+ date: 2017-09-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -60,6 +60,7 @@ executables: []
60
60
  extensions: []
61
61
  extra_rdoc_files: []
62
62
  files:
63
+ - ".all-contributorsrc"
63
64
  - ".gitignore"
64
65
  - ".rspec"
65
66
  - Gemfile