futurism 1.2.0.pre8 → 1.2.0.pre11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Appraisals +24 -0
- data/Appraisals~ +24 -0
- data/CHANGELOG.md +370 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +215 -0
- data/Gemfile~ +17 -0
- data/README.md +44 -9
- data/README.md~ +405 -0
- data/app/assets/javascripts/futurism.js +191 -0
- data/app/assets/javascripts/futurism.min.js +2 -0
- data/app/assets/javascripts/futurism.min.js.map +1 -0
- data/app/assets/javascripts/futurism.umd.js +188 -0
- data/app/assets/javascripts/futurism.umd.min.js +2 -0
- data/app/assets/javascripts/futurism.umd.min.js.map +1 -0
- data/{lib → app/channels}/futurism/channel.rb +1 -1
- data/bin/rails +25 -0
- data/bin/standardize +5 -0
- data/bin/test +5 -0
- data/futurism.gemspec +38 -0
- data/futurism.gemspec~ +30 -0
- data/lib/futurism/configuration.rb +21 -0
- data/lib/futurism/engine.rb +19 -0
- data/lib/futurism/helpers.rb +2 -2
- data/lib/futurism/importmap.rb +2 -0
- data/lib/futurism/version.rb +1 -1
- data/lib/futurism.rb +2 -1
- data/package.json +47 -0
- data/package.json~ +51 -0
- data/rollup.config.js +77 -0
- data/rollup.config.js~ +73 -0
- data/test/cable/channel_test.rb +319 -0
- data/test/dummy/app/channels/application_cable/channel.rb +4 -0
- data/test/dummy/app/channels/application_cable/connection.rb +4 -0
- data/test/dummy/app/controllers/application_controller.rb +2 -0
- data/test/dummy/app/controllers/home_controller.rb +6 -0
- data/test/dummy/app/controllers/posts_controller.rb +59 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/helpers/posts_helper.rb +2 -0
- data/test/dummy/app/jobs/application_job.rb +7 -0
- data/test/dummy/app/models/action_item.rb +2 -0
- data/test/dummy/app/models/application_record.rb +3 -0
- data/test/dummy/app/models/post.rb +2 -0
- data/test/dummy/config/application.rb +29 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +40 -0
- data/test/dummy/config/environments/production.rb +94 -0
- data/test/dummy/config/environments/test.rb +39 -0
- data/test/dummy/config/initializers/application_controller_renderer.rb +8 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/content_security_policy.rb +28 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +9 -0
- data/test/dummy/config/puma.rb +38 -0
- data/test/dummy/config/routes.rb +12 -0
- data/test/dummy/config/spring.rb +6 -0
- data/test/dummy/db/migrate/20200711122838_create_posts.rb +9 -0
- data/test/dummy/db/migrate/2021042923813_create_action_items.rb +9 -0
- data/test/dummy/db/schema.rb +27 -0
- data/test/futurism_test.rb +28 -0
- data/test/helper/helper_test.rb +206 -0
- data/test/integration/navigation_test.rb +7 -0
- data/test/resolver/controller/renderer_test.rb +120 -0
- data/test/resolver/controller_test.rb +26 -0
- data/test/test_helper.rb +14 -0
- data/yarn.lock +3263 -0
- metadata +122 -18
- data/config/routes.rb +0 -2
- data/lib/futurism/channel.rb~ +0 -31
- data/lib/futurism/helpers.rb~ +0 -112
- data/lib/futurism/options_transformer.rb~ +0 -0
- data/lib/futurism/resolver/controller/renderer.rb~ +0 -76
- data/lib/futurism/resolver/controller.rb~ +0 -17
- data/lib/futurism/resolver/resources.rb~ +0 -101
- data/lib/futurism/version.rb~ +0 -3
- data/lib/futurism.rb~ +0 -30
- data/lib/tasks/futurism_tasks.rake +0 -39
- data/lib/tasks/futurism_tasks.rake~ +0 -39
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: futurism
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.0.
|
4
|
+
version: 1.2.0.pre11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Julian Rubisch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: appraisal
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -128,14 +142,14 @@ dependencies:
|
|
128
142
|
requirements:
|
129
143
|
- - '='
|
130
144
|
- !ruby/object:Gem::Version
|
131
|
-
version: 5.0.0.
|
145
|
+
version: 5.0.0.pre9
|
132
146
|
type: :runtime
|
133
147
|
prerelease: false
|
134
148
|
version_requirements: !ruby/object:Gem::Requirement
|
135
149
|
requirements:
|
136
150
|
- - '='
|
137
151
|
- !ruby/object:Gem::Version
|
138
|
-
version: 5.0.0.
|
152
|
+
version: 5.0.0.pre9
|
139
153
|
description: Uses custom html elements with attached IntersectionObserver to automatically
|
140
154
|
lazy load partials via websockets
|
141
155
|
email:
|
@@ -144,31 +158,83 @@ executables: []
|
|
144
158
|
extensions: []
|
145
159
|
extra_rdoc_files: []
|
146
160
|
files:
|
161
|
+
- Appraisals
|
162
|
+
- Appraisals~
|
163
|
+
- CHANGELOG.md
|
164
|
+
- Gemfile
|
165
|
+
- Gemfile.lock
|
166
|
+
- Gemfile~
|
147
167
|
- MIT-LICENSE
|
148
168
|
- README.md
|
169
|
+
- README.md~
|
149
170
|
- Rakefile
|
150
|
-
-
|
171
|
+
- app/assets/javascripts/futurism.js
|
172
|
+
- app/assets/javascripts/futurism.min.js
|
173
|
+
- app/assets/javascripts/futurism.min.js.map
|
174
|
+
- app/assets/javascripts/futurism.umd.js
|
175
|
+
- app/assets/javascripts/futurism.umd.min.js
|
176
|
+
- app/assets/javascripts/futurism.umd.min.js.map
|
177
|
+
- app/channels/futurism/channel.rb
|
178
|
+
- bin/rails
|
179
|
+
- bin/standardize
|
180
|
+
- bin/test
|
181
|
+
- futurism.gemspec
|
182
|
+
- futurism.gemspec~
|
151
183
|
- lib/futurism.rb
|
152
|
-
- lib/futurism.rb
|
153
|
-
- lib/futurism/channel.rb
|
154
|
-
- lib/futurism/channel.rb~
|
184
|
+
- lib/futurism/configuration.rb
|
155
185
|
- lib/futurism/engine.rb
|
156
186
|
- lib/futurism/helpers.rb
|
157
|
-
- lib/futurism/
|
187
|
+
- lib/futurism/importmap.rb
|
158
188
|
- lib/futurism/message_verifier.rb
|
159
189
|
- lib/futurism/options_transformer.rb
|
160
|
-
- lib/futurism/options_transformer.rb~
|
161
190
|
- lib/futurism/resolver/controller.rb
|
162
|
-
- lib/futurism/resolver/controller.rb~
|
163
191
|
- lib/futurism/resolver/controller/renderer.rb
|
164
|
-
- lib/futurism/resolver/controller/renderer.rb~
|
165
192
|
- lib/futurism/resolver/resources.rb
|
166
|
-
- lib/futurism/resolver/resources.rb~
|
167
193
|
- lib/futurism/shims/deep_transform_values.rb
|
168
194
|
- lib/futurism/version.rb
|
169
|
-
-
|
170
|
-
-
|
171
|
-
-
|
195
|
+
- package.json
|
196
|
+
- package.json~
|
197
|
+
- rollup.config.js
|
198
|
+
- rollup.config.js~
|
199
|
+
- test/cable/channel_test.rb
|
200
|
+
- test/dummy/app/channels/application_cable/channel.rb
|
201
|
+
- test/dummy/app/channels/application_cable/connection.rb
|
202
|
+
- test/dummy/app/controllers/application_controller.rb
|
203
|
+
- test/dummy/app/controllers/home_controller.rb
|
204
|
+
- test/dummy/app/controllers/posts_controller.rb
|
205
|
+
- test/dummy/app/helpers/application_helper.rb
|
206
|
+
- test/dummy/app/helpers/posts_helper.rb
|
207
|
+
- test/dummy/app/jobs/application_job.rb
|
208
|
+
- test/dummy/app/models/action_item.rb
|
209
|
+
- test/dummy/app/models/application_record.rb
|
210
|
+
- test/dummy/app/models/post.rb
|
211
|
+
- test/dummy/config/application.rb
|
212
|
+
- test/dummy/config/boot.rb
|
213
|
+
- test/dummy/config/environment.rb
|
214
|
+
- test/dummy/config/environments/development.rb
|
215
|
+
- test/dummy/config/environments/production.rb
|
216
|
+
- test/dummy/config/environments/test.rb
|
217
|
+
- test/dummy/config/initializers/application_controller_renderer.rb
|
218
|
+
- test/dummy/config/initializers/backtrace_silencers.rb
|
219
|
+
- test/dummy/config/initializers/content_security_policy.rb
|
220
|
+
- test/dummy/config/initializers/cookies_serializer.rb
|
221
|
+
- test/dummy/config/initializers/filter_parameter_logging.rb
|
222
|
+
- test/dummy/config/initializers/inflections.rb
|
223
|
+
- test/dummy/config/initializers/mime_types.rb
|
224
|
+
- test/dummy/config/initializers/wrap_parameters.rb
|
225
|
+
- test/dummy/config/puma.rb
|
226
|
+
- test/dummy/config/routes.rb
|
227
|
+
- test/dummy/config/spring.rb
|
228
|
+
- test/dummy/db/migrate/20200711122838_create_posts.rb
|
229
|
+
- test/dummy/db/migrate/2021042923813_create_action_items.rb
|
230
|
+
- test/dummy/db/schema.rb
|
231
|
+
- test/futurism_test.rb
|
232
|
+
- test/helper/helper_test.rb
|
233
|
+
- test/integration/navigation_test.rb
|
234
|
+
- test/resolver/controller/renderer_test.rb
|
235
|
+
- test/resolver/controller_test.rb
|
236
|
+
- test/test_helper.rb
|
237
|
+
- yarn.lock
|
172
238
|
homepage: https://github.com/stimulusreflex/futurism
|
173
239
|
licenses:
|
174
240
|
- MIT
|
@@ -188,8 +254,46 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
188
254
|
- !ruby/object:Gem::Version
|
189
255
|
version: 1.3.1
|
190
256
|
requirements: []
|
191
|
-
rubygems_version: 3.
|
257
|
+
rubygems_version: 3.2.32
|
192
258
|
signing_key:
|
193
259
|
specification_version: 4
|
194
260
|
summary: Lazy-load Rails partials via CableReady
|
195
|
-
test_files:
|
261
|
+
test_files:
|
262
|
+
- test/cable/channel_test.rb
|
263
|
+
- test/dummy/app/channels/application_cable/channel.rb
|
264
|
+
- test/dummy/app/channels/application_cable/connection.rb
|
265
|
+
- test/dummy/app/controllers/application_controller.rb
|
266
|
+
- test/dummy/app/controllers/home_controller.rb
|
267
|
+
- test/dummy/app/controllers/posts_controller.rb
|
268
|
+
- test/dummy/app/helpers/application_helper.rb
|
269
|
+
- test/dummy/app/helpers/posts_helper.rb
|
270
|
+
- test/dummy/app/jobs/application_job.rb
|
271
|
+
- test/dummy/app/models/action_item.rb
|
272
|
+
- test/dummy/app/models/application_record.rb
|
273
|
+
- test/dummy/app/models/post.rb
|
274
|
+
- test/dummy/config/application.rb
|
275
|
+
- test/dummy/config/boot.rb
|
276
|
+
- test/dummy/config/environment.rb
|
277
|
+
- test/dummy/config/environments/development.rb
|
278
|
+
- test/dummy/config/environments/production.rb
|
279
|
+
- test/dummy/config/environments/test.rb
|
280
|
+
- test/dummy/config/initializers/application_controller_renderer.rb
|
281
|
+
- test/dummy/config/initializers/backtrace_silencers.rb
|
282
|
+
- test/dummy/config/initializers/content_security_policy.rb
|
283
|
+
- test/dummy/config/initializers/cookies_serializer.rb
|
284
|
+
- test/dummy/config/initializers/filter_parameter_logging.rb
|
285
|
+
- test/dummy/config/initializers/inflections.rb
|
286
|
+
- test/dummy/config/initializers/mime_types.rb
|
287
|
+
- test/dummy/config/initializers/wrap_parameters.rb
|
288
|
+
- test/dummy/config/puma.rb
|
289
|
+
- test/dummy/config/routes.rb
|
290
|
+
- test/dummy/config/spring.rb
|
291
|
+
- test/dummy/db/migrate/20200711122838_create_posts.rb
|
292
|
+
- test/dummy/db/migrate/2021042923813_create_action_items.rb
|
293
|
+
- test/dummy/db/schema.rb
|
294
|
+
- test/futurism_test.rb
|
295
|
+
- test/helper/helper_test.rb
|
296
|
+
- test/integration/navigation_test.rb
|
297
|
+
- test/resolver/controller/renderer_test.rb
|
298
|
+
- test/resolver/controller_test.rb
|
299
|
+
- test/test_helper.rb
|
data/config/routes.rb
DELETED
data/lib/futurism/channel.rb~
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
module Futurism
|
2
|
-
class Channel < ActionCable::Channel::Base
|
3
|
-
include CableReady::Broadcaster
|
4
|
-
|
5
|
-
def stream_name
|
6
|
-
ids = connection.identifiers.map { |identifier| send(identifier).try(:id) || send(identifier) }
|
7
|
-
[
|
8
|
-
params[:channel],
|
9
|
-
ids.select(&:present?).join(";")
|
10
|
-
].select(&:present?).join(":")
|
11
|
-
end
|
12
|
-
|
13
|
-
def subscribed
|
14
|
-
stream_from stream_name
|
15
|
-
end
|
16
|
-
|
17
|
-
def receive(data)
|
18
|
-
resources = data.fetch_values("signed_params", "sgids", "signed_controllers", "urls") { |_key| Array.new(data["signed_params"].length, nil) }.transpose
|
19
|
-
|
20
|
-
resolver = Resolver::Resources.new(resource_definitions: resources, connection: connection, params: @params)
|
21
|
-
resolver.resolve do |selector, html|
|
22
|
-
cable_ready[stream_name].outer_html(
|
23
|
-
selector: selector,
|
24
|
-
html: html
|
25
|
-
)
|
26
|
-
end
|
27
|
-
|
28
|
-
cable_ready.broadcast
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
data/lib/futurism/helpers.rb~
DELETED
@@ -1,112 +0,0 @@
|
|
1
|
-
module Futurism
|
2
|
-
module Helpers
|
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
|
-
|
12
|
-
options[:eager] = true unless block_given?
|
13
|
-
|
14
|
-
if records_or_string.is_a?(ActiveRecord::Base) || records_or_string.is_a?(ActiveRecord::Relation)
|
15
|
-
futurize_active_record(records_or_string, extends: extends, **options, &block)
|
16
|
-
elsif records_or_string.is_a?(String)
|
17
|
-
html_options = options.delete(:html_options)
|
18
|
-
futurize_with_options(extends: extends, partial: records_or_string, locals: options, html_options: html_options, &block)
|
19
|
-
else
|
20
|
-
futurize_with_options(extends: extends, **options, &block)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def futurize_with_options(extends:, **options, &block)
|
25
|
-
collection = options.delete(:collection)
|
26
|
-
if collection.nil?
|
27
|
-
placeholder = capture(&block) if block_given?
|
28
|
-
|
29
|
-
WrappingFuturismElement.new(extends: extends, placeholder: placeholder, options: options).render
|
30
|
-
else
|
31
|
-
collection_class_name = collection.try(:klass).try(:name) || collection.first.class.to_s
|
32
|
-
as = options.delete(:as) || collection_class_name.underscore
|
33
|
-
broadcast_each = options.delete(:broadcast_each) || false
|
34
|
-
|
35
|
-
collection.each_with_index.map { |record, index|
|
36
|
-
placeholder = capture(record, index, &block) if block_given?
|
37
|
-
|
38
|
-
WrappingFuturismElement.new(extends: extends, placeholder: placeholder, options: options.deep_merge(
|
39
|
-
broadcast_each: broadcast_each,
|
40
|
-
locals: {as.to_sym => record, "#{as}_counter".to_sym => index}
|
41
|
-
)).render
|
42
|
-
}.join.html_safe
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def futurize_active_record(records, extends:, **options, &block)
|
47
|
-
Array(records).map.with_index { |record, index|
|
48
|
-
placeholder = capture(record, index, &block) if block_given?
|
49
|
-
|
50
|
-
WrappingFuturismElement.new(extends: extends, options: options.merge(model: record), placeholder: placeholder).render
|
51
|
-
}.join.html_safe
|
52
|
-
end
|
53
|
-
|
54
|
-
# wraps functionality for rendering a futurism element
|
55
|
-
class WrappingFuturismElement
|
56
|
-
include ActionView::Helpers
|
57
|
-
include Futurism::MessageVerifier
|
58
|
-
include Futurism::OptionsTransformer
|
59
|
-
|
60
|
-
attr_reader :extends, :placeholder, :html_options, :data_attributes, :model, :options, :eager, :broadcast_each, :controller
|
61
|
-
|
62
|
-
def initialize(extends:, placeholder:, options:)
|
63
|
-
@extends = extends
|
64
|
-
@placeholder = placeholder
|
65
|
-
@eager = options.delete(:eager)
|
66
|
-
@broadcast_each = options.delete(:broadcast_each)
|
67
|
-
@controller = options.delete(:controller)
|
68
|
-
@html_options = options.delete(:html_options) || {}
|
69
|
-
@data_attributes = html_options.fetch(:data, {}).except(:sgid, :signed_params)
|
70
|
-
@model = options.delete(:model)
|
71
|
-
@options = data_attributes.any? ? options.merge(data: data_attributes) : options
|
72
|
-
end
|
73
|
-
|
74
|
-
def dataset
|
75
|
-
data_attributes.merge({
|
76
|
-
signed_params: signed_params,
|
77
|
-
sgid: model && model.to_sgid.to_s,
|
78
|
-
eager: eager.presence,
|
79
|
-
broadcast_each: broadcast_each.presence,
|
80
|
-
signed_controller: signed_controller
|
81
|
-
})
|
82
|
-
end
|
83
|
-
|
84
|
-
def render
|
85
|
-
case extends
|
86
|
-
when :li
|
87
|
-
content_tag :li, placeholder, html_options.deep_merge({data: dataset, is: "futurism-li"})
|
88
|
-
when :tr
|
89
|
-
content_tag :tr, placeholder, html_options.deep_merge({data: dataset, is: "futurism-table-row"})
|
90
|
-
else
|
91
|
-
content_tag :"futurism-element", placeholder, html_options.deep_merge({data: dataset})
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
def transformed_options
|
96
|
-
dump_options(options)
|
97
|
-
end
|
98
|
-
|
99
|
-
private
|
100
|
-
|
101
|
-
def signed_params
|
102
|
-
message_verifier.generate(transformed_options)
|
103
|
-
end
|
104
|
-
|
105
|
-
def signed_controller
|
106
|
-
return unless controller.present?
|
107
|
-
|
108
|
-
message_verifier.generate(controller.to_s)
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
File without changes
|
@@ -1,76 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Futurism
|
4
|
-
module Resolver
|
5
|
-
class Controller
|
6
|
-
class Renderer
|
7
|
-
HTTP_METHODS = [:get, :post, :put, :patch, :delete]
|
8
|
-
|
9
|
-
def self.for(controller:, connection:, url:, params:)
|
10
|
-
new(controller: controller, connection: connection, url: url, params: params).renderer
|
11
|
-
end
|
12
|
-
|
13
|
-
def initialize(controller:, connection:, url:, params:)
|
14
|
-
@controller = controller
|
15
|
-
@connection = connection
|
16
|
-
@url = url || ""
|
17
|
-
@params = params || {}
|
18
|
-
|
19
|
-
setup_env!
|
20
|
-
end
|
21
|
-
|
22
|
-
def renderer
|
23
|
-
@renderer ||= controller.renderer
|
24
|
-
end
|
25
|
-
|
26
|
-
private
|
27
|
-
|
28
|
-
attr_reader :controller, :connection, :url, :params
|
29
|
-
attr_writer :renderer
|
30
|
-
|
31
|
-
def setup_env!
|
32
|
-
if url.present?
|
33
|
-
uri = URI.parse(url)
|
34
|
-
path = ActionDispatch::Journey::Router::Utils.normalize_path(uri.path)
|
35
|
-
query_hash = Rack::Utils.parse_nested_query(uri.query)
|
36
|
-
|
37
|
-
path_params = recognize_url(url) # use full url to be more likely to match a url with subdomain constraints
|
38
|
-
|
39
|
-
self.renderer =
|
40
|
-
renderer.new(
|
41
|
-
"rack.request.query_hash" => query_hash,
|
42
|
-
"rack.request.query_string" => uri.query,
|
43
|
-
"ORIGINAL_SCRIPT_NAME" => "",
|
44
|
-
"ORIGINAL_FULLPATH" => path,
|
45
|
-
Rack::SCRIPT_NAME => "",
|
46
|
-
Rack::PATH_INFO => path,
|
47
|
-
Rack::REQUEST_PATH => path,
|
48
|
-
Rack::QUERY_STRING => uri.query,
|
49
|
-
ActionDispatch::Http::Parameters::PARAMETERS_KEY => params.symbolize_keys.merge(path_params).merge(query_hash)
|
50
|
-
)
|
51
|
-
end
|
52
|
-
|
53
|
-
# Copy connection env to renderer to fix some RACK related issues from gems like
|
54
|
-
# Warden or Devise
|
55
|
-
new_env = connection.env.merge(renderer.instance_variable_get(:@env))
|
56
|
-
renderer.instance_variable_set(:@env, new_env)
|
57
|
-
end
|
58
|
-
|
59
|
-
def recognize_url(url)
|
60
|
-
HTTP_METHODS.each do |http_method|
|
61
|
-
path = Rails.application.routes.recognize_path(url, method: http_method)
|
62
|
-
return path if path
|
63
|
-
rescue ActionController::RoutingError
|
64
|
-
# Route not matched, try next
|
65
|
-
end
|
66
|
-
|
67
|
-
warn "We were unable to find a matching rails route for '#{url}'. " \
|
68
|
-
"This may be because there are proc-based routing constraints for this particular url, or " \
|
69
|
-
"it truly is an unrecognizable url."
|
70
|
-
|
71
|
-
{}
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
@@ -1,17 +0,0 @@
|
|
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
|
-
Futurism.default_controller
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,101 +0,0 @@
|
|
1
|
-
module Futurism
|
2
|
-
module Resolver
|
3
|
-
class Resources
|
4
|
-
include Futurism::MessageVerifier
|
5
|
-
|
6
|
-
# resource definitions are an array of [signed_params, sgid, signed_controller, url, broadcast_each]
|
7
|
-
def initialize(resource_definitions:, connection:, params:)
|
8
|
-
@connection = connection
|
9
|
-
@params = params
|
10
|
-
@resources_with_sgids, @resources_without_sgids = resource_definitions
|
11
|
-
.partition { |signed_params, sgid, *| sgid.present? }
|
12
|
-
.map { |partition| partition.map { |definition| ResourceDefinition.new(definition) } }
|
13
|
-
end
|
14
|
-
|
15
|
-
def resolve
|
16
|
-
resolved_models.zip(@resources_with_sgids).each do |model, resource_definition|
|
17
|
-
html = renderer_for(resource_definition: resource_definition).render(model)
|
18
|
-
|
19
|
-
yield(resource_definition.selector, html, resource_definition.broadcast_each)
|
20
|
-
end
|
21
|
-
|
22
|
-
@resources_without_sgids.each do |resource_definition|
|
23
|
-
resource = lookup_resource(resource_definition)
|
24
|
-
renderer = renderer_for(resource_definition: resource_definition)
|
25
|
-
html =
|
26
|
-
begin
|
27
|
-
renderer.render(resource)
|
28
|
-
rescue => exception
|
29
|
-
error_renderer.render(exception)
|
30
|
-
end
|
31
|
-
|
32
|
-
yield(resource_definition.selector, html, resource_definition.broadcast_each)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
private
|
37
|
-
|
38
|
-
def error_renderer
|
39
|
-
ErrorRenderer.new
|
40
|
-
end
|
41
|
-
|
42
|
-
class ResourceDefinition
|
43
|
-
attr_reader :signed_params, :sgid, :signed_controller, :url
|
44
|
-
|
45
|
-
def initialize(resource_definition)
|
46
|
-
@signed_params, @sgid, @signed_controller, @url, @broadcast_each = resource_definition
|
47
|
-
end
|
48
|
-
|
49
|
-
def selector
|
50
|
-
selector = "[data-signed-params='#{@signed_params}']"
|
51
|
-
selector << "[data-sgid='#{@sgid}']" if @sgid.present?
|
52
|
-
selector
|
53
|
-
end
|
54
|
-
|
55
|
-
def controller
|
56
|
-
Resolver::Controller.from(signed_string: @signed_controller)
|
57
|
-
end
|
58
|
-
|
59
|
-
def broadcast_each
|
60
|
-
@broadcast_each == "true"
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
class ErrorRenderer
|
65
|
-
include ActionView::Helpers::TagHelper
|
66
|
-
|
67
|
-
def render(exception)
|
68
|
-
return "" unless render?
|
69
|
-
|
70
|
-
Futurism.logger.error(exception.to_s)
|
71
|
-
Futurism.logger.error(exception.backtrace)
|
72
|
-
|
73
|
-
tag.div { tag.span(exception.to_s) + tag.div(exception.backtrace.join("\n"), style: "display: none;") }
|
74
|
-
end
|
75
|
-
|
76
|
-
def render?
|
77
|
-
Rails.env.development? || Rails.env.test?
|
78
|
-
end
|
79
|
-
|
80
|
-
attr_accessor :output_buffer
|
81
|
-
end
|
82
|
-
|
83
|
-
def renderer_for(resource_definition:)
|
84
|
-
Resolver::Controller::Renderer.for(controller: resource_definition.controller,
|
85
|
-
connection: @connection,
|
86
|
-
url: resource_definition.url,
|
87
|
-
params: @params)
|
88
|
-
end
|
89
|
-
|
90
|
-
def resolved_models
|
91
|
-
GlobalID::Locator.locate_many_signed @resources_with_sgids.map(&:sgid)
|
92
|
-
end
|
93
|
-
|
94
|
-
def lookup_resource(resource_definition)
|
95
|
-
message_verifier
|
96
|
-
.verify(resource_definition.signed_params)
|
97
|
-
.deep_transform_values { |value| value.is_a?(String) && value.start_with?("gid://") ? GlobalID::Locator.locate(value) : value }
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
data/lib/futurism/version.rb~
DELETED
data/lib/futurism.rb~
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
require "rails"
|
2
|
-
require "action_cable"
|
3
|
-
require "cable_ready"
|
4
|
-
require "futurism/engine"
|
5
|
-
require "futurism/message_verifier"
|
6
|
-
require "futurism/resolver/resources"
|
7
|
-
require "futurism/resolver/controller"
|
8
|
-
require "futurism/resolver/controller/renderer"
|
9
|
-
require "futurism/channel"
|
10
|
-
require "futurism/helpers"
|
11
|
-
|
12
|
-
module Futurism
|
13
|
-
extend ActiveSupport::Autoload
|
14
|
-
|
15
|
-
autoload :Helpers, "futurism/helpers"
|
16
|
-
|
17
|
-
mattr_accessor :skip_in_test, default: false
|
18
|
-
|
19
|
-
mattr_writer :default_controller
|
20
|
-
def self.default_controller
|
21
|
-
(@@default_controller || "::ApplicationController").to_s.constantize
|
22
|
-
end
|
23
|
-
|
24
|
-
ActiveSupport.on_load(:action_view) do
|
25
|
-
include Futurism::Helpers
|
26
|
-
end
|
27
|
-
|
28
|
-
mattr_accessor :logger
|
29
|
-
self.logger ||= Rails.logger ? Rails.logger.new : Logger.new($stdout)
|
30
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
require "fileutils"
|
2
|
-
|
3
|
-
namespace :futurism do
|
4
|
-
desc "Let's look into a brighter future with futurism and CableReady"
|
5
|
-
task install: :environment do
|
6
|
-
system "yarn add @stimulus_reflex/futurism"
|
7
|
-
|
8
|
-
filepath = %w[
|
9
|
-
app/javascript/channels/index.js
|
10
|
-
app/javascript/channels/index.ts
|
11
|
-
app/javascript/packs/application.js
|
12
|
-
app/javascript/packs/application.ts
|
13
|
-
]
|
14
|
-
.select { |path| File.exist?(path) }
|
15
|
-
.map { |path| Rails.root.join(path) }
|
16
|
-
.first
|
17
|
-
|
18
|
-
puts "Updating #{filepath}"
|
19
|
-
lines = File.open(filepath, "r") { |f| f.readlines }
|
20
|
-
|
21
|
-
unless lines.find { |line| line.start_with?("import * as Futurism") }
|
22
|
-
matches = lines.select { |line| line =~ /\A(require|import)/ }
|
23
|
-
lines.insert lines.index(matches.last).to_i + 1, "import * as Futurism from '@stimulus_reflex/futurism'\n"
|
24
|
-
end
|
25
|
-
|
26
|
-
unless lines.find { |line| line.start_with?("import consumer") }
|
27
|
-
matches = lines.select { |line| line =~ /\A(require|import)/ }
|
28
|
-
lines.insert lines.index(matches.last).to_i + 1, "import consumer from '../channels/consumer'\n"
|
29
|
-
end
|
30
|
-
|
31
|
-
initialize_line = lines.find { |line| line.start_with?("Futurism.initializeElements") }
|
32
|
-
lines << "Futurism.initializeElements()\n" unless initialize_line
|
33
|
-
|
34
|
-
subscribe_line = lines.find { |line| line.start_with?("Futurism.createSubscription") }
|
35
|
-
lines << "Futurism.createSubscription(consumer)\n" unless subscribe_line
|
36
|
-
|
37
|
-
File.open(filepath, "w") { |f| f.write lines.join }
|
38
|
-
end
|
39
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
require "fileutils"
|
2
|
-
|
3
|
-
namespace :futurism do
|
4
|
-
desc "Let's look into a brighter future with futurism and CableReady"
|
5
|
-
task install: :environment do
|
6
|
-
system "yarn add @minthesize/futurism"
|
7
|
-
|
8
|
-
filepath = %w[
|
9
|
-
app/javascript/channels/index.js
|
10
|
-
app/javascript/channels/index.ts
|
11
|
-
app/javascript/packs/application.js
|
12
|
-
app/javascript/packs/application.ts
|
13
|
-
]
|
14
|
-
.select { |path| File.exist?(path) }
|
15
|
-
.map { |path| Rails.root.join(path) }
|
16
|
-
.first
|
17
|
-
|
18
|
-
puts "Updating #{filepath}"
|
19
|
-
lines = File.open(filepath, "r") { |f| f.readlines }
|
20
|
-
|
21
|
-
unless lines.find { |line| line.start_with?("import * as Futurism") }
|
22
|
-
matches = lines.select { |line| line =~ /\A(require|import)/ }
|
23
|
-
lines.insert lines.index(matches.last).to_i + 1, "import * as Futurism from '@minthesize/futurism'\n"
|
24
|
-
end
|
25
|
-
|
26
|
-
unless lines.find { |line| line.start_with?("import consumer") }
|
27
|
-
matches = lines.select { |line| line =~ /\A(require|import)/ }
|
28
|
-
lines.insert lines.index(matches.last).to_i + 1, "import consumer from '../channels/consumer'\n"
|
29
|
-
end
|
30
|
-
|
31
|
-
initialize_line = lines.find { |line| line.start_with?("Futurism.initializeElements") }
|
32
|
-
lines << "Futurism.initializeElements()\n" unless initialize_line
|
33
|
-
|
34
|
-
subscribe_line = lines.find { |line| line.start_with?("Futurism.createSubscription") }
|
35
|
-
lines << "Futurism.createSubscription(consumer)\n" unless subscribe_line
|
36
|
-
|
37
|
-
File.open(filepath, "w") { |f| f.write lines.join }
|
38
|
-
end
|
39
|
-
end
|