futurism 0.5.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +76 -1
- data/lib/futurism.rb +5 -0
- data/lib/futurism.rb~ +12 -1
- data/lib/futurism/channel.rb +16 -10
- data/lib/futurism/channel.rb~ +17 -11
- data/lib/futurism/helpers.rb +23 -4
- data/lib/futurism/helpers.rb~ +23 -4
- data/lib/futurism/message_verifier.rb +11 -0
- data/lib/futurism/resolver/controller.rb +21 -0
- data/lib/futurism/resolver/controller/renderer.rb +57 -0
- data/lib/futurism/resolver/controller/renderer.rb~ +57 -0
- data/lib/futurism/version.rb +1 -1
- metadata +6 -17
- data/app/assets/config/futurism_manifest.js +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b49e6ebab4db767a2f7aaa4fbc6500ed4103787ea3abefc0489ef6a1536c4fec
|
4
|
+
data.tar.gz: 066ab614d937281fe22e5a6d17b8873370c29649815be1b966e2bc22e7cf4ed0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 638f1eb1bb3fb7304024282419ae2f3baa92a8e9cafe60d31ece08ba837925279005ce905b4acec2c68a6673f430b6b29fec8f4ee9fee5232539c2ea827f54ba
|
7
|
+
data.tar.gz: 5d9a0f5d66ee06ea62b6875b4cf19bab6a22c0b0f272ddacfbe2ad0f5d8f06b4a288c32a6863f5d9c4e65de4b9df3799343fff5a5086a06597e9b23a66c9ab53
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Futurism
|
2
2
|
[![Twitter follow](https://img.shields.io/twitter/follow/julian_rubisch?style=social)](https://twitter.com/julian_rubisch)
|
3
3
|
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
4
|
-
[![All Contributors](https://img.shields.io/badge/all_contributors-
|
4
|
+
[![All Contributors](https://img.shields.io/badge/all_contributors-13-orange.svg?style=flat-square)](#contributors-)
|
5
5
|
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
6
6
|
Lazy-load Rails partials via CableReady
|
7
7
|
|
@@ -20,10 +20,12 @@ Lazy-load Rails partials via CableReady
|
|
20
20
|
- [Resource](#resource)
|
21
21
|
- [Explicit Partial](#explicit-partial)
|
22
22
|
- [HTML Options](#html-options)
|
23
|
+
- [Eager Loading](#eager-loading)
|
23
24
|
- [Events](#events)
|
24
25
|
- [Installation](#installation)
|
25
26
|
- [Manual Installation](#manual-installation)
|
26
27
|
- [Authentication](#authentication)
|
28
|
+
- [Testing](#testing)
|
27
29
|
- [Gotchas](#gotchas)
|
28
30
|
- [Contributing](#contributing)
|
29
31
|
- [License](#license)
|
@@ -122,6 +124,22 @@ Collection rendering is also possible:
|
|
122
124
|
<% end %>
|
123
125
|
```
|
124
126
|
|
127
|
+
#### Specifying Controller to Render
|
128
|
+
|
129
|
+
You can also pass in the controller that will be used to render the partial.
|
130
|
+
|
131
|
+
```erb
|
132
|
+
<%= futurize partial: "items/card", collection: @cards, controller: MyController, extends: :div do %>
|
133
|
+
<div class="spinner"></div>
|
134
|
+
<% end %>
|
135
|
+
```
|
136
|
+
|
137
|
+
By default (i.e. not passing in a value), futurize will use `ApplicationController`, but you may override by setting the Futurism default controller in an initializer, for example `config/initializers/futurism.rb`.
|
138
|
+
|
139
|
+
```ruby
|
140
|
+
Futurism.default_controller = MyController
|
141
|
+
```
|
142
|
+
|
125
143
|
### HTML Options
|
126
144
|
|
127
145
|
You can pass a hash of attribute/value pairs which will be mixed into the HTML markup for the placeholder element. This is important for layouts that require elements to have dimensionality. For example, many scripts calculate size based on element height and width. This option ensures that your elements have integrity, even if they are gone before you see them.
|
@@ -140,6 +158,19 @@ This will output the following:
|
|
140
158
|
</tr>
|
141
159
|
```
|
142
160
|
|
161
|
+
### Eager Loading
|
162
|
+
It may sound surprising to support eager loading in a lazy loading library :joy:, but there's a quite simple use case:
|
163
|
+
|
164
|
+
Suppose you have some hidden interactive portion of your page, like a tab or dropdown. You don't want its content to block the initial page load, but once that is done, you occasionally don't want to wait for the element to become visible and trigger the `IntersectionObserver`, you want to lazy load its contents right after it's added to the DOM.
|
165
|
+
|
166
|
+
Futurism makes that dead simple:
|
167
|
+
|
168
|
+
```erb
|
169
|
+
<%= futurize 'some_tab', eager: true, extends: :tr do %>
|
170
|
+
<div class="placeholder"</td>
|
171
|
+
<% end %>
|
172
|
+
```
|
173
|
+
|
143
174
|
## Events
|
144
175
|
|
145
176
|
Once your futurize element has been rendered, the `futurize:appeared` custom event will be called.
|
@@ -199,6 +230,15 @@ end
|
|
199
230
|
|
200
231
|
The [Stimulus Reflex Docs](https://docs.stimulusreflex.com/authentication) have an excellent section about all sorts of authentication.
|
201
232
|
|
233
|
+
## Testing
|
234
|
+
In Rails system tests there is a chance that flaky errors will occur due to Capybara not waiting for the placeholder elements to be replaced. To overcome this, add the flag
|
235
|
+
|
236
|
+
```ruby
|
237
|
+
Futurism.skip_in_test = true
|
238
|
+
```
|
239
|
+
|
240
|
+
to an initializer, for example `config/initializers/futurism.rb`.
|
241
|
+
|
202
242
|
## Gotchas
|
203
243
|
|
204
244
|
### ActiveStorage URLs aren't correct in development
|
@@ -217,6 +257,39 @@ to your environments.
|
|
217
257
|
|
218
258
|
## Contributing
|
219
259
|
|
260
|
+
### Get local environment setup
|
261
|
+
|
262
|
+
Below are a set of instructions that may help you get a local development environment working
|
263
|
+
|
264
|
+
```shell
|
265
|
+
# Get the gem/npm package source locally
|
266
|
+
git clone futurism
|
267
|
+
cd futurism/javascript
|
268
|
+
yarn install # install all of the npm package's dependencies
|
269
|
+
yarn link # set the local machine's futurism npm package's lookup to this local path
|
270
|
+
|
271
|
+
# Setup a sample project, use the information below directly or use your own project
|
272
|
+
git clone https://github.com/leastbad/stimulus_reflex_harness.git
|
273
|
+
cd stimulus_reflex_harness
|
274
|
+
git checkout futurism
|
275
|
+
# Edit Gemfile to point point to local gem (e.g. `gem "futurism", path: "../futurism"`)
|
276
|
+
# yarn link @minthesize/futurism
|
277
|
+
|
278
|
+
|
279
|
+
# Do your work, Submit PR, Profit!
|
280
|
+
|
281
|
+
|
282
|
+
# To stop using your local version of futurism
|
283
|
+
# change your Gemfile back to the published (e.g. `gem "futurism"`)
|
284
|
+
cd path/to/futurism/javascript
|
285
|
+
# Stop using the local npm package
|
286
|
+
yarn unlink
|
287
|
+
|
288
|
+
# Instruct your project to reinstall the published version of the npm package
|
289
|
+
cd path/to/project
|
290
|
+
yarn install --force
|
291
|
+
```
|
292
|
+
|
220
293
|
## License
|
221
294
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
222
295
|
|
@@ -243,6 +316,8 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|
243
316
|
<td align="center"><a href="https://marcoroth.dev"><img src="https://avatars2.githubusercontent.com/u/6411752?v=4" width="100px;" alt=""/><br /><sub><b>Marco Roth</b></sub></a><br /><a href="https://github.com/julianrubisch/futurism/commits?author=marcoroth" title="Code">💻</a></td>
|
244
317
|
<td align="center"><a href="https://viedit.com"><img src="https://avatars1.githubusercontent.com/u/49990587?v=4" width="100px;" alt=""/><br /><sub><b>Viedit com</b></sub></a><br /><a href="https://github.com/julianrubisch/futurism/commits?author=vieditcom" title="Documentation">📖</a></td>
|
245
318
|
<td align="center"><a href="http://scottbarrow.ca"><img src="https://avatars2.githubusercontent.com/u/5571736?v=4" width="100px;" alt=""/><br /><sub><b>Scott Barrow</b></sub></a><br /><a href="https://github.com/julianrubisch/futurism/commits?author=scottbarrow" title="Code">💻</a></td>
|
319
|
+
<td align="center"><a href="http://domchristie.co.uk"><img src="https://avatars0.githubusercontent.com/u/111734?v=4" width="100px;" alt=""/><br /><sub><b>Dom Christie</b></sub></a><br /><a href="https://github.com/julianrubisch/futurism/pulls?q=is%3Apr+reviewed-by%3Adomchristie" title="Reviewed Pull Requests">👀</a></td>
|
320
|
+
<td align="center"><a href="http://www.rickychilcott.com"><img src="https://avatars1.githubusercontent.com/u/445759?v=4" width="100px;" alt=""/><br /><sub><b>Ricky Chilcott</b></sub></a><br /><a href="https://github.com/julianrubisch/futurism/pulls?q=is%3Apr+reviewed-by%3Arickychilcott" title="Reviewed Pull Requests">👀</a></td>
|
246
321
|
</tr>
|
247
322
|
</table>
|
248
323
|
|
data/lib/futurism.rb
CHANGED
@@ -2,6 +2,9 @@ require "rails"
|
|
2
2
|
require "action_cable"
|
3
3
|
require "cable_ready"
|
4
4
|
require "futurism/engine"
|
5
|
+
require "futurism/message_verifier"
|
6
|
+
require "futurism/resolver/controller"
|
7
|
+
require "futurism/resolver/controller/renderer"
|
5
8
|
require "futurism/channel"
|
6
9
|
require "futurism/helpers"
|
7
10
|
|
@@ -10,6 +13,8 @@ module Futurism
|
|
10
13
|
|
11
14
|
autoload :Helpers, "futurism/helpers"
|
12
15
|
|
16
|
+
mattr_accessor :skip_in_test, :default_controller
|
17
|
+
|
13
18
|
ActiveSupport.on_load(:action_view) {
|
14
19
|
include Futurism::Helpers
|
15
20
|
}
|
data/lib/futurism.rb~
CHANGED
@@ -1,5 +1,16 @@
|
|
1
|
+
require "rails"
|
2
|
+
require "action_cable"
|
3
|
+
require "cable_ready"
|
1
4
|
require "futurism/engine"
|
5
|
+
require "futurism/channel"
|
6
|
+
require "futurism/helpers"
|
2
7
|
|
3
8
|
module Futurism
|
4
|
-
|
9
|
+
extend ActiveSupport::Autoload
|
10
|
+
|
11
|
+
autoload :Helpers, "futurism/helpers"
|
12
|
+
|
13
|
+
ActiveSupport.on_load(:action_view) {
|
14
|
+
include Futurism::Helpers
|
15
|
+
}
|
5
16
|
end
|
data/lib/futurism/channel.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module Futurism
|
2
2
|
class Channel < ActionCable::Channel::Base
|
3
3
|
include CableReady::Broadcaster
|
4
|
+
include Futurism::MessageVerifier
|
4
5
|
|
5
6
|
def stream_name
|
6
7
|
ids = connection.identifiers.map { |identifier| send(identifier).try(:id) || send(identifier) }
|
@@ -15,17 +16,24 @@ module Futurism
|
|
15
16
|
end
|
16
17
|
|
17
18
|
def receive(data)
|
18
|
-
resources = data.fetch_values("signed_params", "sgids") { |
|
19
|
+
resources = data.fetch_values("signed_params", "sgids", "signed_controllers", "urls") { |_key| Array.new(data["signed_params"].length, nil) }.transpose
|
19
20
|
|
20
|
-
|
21
|
-
ApplicationController.renderer.instance_variable_set(:@env, new_env)
|
22
|
-
|
23
|
-
resources.each do |signed_params, sgid|
|
21
|
+
resources.each do |signed_params, sgid, signed_controller, url|
|
24
22
|
selector = "[data-signed-params='#{signed_params}']"
|
25
23
|
selector << "[data-sgid='#{sgid}']" if sgid.present?
|
24
|
+
|
25
|
+
controller = Resolver::Controller.from(signed_string: signed_controller)
|
26
|
+
renderer = Resolver::Controller::Renderer.for(controller: controller,
|
27
|
+
connection: connection,
|
28
|
+
url: url,
|
29
|
+
params: @params)
|
30
|
+
|
31
|
+
resource = lookup_resource(signed_params: signed_params, sgid: sgid)
|
32
|
+
html = renderer.render(resource)
|
33
|
+
|
26
34
|
cable_ready[stream_name].outer_html(
|
27
35
|
selector: selector,
|
28
|
-
html:
|
36
|
+
html: html
|
29
37
|
)
|
30
38
|
end
|
31
39
|
|
@@ -34,12 +42,10 @@ module Futurism
|
|
34
42
|
|
35
43
|
private
|
36
44
|
|
37
|
-
def
|
45
|
+
def lookup_resource(signed_params:, sgid:)
|
38
46
|
return GlobalID::Locator.locate_signed(sgid) if sgid.present?
|
39
47
|
|
40
|
-
|
41
|
-
.application
|
42
|
-
.message_verifier("futurism")
|
48
|
+
message_verifier
|
43
49
|
.verify(signed_params)
|
44
50
|
.deep_transform_values { |value| value.is_a?(String) && value.start_with?("gid://") ? GlobalID::Locator.locate(value) : value }
|
45
51
|
end
|
data/lib/futurism/channel.rb~
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module Futurism
|
2
2
|
class Channel < ActionCable::Channel::Base
|
3
3
|
include CableReady::Broadcaster
|
4
|
+
include Futurism::MessageVerifier
|
4
5
|
|
5
6
|
def stream_name
|
6
7
|
ids = connection.identifiers.map { |identifier| send(identifier).try(:id) || send(identifier) }
|
@@ -15,17 +16,24 @@ module Futurism
|
|
15
16
|
end
|
16
17
|
|
17
18
|
def receive(data)
|
18
|
-
resources = data.fetch_values("signed_params", "sgids") { |
|
19
|
+
resources = data.fetch_values("signed_params", "sgids", "signed_controllers", "urls") { |_key| Array.new(data["signed_params"].length, nil) }.transpose
|
19
20
|
|
20
|
-
|
21
|
-
ApplicationController.renderer.instance_variable_set(:@env, new_env)
|
22
|
-
|
23
|
-
resources.each do |signed_params, sgid|
|
21
|
+
resources.each do |signed_params, sgid, signed_controller, url|
|
24
22
|
selector = "[data-signed-params='#{signed_params}']"
|
25
23
|
selector << "[data-sgid='#{sgid}']" if sgid.present?
|
24
|
+
|
25
|
+
controller = Resolver::Controller.from(signed_string: signed_controller)
|
26
|
+
renderer = Resolver::Controller::Renderer.for(controller: controller,
|
27
|
+
connection: connection,
|
28
|
+
url: url,
|
29
|
+
params: @params)
|
30
|
+
|
31
|
+
resource = lookup_resource(signed_params: signed_params, sgid: sgid)
|
32
|
+
html = renderer.render(resource)
|
33
|
+
|
26
34
|
cable_ready[stream_name].outer_html(
|
27
35
|
selector: selector,
|
28
|
-
html:
|
36
|
+
html: html
|
29
37
|
)
|
30
38
|
end
|
31
39
|
|
@@ -34,14 +42,12 @@ module Futurism
|
|
34
42
|
|
35
43
|
private
|
36
44
|
|
37
|
-
def
|
45
|
+
def lookup_resource(signed_params:, sgid:)
|
38
46
|
return GlobalID::Locator.locate_signed(sgid) if sgid.present?
|
39
47
|
|
40
|
-
|
41
|
-
.application
|
42
|
-
.message_verifier("futurism")
|
48
|
+
message_verifier
|
43
49
|
.verify(signed_params)
|
44
|
-
.deep_transform_values { |value| value.start_with?("gid://") ? GlobalID::Locator.locate(value) : value }
|
50
|
+
.deep_transform_values { |value| value.is_a?(String) && value.start_with?("gid://") ? GlobalID::Locator.locate(value) : value }
|
45
51
|
end
|
46
52
|
end
|
47
53
|
end
|
data/lib/futurism/helpers.rb
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
module Futurism
|
2
2
|
module Helpers
|
3
3
|
def futurize(records_or_string = nil, extends:, **options, &block)
|
4
|
+
if Rails.env.test? && Futurism.skip_in_test
|
5
|
+
if records_or_string.nil?
|
6
|
+
return render(**options)
|
7
|
+
else
|
8
|
+
return render(records_or_string, **options)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
4
12
|
placeholder = capture(&block)
|
5
13
|
|
6
14
|
if records_or_string.is_a?(ActiveRecord::Base) || records_or_string.is_a?(ActiveRecord::Relation)
|
@@ -35,12 +43,15 @@ module Futurism
|
|
35
43
|
# wraps functionality for rendering a futurism element
|
36
44
|
class Element
|
37
45
|
include ActionView::Helpers
|
46
|
+
include Futurism::MessageVerifier
|
38
47
|
|
39
|
-
attr_reader :extends, :placeholder, :html_options, :data_attributes, :model, :options
|
48
|
+
attr_reader :extends, :placeholder, :html_options, :data_attributes, :model, :options, :eager, :controller
|
40
49
|
|
41
50
|
def initialize(extends:, placeholder:, options:)
|
42
51
|
@extends = extends
|
43
52
|
@placeholder = placeholder
|
53
|
+
@eager = options.delete(:eager)
|
54
|
+
@controller = options.delete(:controller)
|
44
55
|
@html_options = options.delete(:html_options) || {}
|
45
56
|
@data_attributes = html_options.fetch(:data, {}).except(:sgid, :signed_params)
|
46
57
|
@model = options.delete(:model)
|
@@ -50,7 +61,9 @@ module Futurism
|
|
50
61
|
def dataset
|
51
62
|
data_attributes.merge({
|
52
63
|
signed_params: signed_params,
|
53
|
-
sgid: model && model.to_sgid.to_s
|
64
|
+
sgid: model && model.to_sgid.to_s,
|
65
|
+
eager: eager.presence,
|
66
|
+
signed_controller: signed_controller
|
54
67
|
})
|
55
68
|
end
|
56
69
|
|
@@ -69,14 +82,20 @@ module Futurism
|
|
69
82
|
require_relative "shims/deep_transform_values" unless options.respond_to? :deep_transform_values
|
70
83
|
|
71
84
|
options.deep_transform_values do |value|
|
72
|
-
value.is_a?(ActiveRecord::Base) ? value.to_global_id.to_s : value
|
85
|
+
value.is_a?(ActiveRecord::Base) && !value.new_record? ? value.to_global_id.to_s : value
|
73
86
|
end
|
74
87
|
end
|
75
88
|
|
76
89
|
private
|
77
90
|
|
78
91
|
def signed_params
|
79
|
-
|
92
|
+
message_verifier.generate(transformed_options)
|
93
|
+
end
|
94
|
+
|
95
|
+
def signed_controller
|
96
|
+
return unless controller.present?
|
97
|
+
|
98
|
+
message_verifier.generate(controller.to_s)
|
80
99
|
end
|
81
100
|
end
|
82
101
|
end
|
data/lib/futurism/helpers.rb~
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
module Futurism
|
2
2
|
module Helpers
|
3
3
|
def futurize(records_or_string = nil, extends:, **options, &block)
|
4
|
+
if Rails.env.test? && Futurism.skip_in_test
|
5
|
+
if records_or_string.nil?
|
6
|
+
return render(**options)
|
7
|
+
else
|
8
|
+
return render(records_or_string, **options)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
4
12
|
placeholder = capture(&block)
|
5
13
|
|
6
14
|
if records_or_string.is_a?(ActiveRecord::Base) || records_or_string.is_a?(ActiveRecord::Relation)
|
@@ -35,12 +43,15 @@ module Futurism
|
|
35
43
|
# wraps functionality for rendering a futurism element
|
36
44
|
class Element
|
37
45
|
include ActionView::Helpers
|
46
|
+
include Futurism::MessageVerifier
|
38
47
|
|
39
|
-
attr_reader :extends, :placeholder, :html_options, :data_attributes, :model, :options
|
48
|
+
attr_reader :extends, :placeholder, :html_options, :data_attributes, :model, :options, :eager, :controller
|
40
49
|
|
41
50
|
def initialize(extends:, placeholder:, options:)
|
42
51
|
@extends = extends
|
43
52
|
@placeholder = placeholder
|
53
|
+
@eager = options.delete(:eager)
|
54
|
+
@controller = options.delete(:controller)
|
44
55
|
@html_options = options.delete(:html_options) || {}
|
45
56
|
@data_attributes = html_options.fetch(:data, {}).except(:sgid, :signed_params)
|
46
57
|
@model = options.delete(:model)
|
@@ -50,7 +61,9 @@ module Futurism
|
|
50
61
|
def dataset
|
51
62
|
data_attributes.merge({
|
52
63
|
signed_params: signed_params,
|
53
|
-
sgid: model && model.to_sgid.to_s
|
64
|
+
sgid: model && model.to_sgid.to_s,
|
65
|
+
eager: eager.presence,
|
66
|
+
signed_controller: signed_controller
|
54
67
|
})
|
55
68
|
end
|
56
69
|
|
@@ -69,14 +82,20 @@ module Futurism
|
|
69
82
|
require_relative "shims/deep_transform_values" unless options.respond_to? :deep_transform_values
|
70
83
|
|
71
84
|
options.deep_transform_values do |value|
|
72
|
-
value.is_a?(ActiveRecord::Base) ? value.to_global_id.to_s : value
|
85
|
+
value.is_a?(ActiveRecord::Base) && !value.new_record? ? value.to_global_id.to_s : value
|
73
86
|
end
|
74
87
|
end
|
75
88
|
|
76
89
|
private
|
77
90
|
|
78
91
|
def signed_params
|
79
|
-
|
92
|
+
message_verifier.generate(transformed_options)
|
93
|
+
end
|
94
|
+
|
95
|
+
def signed_controller
|
96
|
+
return unless controller.present?
|
97
|
+
|
98
|
+
message_verifier.generate(controller.to_s)
|
80
99
|
end
|
81
100
|
end
|
82
101
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Futurism
|
2
|
+
module MessageVerifier
|
3
|
+
def self.message_verifier
|
4
|
+
@message_verifier ||= Rails.application.message_verifier("futurism")
|
5
|
+
end
|
6
|
+
|
7
|
+
def message_verifier
|
8
|
+
@message_verifier ||= Rails.application.message_verifier("futurism")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Futurism
|
2
|
+
module Resolver
|
3
|
+
class Controller
|
4
|
+
def self.from(signed_string:)
|
5
|
+
if signed_string.present?
|
6
|
+
Futurism::MessageVerifier
|
7
|
+
.message_verifier
|
8
|
+
.verify(signed_string)
|
9
|
+
.to_s
|
10
|
+
.safe_constantize
|
11
|
+
else
|
12
|
+
default_controller
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.default_controller
|
17
|
+
Futurism.default_controller || ::ApplicationController
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Futurism
|
2
|
+
module Resolver
|
3
|
+
class Controller
|
4
|
+
class Renderer
|
5
|
+
def self.for(controller:, connection:, url:, params:)
|
6
|
+
new(controller: controller, connection: connection, url: url, params: params).renderer
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(controller:, connection:, url:, params:)
|
10
|
+
@controller = controller
|
11
|
+
@connection = connection
|
12
|
+
@url = url || ""
|
13
|
+
@params = params || {}
|
14
|
+
|
15
|
+
setup_env!
|
16
|
+
end
|
17
|
+
|
18
|
+
def renderer
|
19
|
+
@renderer ||= controller.renderer
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
attr_reader :controller, :connection, :url, :params
|
25
|
+
attr_writer :renderer
|
26
|
+
|
27
|
+
def setup_env!
|
28
|
+
if url.present?
|
29
|
+
uri = URI.parse(url)
|
30
|
+
path = ActionDispatch::Journey::Router::Utils.normalize_path(uri.path)
|
31
|
+
query_hash = Rack::Utils.parse_nested_query(uri.query)
|
32
|
+
|
33
|
+
path_params = Rails.application.routes.recognize_path(path)
|
34
|
+
|
35
|
+
self.renderer =
|
36
|
+
renderer.new(
|
37
|
+
"rack.request.query_hash" => query_hash,
|
38
|
+
"rack.request.query_string" => uri.query,
|
39
|
+
"ORIGINAL_SCRIPT_NAME" => "",
|
40
|
+
"ORIGINAL_FULLPATH" => path,
|
41
|
+
Rack::SCRIPT_NAME => "",
|
42
|
+
Rack::PATH_INFO => path,
|
43
|
+
Rack::REQUEST_PATH => path,
|
44
|
+
Rack::QUERY_STRING => uri.query,
|
45
|
+
ActionDispatch::Http::Parameters::PARAMETERS_KEY => params.symbolize_keys.merge(path_params).merge(query_hash)
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
# Copy connection env to renderer to fix some RACK related issues from gems like
|
50
|
+
# Warden or Devise
|
51
|
+
new_env = connection.env.merge(renderer.instance_variable_get(:@env))
|
52
|
+
renderer.instance_variable_set(:@env, new_env)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Futurism
|
2
|
+
module Resolver
|
3
|
+
class Controller
|
4
|
+
class Renderer
|
5
|
+
def self.for(controller:, connection:, url:, params:)
|
6
|
+
new(controller: controller, connection: connection, url: url, params: params).renderer
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(controller:, connection:, url:, params:)
|
10
|
+
@controller = controller
|
11
|
+
@connection = connection
|
12
|
+
@url = url || ""
|
13
|
+
@params = params || {}
|
14
|
+
|
15
|
+
setup_env!
|
16
|
+
end
|
17
|
+
|
18
|
+
def renderer
|
19
|
+
@renderer ||= controller.renderer
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
attr_reader :controller, :connection, :url, :params
|
25
|
+
attr_writer :renderer
|
26
|
+
|
27
|
+
def setup_env!
|
28
|
+
if url.present?
|
29
|
+
uri = URI.parse(url)
|
30
|
+
path = ActionDispatch::Journey::Router::Utils.normalize_path(uri.path)
|
31
|
+
query_hash = Rack::Utils.parse_nested_query(uri.query)
|
32
|
+
|
33
|
+
path_params = Rails.application.routes.recognize_path(path)
|
34
|
+
|
35
|
+
self.renderer =
|
36
|
+
renderer.new(
|
37
|
+
"rack.request.query_hash" => query_hash,
|
38
|
+
"rack.request.query_string" => uri.query,
|
39
|
+
"ORIGINAL_SCRIPT_NAME" => "",
|
40
|
+
"ORIGINAL_FULLPATH" => path,
|
41
|
+
Rack::SCRIPT_NAME => "",
|
42
|
+
Rack::PATH_INFO => path,
|
43
|
+
Rack::REQUEST_PATH => path,
|
44
|
+
Rack::QUERY_STRING => uri.query,
|
45
|
+
ActionDispatch::Http::Parameters::PARAMETERS_KEY => path_params.reverse_merge(path_params)
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
# Copy connection env to renderer to fix some RACK related issues from gems like
|
50
|
+
# Warden or Devise
|
51
|
+
new_env = connection.env.merge(renderer.instance_variable_get(:@env))
|
52
|
+
renderer.instance_variable_set(:@env, new_env)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/lib/futurism/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: futurism
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Julian Rubisch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: appraisal
|
@@ -108,20 +108,6 @@ dependencies:
|
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: spy
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - ">="
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '0'
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - ">="
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: '0'
|
125
111
|
- !ruby/object:Gem::Dependency
|
126
112
|
name: rack
|
127
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -175,7 +161,6 @@ files:
|
|
175
161
|
- MIT-LICENSE
|
176
162
|
- README.md
|
177
163
|
- Rakefile
|
178
|
-
- app/assets/config/futurism_manifest.js
|
179
164
|
- config/routes.rb
|
180
165
|
- lib/futurism.rb
|
181
166
|
- lib/futurism.rb~
|
@@ -184,6 +169,10 @@ files:
|
|
184
169
|
- lib/futurism/engine.rb
|
185
170
|
- lib/futurism/helpers.rb
|
186
171
|
- lib/futurism/helpers.rb~
|
172
|
+
- lib/futurism/message_verifier.rb
|
173
|
+
- lib/futurism/resolver/controller.rb
|
174
|
+
- lib/futurism/resolver/controller/renderer.rb
|
175
|
+
- lib/futurism/resolver/controller/renderer.rb~
|
187
176
|
- lib/futurism/shims/deep_transform_values.rb
|
188
177
|
- lib/futurism/version.rb
|
189
178
|
- lib/tasks/futurism_tasks.rake
|
File without changes
|