render_async 0.0.2 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitmodules +4 -0
- data/.rspec +2 -0
- data/LICENSE +21 -0
- data/README.md +73 -42
- data/Rakefile +5 -0
- data/app/views/render_async/_render_async.html.erb +18 -8
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/render_async.rb +3 -1
- data/lib/render_async/engine.rb +5 -0
- data/lib/render_async/version.rb +1 -1
- data/lib/render_async/view_helper.rb +14 -0
- data/render_async.gemspec +14 -10
- metadata +44 -31
- data/lib/render_async/rails/engine.rb +0 -7
- data/lib/render_async/railtie.rb +0 -11
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1519f96a0247273fcf694f6a85bae9d668ee92db
|
4
|
+
data.tar.gz: 4a709ff43dbb29a8bccf09e285fe0e63f224aa2b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 69aa88dbe5172447b87eb4da7cdf4b0869daa8d17b890f119e11b3a97b3ada3d35938f9f13cd54998596add714fd6cf270f3114ed1cc9054c74ff007fa9a1547
|
7
|
+
data.tar.gz: c3cafb358d191c916c8e57d1819e967e241811c1020f27f6b36830412dfa51640c02eb0402465dabb566509461021fcddd66fd30b6a94694baa7e1623462776c
|
data/.gitmodules
ADDED
data/.rspec
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2016 Rendered Text
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
CHANGED
@@ -1,62 +1,93 @@
|
|
1
|
+
[![Build Status](https://semaphoreci.com/api/v1/renderedtext/render_async/branches/master/badge.svg)](https://semaphoreci.com/renderedtext/render_async)
|
2
|
+
|
1
3
|
# RenderAsync
|
2
4
|
|
3
|
-
|
5
|
+
Renders partials to your views **asynchronously**. This is done through adding
|
6
|
+
Javascript code that does AJAX request to your controller which then renders
|
7
|
+
your partial.
|
4
8
|
|
5
|
-
|
6
|
-
# routes.rb:
|
7
|
-
match 'articles/counter' => 'articles#counter', :as => :articles_counter
|
8
|
-
# ^ Of course you won't use match, but you get the idea.
|
9
|
+
Workflow:
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
1. user visits a page =>
|
12
|
+
2. AJAX request on the controller action =>
|
13
|
+
3. controller renders a partial =>
|
14
|
+
4. partials renders in the place where you put `render_async` helper
|
13
15
|
|
14
|
-
|
15
|
-
|
16
|
-
```html
|
17
|
-
<div id="render_async_1a931cec881377296672"></div>
|
18
|
-
|
19
|
-
<script type="text/javascript">
|
20
|
-
(function($){
|
21
|
-
div_elem = $("#render_async_1a931cec881377296672");
|
22
|
-
$.ajax({
|
23
|
-
url: "/articles/counter",
|
24
|
-
success: function(response, status) {
|
25
|
-
div_elem.html(response);
|
26
|
-
}
|
27
|
-
});
|
28
|
-
}(jQuery));
|
29
|
-
</script>
|
30
|
-
```
|
16
|
+
Javascript is injected into `<%= content_for :render_async %>` so you choose
|
17
|
+
where to put it.
|
31
18
|
|
32
|
-
##
|
19
|
+
## Installation
|
33
20
|
|
34
|
-
|
21
|
+
Add this line to your application's Gemfile:
|
35
22
|
|
36
|
-
```
|
37
|
-
|
23
|
+
```ruby
|
24
|
+
gem 'render_async', :source => "https://gem.fury.io/renderedtext/"
|
38
25
|
```
|
39
26
|
|
40
|
-
And
|
27
|
+
And then execute:
|
41
28
|
|
42
|
-
|
29
|
+
$ bundle
|
43
30
|
|
44
|
-
|
31
|
+
## Usage
|
45
32
|
|
46
|
-
|
33
|
+
1. Include `render_async` view helper somewhere in your views:
|
47
34
|
|
48
|
-
|
35
|
+
```ruby
|
36
|
+
# app/views/comments/show.html.erb
|
49
37
|
|
50
|
-
|
38
|
+
<%= render_async comment_stats_path %>
|
39
|
+
```
|
51
40
|
|
52
|
-
|
41
|
+
2. Then create a route that will `config/routes.rb`
|
42
|
+
```ruby
|
43
|
+
# config/routes.rb
|
53
44
|
|
54
|
-
|
45
|
+
get :comment_stats, :controller => :comments
|
46
|
+
```
|
47
|
+
|
48
|
+
3. Fill in the logic in your controller
|
49
|
+
```ruby
|
50
|
+
# app/controllers/comments_controller.rb
|
51
|
+
|
52
|
+
def comment_stats
|
53
|
+
@stats = Comment.get_stats
|
54
|
+
|
55
|
+
render :patial => "comment_stats"
|
56
|
+
end
|
57
|
+
```
|
58
|
+
|
59
|
+
4. Create a partial that will render
|
60
|
+
```ruby
|
61
|
+
# app/views/comments/_comment_stats.html.erb
|
62
|
+
|
63
|
+
<div class="col-md-6">
|
64
|
+
<%= @stats %>
|
65
|
+
</div>
|
66
|
+
```
|
67
|
+
|
68
|
+
5. Add `content_for` in your base view file
|
69
|
+
```ruby
|
70
|
+
# application.html.erb
|
71
|
+
|
72
|
+
<%= content_for :render_async %>
|
73
|
+
```
|
74
|
+
|
75
|
+
## Development
|
76
|
+
|
77
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
78
|
+
`rake spec` to run the tests. You can also run `bin/console` for an interactive
|
79
|
+
prompt that will allow you to experiment.
|
80
|
+
|
81
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To
|
82
|
+
release a new version, update the version number in `version.rb`, and then run
|
83
|
+
`bundle exec rake release`, which will create a git tag for the version, push
|
84
|
+
git commits and tags, and push the `.gem` file to
|
85
|
+
[rubygems.org](https://rubygems.org).
|
55
86
|
|
56
87
|
## Contributing
|
57
88
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
89
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/renderedtext/render_async.
|
90
|
+
|
91
|
+
## License
|
92
|
+
|
93
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
CHANGED
@@ -1,15 +1,25 @@
|
|
1
|
-
<div id="<%= container_name %>"
|
1
|
+
<div id="<%= container_name %>">
|
2
|
+
<div id="<%= container_name %>_spinner" class="sk-spinner sk-spinner-double-bounce">
|
3
|
+
<div class="sk-double-bounce1"></div>
|
4
|
+
<div class="sk-double-bounce2"></div>
|
5
|
+
</div>
|
6
|
+
</div>
|
2
7
|
|
3
|
-
<% content_for :
|
8
|
+
<% content_for :render_async do %>
|
4
9
|
<script type="text/javascript">
|
5
10
|
(function($){
|
6
|
-
div_elem = $("#<%= container_name %>");
|
7
11
|
$.ajax({
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
12
|
+
url: "<%= path %>",
|
13
|
+
})
|
14
|
+
.done(function(response, status) {
|
15
|
+
$("#<%= container_name %>").html(response);
|
16
|
+
})
|
17
|
+
.fail(function(response, status) {
|
18
|
+
$("#<%= container_name %>").html(response);
|
19
|
+
})
|
20
|
+
.always(function(response, status) {
|
21
|
+
$("#<%= container_name %>_spinner").hide();
|
22
|
+
});
|
13
23
|
}(jQuery));
|
14
24
|
</script>
|
15
25
|
<% end %>
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "render_async"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/render_async.rb
CHANGED
data/lib/render_async/version.rb
CHANGED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
|
3
|
+
module RenderAsync
|
4
|
+
module ViewHelper
|
5
|
+
|
6
|
+
def render_async(path)
|
7
|
+
container_name = "render_async_#{SecureRandom.hex(5)}#{Time.now.to_i}"
|
8
|
+
|
9
|
+
render "render_async/render_async", :container_name => container_name,
|
10
|
+
:path => path
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
data/render_async.gemspec
CHANGED
@@ -6,18 +6,22 @@ require 'render_async/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "render_async"
|
8
8
|
spec.version = RenderAsync::VERSION
|
9
|
-
spec.authors = ["Kasper Grubbe"]
|
10
|
-
spec.email = ["
|
11
|
-
|
12
|
-
spec.summary =
|
13
|
-
spec.
|
9
|
+
spec.authors = ["Kasper Grubbe", "nikolalsvk"]
|
10
|
+
spec.email = ["nikolaseap@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "Render parts of the page asynchronously with AJAX"
|
13
|
+
spec.description = "Load parts of your page through simple Javascript and Rails pipeline"
|
14
|
+
spec.homepage = "https://github.com/renderedtext/render_async"
|
14
15
|
spec.license = "MIT"
|
15
16
|
|
16
|
-
spec.files = `git ls-files`.split(
|
17
|
-
|
18
|
-
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
22
|
spec.require_paths = ["lib"]
|
20
23
|
|
21
|
-
spec.
|
22
|
-
spec.add_development_dependency "rake"
|
24
|
+
spec.add_dependency "bundler", "~> 1.8"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.2"
|
23
27
|
end
|
metadata
CHANGED
@@ -1,91 +1,104 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: render_async
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Kasper Grubbe
|
8
|
+
- nikolalsvk
|
9
9
|
autorequire:
|
10
|
-
bindir:
|
10
|
+
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2017-05-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
17
|
requirements:
|
19
|
-
- - ~>
|
18
|
+
- - "~>"
|
20
19
|
- !ruby/object:Gem::Version
|
21
|
-
version: '1.
|
22
|
-
type: :
|
20
|
+
version: '1.8'
|
21
|
+
type: :runtime
|
23
22
|
prerelease: false
|
24
23
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
24
|
requirements:
|
27
|
-
- - ~>
|
25
|
+
- - "~>"
|
28
26
|
- !ruby/object:Gem::Version
|
29
|
-
version: '1.
|
27
|
+
version: '1.8'
|
30
28
|
- !ruby/object:Gem::Dependency
|
31
29
|
name: rake
|
32
30
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
31
|
requirements:
|
35
|
-
- -
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '10.0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '10.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rspec
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
36
47
|
- !ruby/object:Gem::Version
|
37
|
-
version: '
|
48
|
+
version: '3.2'
|
38
49
|
type: :development
|
39
50
|
prerelease: false
|
40
51
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
52
|
requirements:
|
43
|
-
- -
|
53
|
+
- - "~>"
|
44
54
|
- !ruby/object:Gem::Version
|
45
|
-
version: '
|
46
|
-
description:
|
55
|
+
version: '3.2'
|
56
|
+
description: Load parts of your page through simple Javascript and Rails pipeline
|
47
57
|
email:
|
48
|
-
-
|
58
|
+
- nikolaseap@gmail.com
|
49
59
|
executables: []
|
50
60
|
extensions: []
|
51
61
|
extra_rdoc_files: []
|
52
62
|
files:
|
53
|
-
- .gitignore
|
63
|
+
- ".gitignore"
|
64
|
+
- ".gitmodules"
|
65
|
+
- ".rspec"
|
54
66
|
- Gemfile
|
67
|
+
- LICENSE
|
55
68
|
- LICENSE.txt
|
56
69
|
- README.md
|
57
70
|
- Rakefile
|
58
71
|
- app/views/render_async/_render_async.html.erb
|
72
|
+
- bin/console
|
73
|
+
- bin/setup
|
59
74
|
- lib/render_async.rb
|
60
|
-
- lib/render_async/
|
61
|
-
- lib/render_async/railtie.rb
|
75
|
+
- lib/render_async/engine.rb
|
62
76
|
- lib/render_async/version.rb
|
77
|
+
- lib/render_async/view_helper.rb
|
63
78
|
- lib/render_async/view_helpers.rb
|
64
79
|
- render_async.gemspec
|
65
|
-
homepage: https://github.com/
|
80
|
+
homepage: https://github.com/renderedtext/render_async
|
66
81
|
licenses:
|
67
82
|
- MIT
|
83
|
+
metadata: {}
|
68
84
|
post_install_message:
|
69
85
|
rdoc_options: []
|
70
86
|
require_paths:
|
71
87
|
- lib
|
72
88
|
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
89
|
requirements:
|
75
|
-
- -
|
90
|
+
- - ">="
|
76
91
|
- !ruby/object:Gem::Version
|
77
92
|
version: '0'
|
78
93
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
-
none: false
|
80
94
|
requirements:
|
81
|
-
- -
|
95
|
+
- - ">="
|
82
96
|
- !ruby/object:Gem::Version
|
83
97
|
version: '0'
|
84
98
|
requirements: []
|
85
99
|
rubyforge_project:
|
86
|
-
rubygems_version:
|
100
|
+
rubygems_version: 2.4.5.2
|
87
101
|
signing_key:
|
88
|
-
specification_version:
|
89
|
-
summary:
|
102
|
+
specification_version: 4
|
103
|
+
summary: Render parts of the page asynchronously with AJAX
|
90
104
|
test_files: []
|
91
|
-
has_rdoc:
|
data/lib/render_async/railtie.rb
DELETED