get_schwifty 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +160 -0
- data/Rakefile +33 -0
- data/app/assets/javascripts/get_schwifty.js +44 -0
- data/lib/generators/get_schwifty/cable_generator.rb +20 -0
- data/lib/generators/get_schwifty/install_generator.rb +42 -0
- data/lib/generators/templates/CABLE +38 -0
- data/lib/generators/templates/INSTALL +26 -0
- data/lib/generators/templates/assets/javascripts/get_schwifty_channel.js +3 -0
- data/lib/generators/templates/cables/base_cable.rb +10 -0
- data/lib/generators/templates/cables/cable.rb +16 -0
- data/lib/generators/templates/channels/get_schwifty_channel.rb +4 -0
- data/lib/generators/templates/controllers/get_schwifty_controller.rb +4 -0
- data/lib/generators/templates/jobs/get_schwifty_runner_job.rb +4 -0
- data/lib/generators/templates/views/cables/action.html.erb +1 -0
- data/lib/get_schwifty/cable/base.rb +22 -0
- data/lib/get_schwifty/channel.rb +40 -0
- data/lib/get_schwifty/helper.rb +25 -0
- data/lib/get_schwifty/job.rb +7 -0
- data/lib/get_schwifty/version.rb +3 -0
- data/lib/get_schwifty.rb +16 -0
- data/lib/tasks/get_schwifty_tasks.rake +4 -0
- metadata +151 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f937f9b21a7ac4b56fff5a6502f91a8ab92c8a15
|
4
|
+
data.tar.gz: 4118a97184ccef0f2f8d793c53e6a5856b840b15
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: afebf12398a35645ca1aea418a6c2a988160336d9e0916010ac339d95c2c0b5b624191cb2dd3290f3a1ac81dcea59fe1155a135ae890c036ac5310885d525661
|
7
|
+
data.tar.gz: 0c08a37cb35a502231f25865157276e91ac3f4c08d5c798802f4d01dba75a666710fd1913421389e392e40a17e745b3778370e9f8949816f6639dd95c78b6ee6
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2017 Daniel Westendorf
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
# GetSchwifty
|
2
|
+
>Oh, yeah!
|
3
|
+
You gotta get schwifty.
|
4
|
+
You gotta get schwifty in here.
|
5
|
+
|
6
|
+
GetSchwifty is a Rails plugin for rendering slow view partials in a background job and sending them to the client over ActionCable websockets.
|
7
|
+
|
8
|
+
## Justification
|
9
|
+
|
10
|
+
Slow-to-render HTML elements can be expensive (hosting) and unavoidable (technical debt, slow libs, expensive db queries, etc). Rendering in-line in your web server consumes a connection which could be serving other clients. Sometimes it's better to just return a minimal page quickly, and let the data backfill as it's generated.
|
11
|
+
|
12
|
+
GetSchwifty is all about quick responses by utilizing background jobs to do the rendering for your and delivering it to the client with ActionCable.
|
13
|
+
|
14
|
+
## Installation
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem "get_schwifty"
|
19
|
+
```
|
20
|
+
|
21
|
+
And then execute:
|
22
|
+
```bash
|
23
|
+
$ bundle
|
24
|
+
```
|
25
|
+
|
26
|
+
Or install it yourself as:
|
27
|
+
```bash
|
28
|
+
$ gem install get_schwifty
|
29
|
+
```
|
30
|
+
|
31
|
+
Install the plugin
|
32
|
+
```bash
|
33
|
+
$ rails generate get_schwifty:install
|
34
|
+
```
|
35
|
+
Follow the instructions printed.
|
36
|
+
|
37
|
+
|
38
|
+
## Usage
|
39
|
+
|
40
|
+
Generate your first GetSchwifty Cable
|
41
|
+
```bash
|
42
|
+
$ rails generate get_schwifty:cable Calculator fibonacci
|
43
|
+
```
|
44
|
+
|
45
|
+
Cables are a place to put your data access logic. Think Controllers for each GetSchwifty cable.
|
46
|
+
```ruby
|
47
|
+
# app/cables/calculator_cable.rb
|
48
|
+
|
49
|
+
class CalculatorCable < BaseCable
|
50
|
+
def fibonacci
|
51
|
+
n = SecureRandom.rand(30..40)
|
52
|
+
calculated = calculate_fibonacci(n)
|
53
|
+
stream partial: "calculator/fibonacci", locals: { calculated: calculated, n: n }
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def calculate_fibonacci(n)
|
59
|
+
return n if n <= 1
|
60
|
+
calculate_fibonacci( n - 1 ) + calculate_fibonacci( n - 2 )
|
61
|
+
end
|
62
|
+
end
|
63
|
+
```
|
64
|
+
|
65
|
+
When the data has been queried/generated, the partial is rendered. `stream` is a wrapper around the normal Rails `render`.
|
66
|
+
|
67
|
+
```erb
|
68
|
+
# app/views/cables/calculator/_fibonacci.html.erb
|
69
|
+
<p class="take-off-your-pants">
|
70
|
+
Fibonacci of <%= n %> is <%= calculated %>
|
71
|
+
</p>
|
72
|
+
|
73
|
+
```
|
74
|
+
|
75
|
+
Lastly, we need to tell the app where to render this chunk of HTML. GetSchwifty uses a similar routing syntax to Rails routes of `cablecontrollername#action`.
|
76
|
+
|
77
|
+
```erb
|
78
|
+
# app/views/yourpage.html.erb
|
79
|
+
... Other HTML ...
|
80
|
+
<%= get_schwifty "calculator#fibonacci" do %>
|
81
|
+
<p>
|
82
|
+
This will get displayed while the cable is waiting to get schwifty.
|
83
|
+
Maybe markup for a loading animation?
|
84
|
+
</p>
|
85
|
+
<%- end %>
|
86
|
+
... Other HTML ...
|
87
|
+
```
|
88
|
+
|
89
|
+
Load the page, and you should get the whole page back quickly, while the Fibonacci comes later.
|
90
|
+
|
91
|
+
### Identifiers & Params
|
92
|
+
|
93
|
+
Random data isn't very useful. Unauthenticated data isn't very cool either. Usually in Rails data scoping belongs starts at a current_user method. GetSchwifty will make any identefiers or params made available in the channel subscription within your cables. Let's take a look at an example.
|
94
|
+
|
95
|
+
#### Identifiers
|
96
|
+
Here we'll find the current user. This is copied form the [Rails Guides](http://guides.rubyonrails.org/action_cable_overview.html#connection-setup).
|
97
|
+
``` ruby
|
98
|
+
# app/channels/connection.rb
|
99
|
+
module ApplicationCable
|
100
|
+
class Connection < ActionCable::Connection::Base
|
101
|
+
identified_by :current_user
|
102
|
+
|
103
|
+
def connect
|
104
|
+
self.current_user = find_verified_user
|
105
|
+
end
|
106
|
+
|
107
|
+
private
|
108
|
+
|
109
|
+
def find_verified_user
|
110
|
+
if current_user = User.find_by(id: cookies.signed[:user_id])
|
111
|
+
current_user
|
112
|
+
else
|
113
|
+
reject_unauthorized_connection
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
```
|
119
|
+
|
120
|
+
Let's assume the `User#fibonacci` returns and integer to use in the `CalculatorCable#fibonacci`.
|
121
|
+
```ruby
|
122
|
+
# app/cables/calculator_cable.rb
|
123
|
+
|
124
|
+
class CalculatorCable < BaseCable
|
125
|
+
def fibonacci
|
126
|
+
n = identifiers[:current_user]
|
127
|
+
... same code as before ..
|
128
|
+
end
|
129
|
+
end
|
130
|
+
```
|
131
|
+
|
132
|
+
Similarly, any other identifiers created in the connection will follow suite and be made available in your cable. Additionally, you may want to add getter methods to `BaseCable` make accessing identifiers easier.
|
133
|
+
|
134
|
+
#### Params
|
135
|
+
|
136
|
+
Code reusability is the Rails way, so maybe we need to tweak how the cable's action is invoked dynamically, based on where the HTML is to be rendered. This is easy as pie, simply pass a hash of parameters to the `get_schwifty` view helper.
|
137
|
+
|
138
|
+
```erb
|
139
|
+
# app/views/yourpage.html.erb
|
140
|
+
... Other HTML ...
|
141
|
+
<%= get_schwifty "calculator#fibonacci", min_start: 3 do %>
|
142
|
+
... same as before ...
|
143
|
+
<%- end %>
|
144
|
+
... Other HTML ...
|
145
|
+
```
|
146
|
+
|
147
|
+
These params will be available in your cable action.
|
148
|
+
```ruby
|
149
|
+
# app/cables/calculator_cable.rb
|
150
|
+
|
151
|
+
class CalculatorCable < BaseCable
|
152
|
+
def fibonacci
|
153
|
+
n = SecureRandom.rand(params[:min_start]..40)
|
154
|
+
... same code as before ..
|
155
|
+
end
|
156
|
+
end
|
157
|
+
```
|
158
|
+
|
159
|
+
## License
|
160
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'GetSchwifty'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
require 'bundler/gem_tasks'
|
23
|
+
|
24
|
+
require 'rake/testtask'
|
25
|
+
|
26
|
+
Rake::TestTask.new(:test) do |t|
|
27
|
+
t.libs << 'test'
|
28
|
+
t.pattern = 'test/**/*_test.rb'
|
29
|
+
t.verbose = false
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
task default: :test
|
@@ -0,0 +1,44 @@
|
|
1
|
+
GetSchwifty = function(app) {
|
2
|
+
_App = app;
|
3
|
+
|
4
|
+
function dispatchEvent(ev, el, data) {
|
5
|
+
data = data || {}
|
6
|
+
var event = new CustomEvent('getSchwifty.' + ev, {
|
7
|
+
detail: data,
|
8
|
+
bubbles: true
|
9
|
+
});
|
10
|
+
el.dispatchEvent(event)
|
11
|
+
};
|
12
|
+
|
13
|
+
return {
|
14
|
+
showMeWhatYouGot: function(selector) {
|
15
|
+
selector = selector || '';
|
16
|
+
|
17
|
+
[].forEach.call(document.querySelectorAll(selector + ' [data-get-schwifty]'), function(el) {
|
18
|
+
var schwiftyJobId = el.getAttribute('data-get-schwifty');
|
19
|
+
var schwiftyParams = JSON.parse(el.getAttribute('data-get-schwifty-params')) || {};
|
20
|
+
|
21
|
+
dispatchEvent('subscribe:before', el, { schwiftyJobId: schwiftyJobId, paschwiftyParamsrams: schwiftyParams });
|
22
|
+
|
23
|
+
var subscription = Object.assign({ channel: "GetSchwiftyChannel", id: schwiftyJobId }, schwiftyParams);
|
24
|
+
|
25
|
+
var cable = _App.cable.subscriptions.create(subscription, {
|
26
|
+
received: function(html) {
|
27
|
+
dispatchEvent('render:before', el, { schwiftyJobId: schwiftyJobId, html: html });
|
28
|
+
|
29
|
+
var newContent = document.createRange().createContextualFragment(html);
|
30
|
+
var newEl = newContent.firstChild;
|
31
|
+
el.parentNode.replaceChild(newContent, el)
|
32
|
+
|
33
|
+
dispatchEvent('render:after', newEl, { schwiftyJobId: schwiftyJobId, html: html });
|
34
|
+
|
35
|
+
cable.perform('rendered');
|
36
|
+
cable.unsubscribe();
|
37
|
+
}
|
38
|
+
});
|
39
|
+
|
40
|
+
dispatchEvent('subscribe:after', el, { schwiftyJobId: schwiftyJobId })
|
41
|
+
});
|
42
|
+
}
|
43
|
+
};
|
44
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module GetSchwifty
|
2
|
+
module Generators
|
3
|
+
class CableGenerator < Rails::Generators::NamedBase
|
4
|
+
source_root File.expand_path("../../templates", __FILE__)
|
5
|
+
argument :actions, type: :array, default: [], banner: "action action"
|
6
|
+
|
7
|
+
def create_cable_files
|
8
|
+
template "cables/cable.rb", File.join("app", "cables", class_path, "#{file_name}_cable.rb")
|
9
|
+
|
10
|
+
actions.each do |action|
|
11
|
+
template "views/cables/action.html.erb", File.join("app", "views", "cables", class_path, file_name, "_#{action}.html.erb")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def print_readme
|
16
|
+
readme "CABLE"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module GetSchwifty
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
source_root File.expand_path("../../templates", __FILE__)
|
5
|
+
|
6
|
+
desc "Installs required files for getting schwifty in here"
|
7
|
+
|
8
|
+
def copy_controller
|
9
|
+
template "controllers/get_schwifty_controller.rb", "app/controllers/get_schwifty_controller.rb"
|
10
|
+
end
|
11
|
+
|
12
|
+
def copy_channel
|
13
|
+
template "channels/get_schwifty_channel.rb", "app/channels/get_schwifty_channel.rb"
|
14
|
+
end
|
15
|
+
|
16
|
+
def copy_job
|
17
|
+
template "jobs/get_schwifty_runner_job.rb", "app/jobs/get_schwifty_runner_job.rb"
|
18
|
+
end
|
19
|
+
|
20
|
+
def create_cables_directories
|
21
|
+
empty_directory "app/cables"
|
22
|
+
empty_directory "app/views/cables"
|
23
|
+
end
|
24
|
+
|
25
|
+
def copy_base_cable
|
26
|
+
template "cables/base_cable.rb", "app/cables/base_cable.rb"
|
27
|
+
end
|
28
|
+
|
29
|
+
def autoload_cables_path
|
30
|
+
application %(config.autoload_paths << config.root.join("app", "cables"))
|
31
|
+
end
|
32
|
+
|
33
|
+
def copy_get_schwifty_channel_js
|
34
|
+
template "assets/javascripts/get_schwifty_channel.js", "app/assets/javascripts/channels/get_schwifty_channel.js"
|
35
|
+
end
|
36
|
+
|
37
|
+
def print_readme
|
38
|
+
readme "INSTALL"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
===============================================================================
|
2
|
+
|
3
|
+
How to use your cable:
|
4
|
+
|
5
|
+
1. Use the get_schwifty view helper to insert the cable into your markup.
|
6
|
+
|
7
|
+
<%= get_schwifty "dashboard#fibonacci" do %>
|
8
|
+
<p>
|
9
|
+
This will get displayed while the cable is waiting to get schwifty.
|
10
|
+
Maybe markup for a loading animation?
|
11
|
+
</p>
|
12
|
+
<%- end %>
|
13
|
+
|
14
|
+
2. Update your cable action to implement the slow performing code. This code
|
15
|
+
will get schwifty in your background job queue.
|
16
|
+
|
17
|
+
# app/cables/dashboard.rb
|
18
|
+
def fibonacci
|
19
|
+
n = SecureRandom.rand(20..40)
|
20
|
+
calculated = calculate_fibonacci(n)
|
21
|
+
stream partial: "dashboard/fibonacci", locals: { calculated: calculated, n: n }
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def calculate_fibonacci(n)
|
27
|
+
return n if n <= 1
|
28
|
+
calculate_fibonacci( n - 1 ) + calculate_fibonacci( n - 2 )
|
29
|
+
end
|
30
|
+
|
31
|
+
3. Implement the partial view for the cable action.
|
32
|
+
|
33
|
+
# app/views/cables/dashboard/_fibonacci.html.erb
|
34
|
+
<p>
|
35
|
+
Fibonacci of <%= n %>: <%= calculated %>
|
36
|
+
</p>
|
37
|
+
|
38
|
+
===============================================================================
|
@@ -0,0 +1,26 @@
|
|
1
|
+
===============================================================================
|
2
|
+
|
3
|
+
Some setup you must do manually if you haven't yet:
|
4
|
+
|
5
|
+
1. Restart your server. app/cables has been added to the load path, and it
|
6
|
+
is necessary to restart your web server and any non-async job queues.
|
7
|
+
|
8
|
+
ActionCable requires that you use a servers such as Puma as your development
|
9
|
+
webserver.
|
10
|
+
|
11
|
+
2. Ensure you're using a shared cache store. Rails by default uses an
|
12
|
+
in-memory cache store, which can't be accessed between processes.
|
13
|
+
http://guides.rubyonrails.org/caching_with_rails.html#activesupport-cache-filestore
|
14
|
+
|
15
|
+
# config/environments/development.rb
|
16
|
+
config.cache_store = :file_store, "tmp/cache"
|
17
|
+
|
18
|
+
3. Add the get_schwifty javascript to your application.js
|
19
|
+
|
20
|
+
//= require get_schwifty
|
21
|
+
|
22
|
+
4. Setup your first cable to get schwifty
|
23
|
+
|
24
|
+
rails g get_schwifty:cable Dashboard fibonacci
|
25
|
+
|
26
|
+
===============================================================================
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# Base cable class to inherit from when getting schwifty
|
2
|
+
class BaseCable < GetSchwifty::Cable::Base
|
3
|
+
# Access to pundit helper methods for authorization
|
4
|
+
# include Pundit
|
5
|
+
|
6
|
+
# Utility method shared accross cables for accessing the current user
|
7
|
+
# def current_user
|
8
|
+
# identifiers[:user]
|
9
|
+
# end
|
10
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<% if namespaced? -%>
|
2
|
+
require_dependency "<%= namespaced_class_path %>/application_cable"
|
3
|
+
<% end -%>
|
4
|
+
<% module_namespacing do -%>
|
5
|
+
class <%= class_name %>Cable < BaseCable
|
6
|
+
<% actions.each do |action| -%>
|
7
|
+
def <%= action %>
|
8
|
+
a = 1
|
9
|
+
b = 2
|
10
|
+
|
11
|
+
stream partial: "<%= class_name.underscore %>/<%= action %>", locals: { a: a, b: b }
|
12
|
+
end
|
13
|
+
<%= "\n" unless action == actions.last -%>
|
14
|
+
<% end -%>
|
15
|
+
end
|
16
|
+
<% end -%>
|
@@ -0,0 +1 @@
|
|
1
|
+
<!-- Slow to generate HTML goes here -->
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module GetSchwifty
|
2
|
+
module Cable
|
3
|
+
class Base
|
4
|
+
attr_reader :schwifty_job_id, :identifiers, :params
|
5
|
+
|
6
|
+
def initialize(schwifty_job_id, params, identifiers)
|
7
|
+
@schwifty_job_id = schwifty_job_id
|
8
|
+
@identifiers = identifiers.symbolize_keys!
|
9
|
+
@params = params
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def stream(*args)
|
15
|
+
ActionCable.server.broadcast(
|
16
|
+
schwifty_job_id,
|
17
|
+
GetSchwiftyController.renderer.new.render(*args).squish
|
18
|
+
)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module GetSchwifty
|
2
|
+
module Channel
|
3
|
+
def subscribed
|
4
|
+
reject if route.blank?
|
5
|
+
|
6
|
+
stream_from channel_name
|
7
|
+
GetSchwiftyRunnerJob.perform_later(channel_name, controller, action, params, *identifiers.flatten)
|
8
|
+
end
|
9
|
+
|
10
|
+
def rendered
|
11
|
+
Rails.cache.write(channel_name, nil)
|
12
|
+
end
|
13
|
+
|
14
|
+
def route
|
15
|
+
Rails.cache.read(channel_name)
|
16
|
+
end
|
17
|
+
|
18
|
+
def controller
|
19
|
+
(route.split("#").first + "_cable").camelize
|
20
|
+
end
|
21
|
+
|
22
|
+
def action
|
23
|
+
route.split("#").last
|
24
|
+
end
|
25
|
+
|
26
|
+
def identifiers
|
27
|
+
connection.identifiers.collect do |key|
|
28
|
+
[key.to_s, send(key)]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def schwifty_job_id
|
33
|
+
params[:id]
|
34
|
+
end
|
35
|
+
|
36
|
+
def channel_name
|
37
|
+
"get_schwifty:#{schwifty_job_id}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module GetSchwifty
|
2
|
+
module Helper
|
3
|
+
def get_schwifty(route, params = nil, &blk)
|
4
|
+
id = SecureRandom.hex
|
5
|
+
Rails.cache.write("get_schwifty:#{id}", route, expires_in: 10.minutes)
|
6
|
+
|
7
|
+
opts = {
|
8
|
+
"data-get-schwifty" => id
|
9
|
+
}
|
10
|
+
|
11
|
+
opts["data-get-schwifty-params"] = params.to_json if params
|
12
|
+
|
13
|
+
args = [
|
14
|
+
:div, nil, opts
|
15
|
+
]
|
16
|
+
|
17
|
+
if block_given?
|
18
|
+
args.reject!(&:nil?)
|
19
|
+
return content_tag(*args, &blk)
|
20
|
+
end
|
21
|
+
|
22
|
+
content_tag(*args)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/get_schwifty.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require "get_schwifty/helper"
|
2
|
+
require "get_schwifty/channel"
|
3
|
+
require "get_schwifty/job"
|
4
|
+
require "get_schwifty/cable/base"
|
5
|
+
|
6
|
+
module GetSchwifty
|
7
|
+
class Engine < ::Rails::Engine
|
8
|
+
config.assets.paths += [File.expand_path("../../app/assets/javascripts", __FILE__)] if config.respond_to?(:assets)
|
9
|
+
|
10
|
+
initializer :get_schwifty do |app|
|
11
|
+
ActiveSupport.on_load(:action_view) do
|
12
|
+
include GetSchwifty::Helper
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: get_schwifty
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Daniel Westendorf
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-09-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: puma
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: capybara
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: selenium-webdriver
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sqlite3
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: redis
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: "\n Offload the rendering of slow view partials with
|
98
|
+
ActiveJob and ActionCable to reduce page load times.\n "
|
99
|
+
email:
|
100
|
+
- daniel@prowestech.com
|
101
|
+
executables: []
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- MIT-LICENSE
|
106
|
+
- README.md
|
107
|
+
- Rakefile
|
108
|
+
- app/assets/javascripts/get_schwifty.js
|
109
|
+
- lib/generators/get_schwifty/cable_generator.rb
|
110
|
+
- lib/generators/get_schwifty/install_generator.rb
|
111
|
+
- lib/generators/templates/CABLE
|
112
|
+
- lib/generators/templates/INSTALL
|
113
|
+
- lib/generators/templates/assets/javascripts/get_schwifty_channel.js
|
114
|
+
- lib/generators/templates/cables/base_cable.rb
|
115
|
+
- lib/generators/templates/cables/cable.rb
|
116
|
+
- lib/generators/templates/channels/get_schwifty_channel.rb
|
117
|
+
- lib/generators/templates/controllers/get_schwifty_controller.rb
|
118
|
+
- lib/generators/templates/jobs/get_schwifty_runner_job.rb
|
119
|
+
- lib/generators/templates/views/cables/action.html.erb
|
120
|
+
- lib/get_schwifty.rb
|
121
|
+
- lib/get_schwifty/cable/base.rb
|
122
|
+
- lib/get_schwifty/channel.rb
|
123
|
+
- lib/get_schwifty/helper.rb
|
124
|
+
- lib/get_schwifty/job.rb
|
125
|
+
- lib/get_schwifty/version.rb
|
126
|
+
- lib/tasks/get_schwifty_tasks.rake
|
127
|
+
homepage: https://github.com/danielwestendorf/get_schwifty
|
128
|
+
licenses:
|
129
|
+
- MIT
|
130
|
+
metadata: {}
|
131
|
+
post_install_message:
|
132
|
+
rdoc_options: []
|
133
|
+
require_paths:
|
134
|
+
- lib
|
135
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
requirements: []
|
146
|
+
rubyforge_project:
|
147
|
+
rubygems_version: 2.6.13
|
148
|
+
signing_key:
|
149
|
+
specification_version: 4
|
150
|
+
summary: Render view partials with ActiveJob and ActionCable.
|
151
|
+
test_files: []
|