futurism 1.1.0 → 1.2.0.pre4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 591fcd6ac1487dba8088003e9890f285336699ca85e4c54a42d8cc870c75a094
4
- data.tar.gz: 1acc85f2deb6f879104a8010581a42eeed05692154ef0fba7fc0f0858d88afcd
3
+ metadata.gz: 4d6957dab754ba0fa363c7636d060efee6cd1c0bf55d0e4ba71d6af6e5a4dd70
4
+ data.tar.gz: 59fd73ff311a606a26e307eab3185882c89bf3c27ac23ee7940dd32b1565ade2
5
5
  SHA512:
6
- metadata.gz: f037cca43c70ba733a81fe366b6af3885e262318cf3333194e756a7593d9e7df729bc651e6b37071607fe954f2baf77fac2eb7c6f027cd94daa2a29dc5d99df8
7
- data.tar.gz: cd1ae23d900d3e594cbb4f351afda32e96847eb3be9d263559f6540c1b306b24675315d87c4575cf17d60c4ed72675786a19e150ed5534ad18e98b29754c3b58
6
+ metadata.gz: 8333bc75d032dfeec4c3776c71df44a56f0c6a057ddfb2f09b026e27550e07289c425b9253c4bbb7d04ccd22497c5b67edf40828dd06b42b8b5315abd5451c32
7
+ data.tar.gz: 91c0f41783e97e8be0645a0a2814dbb29466c0d7bcda3a69d81fdc4267d21d72db98e4161f326c5792cab320cf711bb060fe348b7fe8fe9e27c7c1802b207517
@@ -28,12 +28,13 @@ module Futurism
28
28
 
29
29
  WrappingFuturismElement.new(extends: extends, placeholder: placeholder, options: options).render
30
30
  else
31
- placeholder = capture(record, index, &block) if block_given?
32
-
33
31
  collection_class_name = collection.try(:klass).try(:name) || collection.first.class.to_s
34
32
  as = options.delete(:as) || collection_class_name.underscore
35
33
  broadcast_each = options.delete(:broadcast_each) || false
34
+
36
35
  collection.each_with_index.map { |record, index|
36
+ placeholder = capture(record, index, &block) if block_given?
37
+
37
38
  WrappingFuturismElement.new(extends: extends, placeholder: placeholder, options: options.deep_merge(
38
39
  broadcast_each: broadcast_each,
39
40
  locals: {as.to_sym => record, "#{as}_counter".to_sym => index}
@@ -1,7 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Futurism
2
4
  module Resolver
3
5
  class Controller
4
6
  class Renderer
7
+ HTTP_METHODS = [:get, :post, :put, :patch, :delete]
8
+
5
9
  def self.for(controller:, connection:, url:, params:)
6
10
  new(controller: controller, connection: connection, url: url, params: params).renderer
7
11
  end
@@ -30,7 +34,7 @@ module Futurism
30
34
  path = ActionDispatch::Journey::Router::Utils.normalize_path(uri.path)
31
35
  query_hash = Rack::Utils.parse_nested_query(uri.query)
32
36
 
33
- path_params = Rails.application.routes.recognize_path(path)
37
+ path_params = recognize_url(url) # use full url to be more likely to match a url with subdomain constraints
34
38
 
35
39
  self.renderer =
36
40
  renderer.new(
@@ -42,7 +46,7 @@ module Futurism
42
46
  Rack::PATH_INFO => path,
43
47
  Rack::REQUEST_PATH => path,
44
48
  Rack::QUERY_STRING => uri.query,
45
- ActionDispatch::Http::Parameters::PARAMETERS_KEY => path_params.reverse_merge(path_params)
49
+ ActionDispatch::Http::Parameters::PARAMETERS_KEY => params.symbolize_keys.merge(path_params).merge(query_hash)
46
50
  )
47
51
  end
48
52
 
@@ -51,6 +55,21 @@ module Futurism
51
55
  new_env = connection.env.merge(renderer.instance_variable_get(:@env))
52
56
  renderer.instance_variable_set(:@env, new_env)
53
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
54
73
  end
55
74
  end
56
75
  end
@@ -3,7 +3,7 @@ module Futurism
3
3
  class Resources
4
4
  include Futurism::MessageVerifier
5
5
 
6
- # resource definitions are an array of [signed_params, sgid, signed_controller, url]
6
+ # resource definitions are an array of [signed_params, sgid, signed_controller, url, broadcast_each]
7
7
  def initialize(resource_definitions:, connection:, params:)
8
8
  @connection = connection
9
9
  @params = params
@@ -16,7 +16,7 @@ module Futurism
16
16
  resolved_models.zip(@resources_with_sgids).each do |model, resource_definition|
17
17
  html = renderer_for(resource_definition: resource_definition).render(model)
18
18
 
19
- yield(resource_definition.selector, html)
19
+ yield(resource_definition.selector, html, resource_definition.broadcast_each)
20
20
  end
21
21
 
22
22
  @resources_without_sgids.each do |resource_definition|
@@ -29,7 +29,7 @@ module Futurism
29
29
  error_renderer.render(exception)
30
30
  end
31
31
 
32
- yield(resource_definition.selector, html)
32
+ yield(resource_definition.selector, html, resource_definition.broadcast_each)
33
33
  end
34
34
  end
35
35
 
@@ -43,7 +43,7 @@ module Futurism
43
43
  attr_reader :signed_params, :sgid, :signed_controller, :url
44
44
 
45
45
  def initialize(resource_definition)
46
- @signed_params, @sgid, @signed_controller, @url = resource_definition
46
+ @signed_params, @sgid, @signed_controller, @url, @broadcast_each = resource_definition
47
47
  end
48
48
 
49
49
  def selector
@@ -55,6 +55,10 @@ module Futurism
55
55
  def controller
56
56
  Resolver::Controller.from(signed_string: @signed_controller)
57
57
  end
58
+
59
+ def broadcast_each
60
+ @broadcast_each == "true"
61
+ end
58
62
  end
59
63
 
60
64
  class ErrorRenderer
@@ -1,3 +1,3 @@
1
1
  module Futurism
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0.pre4"
3
3
  end
@@ -1,3 +1,3 @@
1
1
  module Futurism
2
- VERSION = "1.0.0"
2
+ VERSION = "1.2.0.pre3"
3
3
  end
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: 1.1.0
4
+ version: 1.2.0.pre4
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-09-14 00:00:00.000000000 Z
11
+ date: 2021-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -126,16 +126,16 @@ dependencies:
126
126
  name: cable_ready
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - ">="
129
+ - - '='
130
130
  - !ruby/object:Gem::Version
131
- version: '4'
131
+ version: 5.0.0.pre5
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - ">="
136
+ - - '='
137
137
  - !ruby/object:Gem::Version
138
- version: '4'
138
+ version: 5.0.0.pre5
139
139
  description: Uses custom html elements with attached IntersectionObserver to automatically
140
140
  lazy load partials via websockets
141
141
  email:
@@ -182,9 +182,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
182
182
  version: '0'
183
183
  required_rubygems_version: !ruby/object:Gem::Requirement
184
184
  requirements:
185
- - - ">="
185
+ - - ">"
186
186
  - !ruby/object:Gem::Version
187
- version: '0'
187
+ version: 1.3.1
188
188
  requirements: []
189
189
  rubygems_version: 3.1.4
190
190
  signing_key: