futurism 1.2.0.pre3 → 1.2.0.pre7

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: 80e0ce6e5c458215afe4266493a6644a029b75f005bfbadcdc181b82325e0d43
4
- data.tar.gz: 902744214a43cee7e28c57f1999e52191aaf2d2022860c53c4784ba9fda200fd
3
+ metadata.gz: 63b1ff17b81590446065de7fb4bf679605514bfaac06d59522f42d83fb6e771a
4
+ data.tar.gz: 5643e6051b11724edcf0274fb863c5d09a0d9fdfe82fd056c25bbdaaae901b69
5
5
  SHA512:
6
- metadata.gz: a8638ce1768afd2da09199dc9e033b32168b54c401fd5ab2b26e20e127b38e4c172b93d8846cca8cc0adb28078073fb0bcd2554d70a5d070e60f631d1d596e5b
7
- data.tar.gz: cf8c0a7ecd8451b15f7d71f496bd0e49adb358e1bf9770449424e4d4780709b410ba197f8c459a71468f46c3d7961b4ae331bd9e61e4d0e1d959720b46a7dd88
6
+ metadata.gz: c6803e1178cf5aab943cd1d7dfc7b1cea6a41342484a4e3d77235e8a4486925edbeccce713c95135e6f8b9df500cdad44d414c3208298c39739eb7f11b1e4f28
7
+ data.tar.gz: fba50ae48ee6c3100619cd62bc784f7e8e75c74698300fcd9e14dadf13d66987577badae393863e4da7dbe589c2c9016dde2296bbcf045e8193b91f5cde51d34
@@ -55,6 +55,7 @@ module Futurism
55
55
  class WrappingFuturismElement
56
56
  include ActionView::Helpers
57
57
  include Futurism::MessageVerifier
58
+ include Futurism::OptionsTransformer
58
59
 
59
60
  attr_reader :extends, :placeholder, :html_options, :data_attributes, :model, :options, :eager, :broadcast_each, :controller
60
61
 
@@ -92,14 +93,7 @@ module Futurism
92
93
  end
93
94
 
94
95
  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
96
+ dump_options(options)
103
97
  end
104
98
 
105
99
  private
@@ -56,7 +56,7 @@ module Futurism
56
56
  include ActionView::Helpers
57
57
  include Futurism::MessageVerifier
58
58
 
59
- attr_reader :placeholder, :html_options, :data_attributes, :model, :options, :eager, :broadcast_each, :controller
59
+ attr_reader :extends, :placeholder, :html_options, :data_attributes, :model, :options, :eager, :broadcast_each, :controller
60
60
 
61
61
  def initialize(extends:, placeholder:, options:)
62
62
  @extends = extends
@@ -81,7 +81,14 @@ module Futurism
81
81
  end
82
82
 
83
83
  def render
84
- content_tag :"futurism-element", placeholder, html_options.deep_merge({data: dataset, extends: extends})
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
85
92
  end
86
93
 
87
94
  def transformed_options
@@ -106,15 +113,6 @@ module Futurism
106
113
 
107
114
  message_verifier.generate(controller.to_s)
108
115
  end
109
-
110
- def extends
111
- # TODO remove this in the next major version
112
- case @extends
113
- when :li then "list-item"
114
- when :tr then "table-row"
115
- else @extends
116
- end
117
- end
118
116
  end
119
117
  end
120
118
  end
@@ -0,0 +1,20 @@
1
+ module Futurism
2
+ module OptionsTransformer
3
+ def dump_options(options)
4
+ require_relative "shims/deep_transform_values" unless options.respond_to? :deep_transform_values
5
+
6
+ options.deep_transform_values do |value|
7
+ next(value) unless value.respond_to?(:to_global_id)
8
+ next(value) if value.is_a?(ActiveRecord::Base) && value.new_record?
9
+
10
+ value.to_global_id.to_s
11
+ end
12
+ end
13
+
14
+ def load_options(options)
15
+ require_relative "shims/deep_transform_values" unless options.respond_to? :deep_transform_values
16
+
17
+ options.deep_transform_values { |value| value.is_a?(String) && value.start_with?("gid://") ? GlobalID::Locator.locate(value) : value }
18
+ end
19
+ end
20
+ end
File without changes
@@ -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
@@ -2,6 +2,7 @@ module Futurism
2
2
  module Resolver
3
3
  class Resources
4
4
  include Futurism::MessageVerifier
5
+ include Futurism::OptionsTransformer
5
6
 
6
7
  # resource definitions are an array of [signed_params, sgid, signed_controller, url, broadcast_each]
7
8
  def initialize(resource_definitions:, connection:, params:)
@@ -20,11 +21,11 @@ module Futurism
20
21
  end
21
22
 
22
23
  @resources_without_sgids.each do |resource_definition|
23
- resource = lookup_resource(resource_definition)
24
+ options = options_from_resource(resource_definition)
24
25
  renderer = renderer_for(resource_definition: resource_definition)
25
26
  html =
26
27
  begin
27
- renderer.render(resource)
28
+ renderer.render(options)
28
29
  rescue => exception
29
30
  error_renderer.render(exception)
30
31
  end
@@ -91,10 +92,9 @@ module Futurism
91
92
  GlobalID::Locator.locate_many_signed @resources_with_sgids.map(&:sgid)
92
93
  end
93
94
 
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 }
95
+ def options_from_resource(resource_definition)
96
+ load_options(message_verifier
97
+ .verify(resource_definition.signed_params))
98
98
  end
99
99
  end
100
100
  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.2.0.pre3"
2
+ VERSION = "1.2.0.pre7"
3
3
  end
@@ -1,3 +1,3 @@
1
1
  module Futurism
2
- VERSION = "1.2.0.pre2"
2
+ VERSION = "1.2.0.pre6"
3
3
  end
data/lib/futurism.rb CHANGED
@@ -3,6 +3,7 @@ require "action_cable"
3
3
  require "cable_ready"
4
4
  require "futurism/engine"
5
5
  require "futurism/message_verifier"
6
+ require "futurism/options_transformer"
6
7
  require "futurism/resolver/resources"
7
8
  require "futurism/resolver/controller"
8
9
  require "futurism/resolver/controller/renderer"
data/lib/futurism.rb~ CHANGED
@@ -3,6 +3,7 @@ require "action_cable"
3
3
  require "cable_ready"
4
4
  require "futurism/engine"
5
5
  require "futurism/message_verifier"
6
+ require "futurism/resolver/resources"
6
7
  require "futurism/resolver/controller"
7
8
  require "futurism/resolver/controller/renderer"
8
9
  require "futurism/channel"
@@ -20,7 +21,10 @@ module Futurism
20
21
  (@@default_controller || "::ApplicationController").to_s.constantize
21
22
  end
22
23
 
23
- ActiveSupport.on_load(:action_view) {
24
+ ActiveSupport.on_load(:action_view) do
24
25
  include Futurism::Helpers
25
- }
26
+ end
27
+
28
+ mattr_accessor :logger
29
+ self.logger ||= Rails.logger ? Rails.logger.new : Logger.new($stdout)
26
30
  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.2.0.pre3
4
+ version: 1.2.0.pre7
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-10-04 00:00:00.000000000 Z
11
+ date: 2021-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -128,14 +128,14 @@ dependencies:
128
128
  requirements:
129
129
  - - '='
130
130
  - !ruby/object:Gem::Version
131
- version: 5.0.0.pre4
131
+ version: 5.0.0.pre7
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: 5.0.0.pre4
138
+ version: 5.0.0.pre7
139
139
  description: Uses custom html elements with attached IntersectionObserver to automatically
140
140
  lazy load partials via websockets
141
141
  email:
@@ -156,6 +156,8 @@ files:
156
156
  - lib/futurism/helpers.rb
157
157
  - lib/futurism/helpers.rb~
158
158
  - lib/futurism/message_verifier.rb
159
+ - lib/futurism/options_transformer.rb
160
+ - lib/futurism/options_transformer.rb~
159
161
  - lib/futurism/resolver/controller.rb
160
162
  - lib/futurism/resolver/controller.rb~
161
163
  - lib/futurism/resolver/controller/renderer.rb