futurism 1.2.0.pre7 → 1.2.0.pre10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/Appraisals +24 -0
  3. data/Appraisals~ +24 -0
  4. data/CHANGELOG.md +370 -0
  5. data/Gemfile +15 -0
  6. data/Gemfile.lock +215 -0
  7. data/Gemfile~ +17 -0
  8. data/README.md +59 -10
  9. data/README.md~ +405 -0
  10. data/app/assets/javascripts/futurism.js +191 -0
  11. data/app/assets/javascripts/futurism.min.js +2 -0
  12. data/app/assets/javascripts/futurism.min.js.map +1 -0
  13. data/app/assets/javascripts/futurism.umd.js +188 -0
  14. data/app/assets/javascripts/futurism.umd.min.js +2 -0
  15. data/app/assets/javascripts/futurism.umd.min.js.map +1 -0
  16. data/{lib → app/channels}/futurism/channel.rb +1 -1
  17. data/bin/rails +25 -0
  18. data/bin/standardize +5 -0
  19. data/bin/test +5 -0
  20. data/futurism.gemspec +38 -0
  21. data/futurism.gemspec~ +30 -0
  22. data/lib/futurism/configuration.rb +21 -0
  23. data/lib/futurism/engine.rb +19 -0
  24. data/lib/futurism/helpers.rb +5 -2
  25. data/lib/futurism/importmap.rb +2 -0
  26. data/lib/futurism/version.rb +1 -1
  27. data/lib/futurism.rb +2 -1
  28. data/package.json +47 -0
  29. data/package.json~ +51 -0
  30. data/rollup.config.js +77 -0
  31. data/rollup.config.js~ +73 -0
  32. data/test/cable/channel_test.rb +319 -0
  33. data/test/dummy/app/channels/application_cable/channel.rb +4 -0
  34. data/test/dummy/app/channels/application_cable/connection.rb +4 -0
  35. data/test/dummy/app/controllers/application_controller.rb +2 -0
  36. data/test/dummy/app/controllers/home_controller.rb +6 -0
  37. data/test/dummy/app/controllers/posts_controller.rb +59 -0
  38. data/test/dummy/app/helpers/application_helper.rb +2 -0
  39. data/test/dummy/app/helpers/posts_helper.rb +2 -0
  40. data/test/dummy/app/jobs/application_job.rb +7 -0
  41. data/test/dummy/app/models/action_item.rb +2 -0
  42. data/test/dummy/app/models/application_record.rb +3 -0
  43. data/test/dummy/app/models/post.rb +2 -0
  44. data/test/dummy/config/application.rb +29 -0
  45. data/test/dummy/config/boot.rb +5 -0
  46. data/test/dummy/config/environment.rb +5 -0
  47. data/test/dummy/config/environments/development.rb +40 -0
  48. data/test/dummy/config/environments/production.rb +94 -0
  49. data/test/dummy/config/environments/test.rb +39 -0
  50. data/test/dummy/config/initializers/application_controller_renderer.rb +8 -0
  51. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  52. data/test/dummy/config/initializers/content_security_policy.rb +28 -0
  53. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  54. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  55. data/test/dummy/config/initializers/inflections.rb +16 -0
  56. data/test/dummy/config/initializers/mime_types.rb +4 -0
  57. data/test/dummy/config/initializers/wrap_parameters.rb +9 -0
  58. data/test/dummy/config/puma.rb +38 -0
  59. data/test/dummy/config/routes.rb +12 -0
  60. data/test/dummy/config/spring.rb +6 -0
  61. data/test/dummy/db/migrate/20200711122838_create_posts.rb +9 -0
  62. data/test/dummy/db/migrate/2021042923813_create_action_items.rb +9 -0
  63. data/test/dummy/db/schema.rb +27 -0
  64. data/test/futurism_test.rb +28 -0
  65. data/test/helper/helper_test.rb +206 -0
  66. data/test/integration/navigation_test.rb +7 -0
  67. data/test/resolver/controller/renderer_test.rb +120 -0
  68. data/test/resolver/controller_test.rb +26 -0
  69. data/test/test_helper.rb +14 -0
  70. data/yarn.lock +3263 -0
  71. metadata +122 -18
  72. data/config/routes.rb +0 -2
  73. data/lib/futurism/channel.rb~ +0 -31
  74. data/lib/futurism/helpers.rb~ +0 -118
  75. data/lib/futurism/options_transformer.rb~ +0 -0
  76. data/lib/futurism/resolver/controller/renderer.rb~ +0 -76
  77. data/lib/futurism/resolver/controller.rb~ +0 -17
  78. data/lib/futurism/resolver/resources.rb~ +0 -101
  79. data/lib/futurism/version.rb~ +0 -3
  80. data/lib/futurism.rb~ +0 -30
  81. data/lib/tasks/futurism_tasks.rake +0 -39
  82. 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.pre7
4
+ version: 1.2.0.pre10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Rubisch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-05 00:00:00.000000000 Z
11
+ date: 2022-04-04 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.pre7
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.pre7
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
- - config/routes.rb
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/helpers.rb~
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
- - lib/futurism/version.rb~
170
- - lib/tasks/futurism_tasks.rake
171
- - lib/tasks/futurism_tasks.rake~
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.1.4
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
@@ -1,2 +0,0 @@
1
- Rails.application.routes.draw do
2
- end
@@ -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
@@ -1,118 +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
-
59
- attr_reader :extends, :placeholder, :html_options, :data_attributes, :model, :options, :eager, :broadcast_each, :controller
60
-
61
- def initialize(extends:, placeholder:, options:)
62
- @extends = extends
63
- @placeholder = placeholder
64
- @eager = options.delete(:eager)
65
- @broadcast_each = options.delete(:broadcast_each)
66
- @controller = options.delete(:controller)
67
- @html_options = options.delete(:html_options) || {}
68
- @data_attributes = html_options.fetch(:data, {}).except(:sgid, :signed_params)
69
- @model = options.delete(:model)
70
- @options = data_attributes.any? ? options.merge(data: data_attributes) : options
71
- end
72
-
73
- def dataset
74
- data_attributes.merge({
75
- signed_params: signed_params,
76
- sgid: model && model.to_sgid.to_s,
77
- eager: eager.presence,
78
- broadcast_each: broadcast_each.presence,
79
- signed_controller: signed_controller
80
- })
81
- end
82
-
83
- def render
84
- case extends
85
- when :li
86
- content_tag :li, placeholder, html_options.deep_merge({data: dataset, is: "futurism-li"})
87
- when :tr
88
- content_tag :tr, placeholder, html_options.deep_merge({data: dataset, is: "futurism-table-row"})
89
- else
90
- content_tag :"futurism-element", placeholder, html_options.deep_merge({data: dataset})
91
- end
92
- end
93
-
94
- def transformed_options
95
- require_relative "shims/deep_transform_values" unless options.respond_to? :deep_transform_values
96
-
97
- options.deep_transform_values do |value|
98
- next(value) unless value.respond_to?(:to_global_id)
99
- next(value) if value.is_a?(ActiveRecord::Base) && value.new_record?
100
-
101
- value.to_global_id.to_s
102
- end
103
- end
104
-
105
- private
106
-
107
- def signed_params
108
- message_verifier.generate(transformed_options)
109
- end
110
-
111
- def signed_controller
112
- return unless controller.present?
113
-
114
- message_verifier.generate(controller.to_s)
115
- end
116
- end
117
- end
118
- 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
@@ -1,3 +0,0 @@
1
- module Futurism
2
- VERSION = "1.2.0.pre6"
3
- end
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