futurism 1.2.0.pre4 → 1.2.0.pre8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +15 -1
- data/lib/futurism/helpers.rb +6 -9
- data/lib/futurism/helpers.rb~ +2 -8
- data/lib/futurism/options_transformer.rb +20 -0
- data/lib/futurism/options_transformer.rb~ +0 -0
- data/lib/futurism/resolver/resources.rb +6 -6
- data/lib/futurism/version.rb +1 -1
- data/lib/futurism/version.rb~ +1 -1
- data/lib/futurism.rb +1 -0
- data/lib/futurism.rb~ +6 -2
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c1bffa6e39b44603caf5ef679a8785e0df31e1019d57e2aef49208751a4fd7ba
|
4
|
+
data.tar.gz: f725d03372fa6919fb633801b884395cfefb88f95944adc22b08889bee97827c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55a981065cef8d8a62f169b0bb360418b642deaee1fc590ef2460c1e2723a60791df0f11e482c14985bfd40daaa9ff8e4a5d223fd26d204e68e31c7eb1675d2d
|
7
|
+
data.tar.gz: 2cdf24b379ca0d654a08981b130b500d2399243d8deeecd59164bc40ff1296f03c64c44606418ff29012dc72b8f546631e79df1af9fca90287340218af2e5a36
|
data/README.md
CHANGED
@@ -21,6 +21,7 @@ Lazy-load Rails partials via CableReady
|
|
21
21
|
- [Explicit Partial](#explicit-partial)
|
22
22
|
- [HTML Options](#html-options)
|
23
23
|
- [Eager Loading](#eager-loading)
|
24
|
+
- [Bypassing](#bypassing)
|
24
25
|
- [Broadcast Partials Individually](#broadcast-partials-individually)
|
25
26
|
- [Contextual Placeholder Arguments](#contextual-placeholder-arguments)
|
26
27
|
- [Events](#events)
|
@@ -175,6 +176,19 @@ Futurism makes that dead simple:
|
|
175
176
|
<% end %>
|
176
177
|
```
|
177
178
|
|
179
|
+
### Bypassing
|
180
|
+
|
181
|
+
In some rare cases, e.g. when combined with CableReady's async `updates_for` mechanism, you'll want to bypass futurism entirely and fall back to native `rendering`. You can do this by passing an `unless` option:
|
182
|
+
|
183
|
+
```erb
|
184
|
+
<%= futurize 'some_tab', unless: bypass_futurism?, extends: :tr do %>
|
185
|
+
<div class="placeholder"</td>
|
186
|
+
<% end %>
|
187
|
+
```
|
188
|
+
|
189
|
+
Internally, this works the same as [bypassing futurism in tests](#testing)
|
190
|
+
|
191
|
+
|
178
192
|
### Broadcast Partials Individually
|
179
193
|
Futurism's default behavior is to `broadcast` partials as they are generated in batches:
|
180
194
|
|
@@ -188,7 +202,7 @@ For collections, however, you can opt into individual broadcasts by specifying `
|
|
188
202
|
<% end %>
|
189
203
|
```
|
190
204
|
|
191
|
-
|
205
|
+
### Contextual Placeholder Arguments
|
192
206
|
|
193
207
|
For individual models or arbitrary collections, you can pass `record` and `index` to the placeholder block as arguments:
|
194
208
|
|
data/lib/futurism/helpers.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
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
|
4
|
+
if (Rails.env.test? && Futurism.skip_in_test) || options[:unless]
|
5
5
|
if records_or_string.nil?
|
6
6
|
return render(**options)
|
7
7
|
else
|
@@ -11,6 +11,9 @@ module Futurism
|
|
11
11
|
|
12
12
|
options[:eager] = true unless block_given?
|
13
13
|
|
14
|
+
# cannot serialize a proc
|
15
|
+
options.delete(:cached) if options[:cached].is_a?(Proc)
|
16
|
+
|
14
17
|
if records_or_string.is_a?(ActiveRecord::Base) || records_or_string.is_a?(ActiveRecord::Relation)
|
15
18
|
futurize_active_record(records_or_string, extends: extends, **options, &block)
|
16
19
|
elsif records_or_string.is_a?(String)
|
@@ -55,6 +58,7 @@ module Futurism
|
|
55
58
|
class WrappingFuturismElement
|
56
59
|
include ActionView::Helpers
|
57
60
|
include Futurism::MessageVerifier
|
61
|
+
include Futurism::OptionsTransformer
|
58
62
|
|
59
63
|
attr_reader :extends, :placeholder, :html_options, :data_attributes, :model, :options, :eager, :broadcast_each, :controller
|
60
64
|
|
@@ -92,14 +96,7 @@ module Futurism
|
|
92
96
|
end
|
93
97
|
|
94
98
|
def transformed_options
|
95
|
-
|
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
|
99
|
+
dump_options(options)
|
103
100
|
end
|
104
101
|
|
105
102
|
private
|
data/lib/futurism/helpers.rb~
CHANGED
@@ -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
|
-
|
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
|
@@ -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
|
@@ -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
|
-
|
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(
|
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
|
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
|
data/lib/futurism/version.rb
CHANGED
data/lib/futurism/version.rb~
CHANGED
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.
|
4
|
+
version: 1.2.0.pre8
|
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
|
11
|
+
date: 2021-11-10 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.
|
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.
|
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
|