turbo-rails 0.7.12 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -4
- data/app/assets/javascripts/turbo.js +6 -1
- data/app/channels/turbo/streams/broadcasts.rb +16 -16
- data/app/helpers/turbo/streams/action_helper.rb +7 -3
- data/app/models/concerns/turbo/broadcastable.rb +12 -12
- data/lib/install/turbo_needs_redis.rb +11 -1
- data/lib/tasks/turbo_tasks.rake +2 -2
- data/lib/turbo/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 53322c9735f1d41eb97512711037e8143fcaf903a60ed69b724a03c1859e329a
|
4
|
+
data.tar.gz: 2fddfbb67fc6b44ca622f2b33e7eef51130115759929f2f5e5a96fb060980582
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5867df95abc9376ff2f0df5be93545b2a3814853447b8a5a4c971b114066b041a8f8b9aa62faa537bdeae7402495e0395b9ae01a707dd2d8688b9f79ca51618f
|
7
|
+
data.tar.gz: 30057544c5b4bbf376903bb88c12759c90829243700273228b2a521ccd96dabac185c403856b1d471e71ed7aa53802a1afdc6cd783e1ed7ae0ab83513355d1ce
|
data/README.md
CHANGED
@@ -71,10 +71,7 @@ Turbo can coexist with Rails UJS, but you need to take a series of upgrade steps
|
|
71
71
|
|
72
72
|
## Development
|
73
73
|
|
74
|
-
|
75
|
-
* To install dependencies: `bundle install`
|
76
|
-
* To prepare the test database: `cd test/dummy; RAILS_ENV=test ./bin/rails db:migrate`
|
77
|
-
* To compile the JavaScript for the asset pipeline: `yarn build`
|
74
|
+
Run the tests with `./bin/test`.
|
78
75
|
|
79
76
|
|
80
77
|
## License
|
@@ -247,7 +247,11 @@ function dispatch(eventName, {target: target, cancelable: cancelable, detail: de
|
|
247
247
|
bubbles: true,
|
248
248
|
detail: detail
|
249
249
|
});
|
250
|
-
|
250
|
+
if (target && target.isConnected) {
|
251
|
+
target.dispatchEvent(event);
|
252
|
+
} else {
|
253
|
+
document.documentElement.dispatchEvent(event);
|
254
|
+
}
|
251
255
|
return event;
|
252
256
|
}
|
253
257
|
|
@@ -2556,6 +2560,7 @@ class Session {
|
|
2556
2560
|
const form = document.createElement("form");
|
2557
2561
|
form.method = linkMethod;
|
2558
2562
|
form.action = link.getAttribute("href") || "undefined";
|
2563
|
+
form.hidden = true;
|
2559
2564
|
(_a = link.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(form, link);
|
2560
2565
|
return dispatch("submit", {
|
2561
2566
|
cancelable: true,
|
@@ -6,61 +6,61 @@ module Turbo::Streams::Broadcasts
|
|
6
6
|
include Turbo::Streams::ActionHelper
|
7
7
|
|
8
8
|
def broadcast_remove_to(*streamables, **opts)
|
9
|
-
broadcast_action_to
|
9
|
+
broadcast_action_to(*streamables, action: :remove, **opts)
|
10
10
|
end
|
11
11
|
|
12
12
|
def broadcast_replace_to(*streamables, **opts)
|
13
|
-
broadcast_action_to
|
13
|
+
broadcast_action_to(*streamables, action: :replace, **opts)
|
14
14
|
end
|
15
15
|
|
16
16
|
def broadcast_update_to(*streamables, **opts)
|
17
|
-
broadcast_action_to
|
17
|
+
broadcast_action_to(*streamables, action: :update, **opts)
|
18
18
|
end
|
19
19
|
|
20
20
|
def broadcast_before_to(*streamables, **opts)
|
21
|
-
broadcast_action_to
|
21
|
+
broadcast_action_to(*streamables, action: :before, **opts)
|
22
22
|
end
|
23
23
|
|
24
24
|
def broadcast_after_to(*streamables, **opts)
|
25
|
-
broadcast_action_to
|
25
|
+
broadcast_action_to(*streamables, action: :after, **opts)
|
26
26
|
end
|
27
27
|
|
28
28
|
def broadcast_append_to(*streamables, **opts)
|
29
|
-
broadcast_action_to
|
29
|
+
broadcast_action_to(*streamables, action: :append, **opts)
|
30
30
|
end
|
31
31
|
|
32
32
|
def broadcast_prepend_to(*streamables, **opts)
|
33
|
-
broadcast_action_to
|
33
|
+
broadcast_action_to(*streamables, action: :prepend, **opts)
|
34
34
|
end
|
35
35
|
|
36
36
|
def broadcast_action_to(*streamables, action:, target: nil, targets: nil, **rendering)
|
37
|
-
broadcast_stream_to
|
37
|
+
broadcast_stream_to(*streamables, content: turbo_stream_action_tag(action, target: target, targets: targets, template:
|
38
38
|
rendering.delete(:content) || (rendering.any? ? render_format(:html, **rendering) : nil)
|
39
|
-
)
|
39
|
+
))
|
40
40
|
end
|
41
41
|
|
42
42
|
def broadcast_replace_later_to(*streamables, **opts)
|
43
|
-
broadcast_action_later_to
|
43
|
+
broadcast_action_later_to(*streamables, action: :replace, **opts)
|
44
44
|
end
|
45
45
|
|
46
46
|
def broadcast_update_later_to(*streamables, **opts)
|
47
|
-
broadcast_action_later_to
|
47
|
+
broadcast_action_later_to(*streamables, action: :update, **opts)
|
48
48
|
end
|
49
49
|
|
50
50
|
def broadcast_before_later_to(*streamables, **opts)
|
51
|
-
broadcast_action_later_to
|
51
|
+
broadcast_action_later_to(*streamables, action: :before, **opts)
|
52
52
|
end
|
53
53
|
|
54
54
|
def broadcast_after_later_to(*streamables, **opts)
|
55
|
-
broadcast_action_later_to
|
55
|
+
broadcast_action_later_to(*streamables, action: :after, **opts)
|
56
56
|
end
|
57
57
|
|
58
58
|
def broadcast_append_later_to(*streamables, **opts)
|
59
|
-
broadcast_action_later_to
|
59
|
+
broadcast_action_later_to(*streamables, action: :append, **opts)
|
60
60
|
end
|
61
61
|
|
62
62
|
def broadcast_prepend_later_to(*streamables, **opts)
|
63
|
-
broadcast_action_later_to
|
63
|
+
broadcast_action_later_to(*streamables, action: :prepend, **opts)
|
64
64
|
end
|
65
65
|
|
66
66
|
def broadcast_action_later_to(*streamables, action:, target: nil, targets: nil, **rendering)
|
@@ -69,7 +69,7 @@ module Turbo::Streams::Broadcasts
|
|
69
69
|
end
|
70
70
|
|
71
71
|
def broadcast_render_to(*streamables, **rendering)
|
72
|
-
broadcast_stream_to
|
72
|
+
broadcast_stream_to(*streamables, content: render_format(:turbo_stream, **rendering))
|
73
73
|
end
|
74
74
|
|
75
75
|
def broadcast_render_later_to(*streamables, **rendering)
|
@@ -14,7 +14,7 @@ module Turbo::Streams::ActionHelper
|
|
14
14
|
|
15
15
|
if target = convert_to_turbo_stream_dom_id(target)
|
16
16
|
%(<turbo-stream action="#{action}" target="#{target}">#{template}</turbo-stream>).html_safe
|
17
|
-
elsif targets = convert_to_turbo_stream_dom_id(targets)
|
17
|
+
elsif targets = convert_to_turbo_stream_dom_id(targets, include_selector: true)
|
18
18
|
%(<turbo-stream action="#{action}" targets="#{targets}">#{template}</turbo-stream>).html_safe
|
19
19
|
else
|
20
20
|
raise ArgumentError, "target or targets must be supplied"
|
@@ -22,7 +22,11 @@ module Turbo::Streams::ActionHelper
|
|
22
22
|
end
|
23
23
|
|
24
24
|
private
|
25
|
-
def convert_to_turbo_stream_dom_id(target)
|
26
|
-
target.respond_to?(:to_key)
|
25
|
+
def convert_to_turbo_stream_dom_id(target, include_selector: false)
|
26
|
+
if target.respond_to?(:to_key)
|
27
|
+
[ ("#" if include_selector), ActionView::RecordIdentifier.dom_id(target) ].compact.join
|
28
|
+
else
|
29
|
+
target
|
30
|
+
end
|
27
31
|
end
|
28
32
|
end
|
@@ -76,7 +76,7 @@ module Turbo::Broadcastable
|
|
76
76
|
# # Sends <turbo-stream action="remove" target="clearance_5"></turbo-stream> to the stream named "identity:2:clearances"
|
77
77
|
# clearance.broadcast_remove_to examiner.identity, :clearances
|
78
78
|
def broadcast_remove_to(*streamables, target: self)
|
79
|
-
Turbo::StreamsChannel.broadcast_remove_to
|
79
|
+
Turbo::StreamsChannel.broadcast_remove_to(*streamables, target: target)
|
80
80
|
end
|
81
81
|
|
82
82
|
# Same as <tt>#broadcast_remove_to</tt>, but the designated stream is automatically set to the current model.
|
@@ -95,7 +95,7 @@ module Turbo::Broadcastable
|
|
95
95
|
# # to the stream named "identity:2:clearances"
|
96
96
|
# clearance.broadcast_replace_to examiner.identity, :clearances, partial: "clearances/other_partial", locals: { a: 1 }
|
97
97
|
def broadcast_replace_to(*streamables, **rendering)
|
98
|
-
Turbo::StreamsChannel.broadcast_replace_to
|
98
|
+
Turbo::StreamsChannel.broadcast_replace_to(*streamables, target: self, **broadcast_rendering_with_defaults(rendering))
|
99
99
|
end
|
100
100
|
|
101
101
|
# Same as <tt>#broadcast_replace_to</tt>, but the designated stream is automatically set to the current model.
|
@@ -114,7 +114,7 @@ module Turbo::Broadcastable
|
|
114
114
|
# # to the stream named "identity:2:clearances"
|
115
115
|
# clearance.broadcast_update_to examiner.identity, :clearances, partial: "clearances/other_partial", locals: { a: 1 }
|
116
116
|
def broadcast_update_to(*streamables, **rendering)
|
117
|
-
Turbo::StreamsChannel.broadcast_update_to
|
117
|
+
Turbo::StreamsChannel.broadcast_update_to(*streamables, target: self, **broadcast_rendering_with_defaults(rendering))
|
118
118
|
end
|
119
119
|
|
120
120
|
# Same as <tt>#broadcast_update_to</tt>, but the designated stream is automatically set to the current model.
|
@@ -135,7 +135,7 @@ module Turbo::Broadcastable
|
|
135
135
|
# clearance.broadcast_before_to examiner.identity, :clearances, target: "clearance_5",
|
136
136
|
# partial: "clearances/other_partial", locals: { a: 1 }
|
137
137
|
def broadcast_before_to(*streamables, target:, **rendering)
|
138
|
-
Turbo::StreamsChannel.broadcast_before_to
|
138
|
+
Turbo::StreamsChannel.broadcast_before_to(*streamables, target: target, **broadcast_rendering_with_defaults(rendering))
|
139
139
|
end
|
140
140
|
|
141
141
|
# Insert a rendering of this broadcastable model after the target identified by it's dom id passed as <tt>target</tt>
|
@@ -151,7 +151,7 @@ module Turbo::Broadcastable
|
|
151
151
|
# clearance.broadcast_after_to examiner.identity, :clearances, target: "clearance_5",
|
152
152
|
# partial: "clearances/other_partial", locals: { a: 1 }
|
153
153
|
def broadcast_after_to(*streamables, target:, **rendering)
|
154
|
-
Turbo::StreamsChannel.broadcast_after_to
|
154
|
+
Turbo::StreamsChannel.broadcast_after_to(*streamables, target: target, **broadcast_rendering_with_defaults(rendering))
|
155
155
|
end
|
156
156
|
|
157
157
|
# Append a rendering of this broadcastable model to the target identified by it's dom id passed as <tt>target</tt>
|
@@ -167,7 +167,7 @@ module Turbo::Broadcastable
|
|
167
167
|
# clearance.broadcast_append_to examiner.identity, :clearances, target: "clearances",
|
168
168
|
# partial: "clearances/other_partial", locals: { a: 1 }
|
169
169
|
def broadcast_append_to(*streamables, target: broadcast_target_default, **rendering)
|
170
|
-
Turbo::StreamsChannel.broadcast_append_to
|
170
|
+
Turbo::StreamsChannel.broadcast_append_to(*streamables, target: target, **broadcast_rendering_with_defaults(rendering))
|
171
171
|
end
|
172
172
|
|
173
173
|
# Same as <tt>#broadcast_append_to</tt>, but the designated stream is automatically set to the current model.
|
@@ -188,7 +188,7 @@ module Turbo::Broadcastable
|
|
188
188
|
# clearance.broadcast_prepend_to examiner.identity, :clearances, target: "clearances",
|
189
189
|
# partial: "clearances/other_partial", locals: { a: 1 }
|
190
190
|
def broadcast_prepend_to(*streamables, target: broadcast_target_default, **rendering)
|
191
|
-
Turbo::StreamsChannel.broadcast_prepend_to
|
191
|
+
Turbo::StreamsChannel.broadcast_prepend_to(*streamables, target: target, **broadcast_rendering_with_defaults(rendering))
|
192
192
|
end
|
193
193
|
|
194
194
|
# Same as <tt>#broadcast_prepend_to</tt>, but the designated stream is automatically set to the current model.
|
@@ -213,7 +213,7 @@ module Turbo::Broadcastable
|
|
213
213
|
|
214
214
|
# Same as <tt>broadcast_replace_to</tt> but run asynchronously via a <tt>Turbo::Streams::BroadcastJob</tt>.
|
215
215
|
def broadcast_replace_later_to(*streamables, **rendering)
|
216
|
-
Turbo::StreamsChannel.broadcast_replace_later_to
|
216
|
+
Turbo::StreamsChannel.broadcast_replace_later_to(*streamables, target: self, **broadcast_rendering_with_defaults(rendering))
|
217
217
|
end
|
218
218
|
|
219
219
|
# Same as <tt>#broadcast_replace_later_to</tt>, but the designated stream is automatically set to the current model.
|
@@ -223,7 +223,7 @@ module Turbo::Broadcastable
|
|
223
223
|
|
224
224
|
# Same as <tt>broadcast_update_to</tt> but run asynchronously via a <tt>Turbo::Streams::BroadcastJob</tt>.
|
225
225
|
def broadcast_update_later_to(*streamables, **rendering)
|
226
|
-
Turbo::StreamsChannel.broadcast_update_later_to
|
226
|
+
Turbo::StreamsChannel.broadcast_update_later_to(*streamables, target: self, **broadcast_rendering_with_defaults(rendering))
|
227
227
|
end
|
228
228
|
|
229
229
|
# Same as <tt>#broadcast_update_later_to</tt>, but the designated stream is automatically set to the current model.
|
@@ -233,7 +233,7 @@ module Turbo::Broadcastable
|
|
233
233
|
|
234
234
|
# Same as <tt>broadcast_append_to</tt> but run asynchronously via a <tt>Turbo::Streams::BroadcastJob</tt>.
|
235
235
|
def broadcast_append_later_to(*streamables, target: broadcast_target_default, **rendering)
|
236
|
-
Turbo::StreamsChannel.broadcast_append_later_to
|
236
|
+
Turbo::StreamsChannel.broadcast_append_later_to(*streamables, target: target, **broadcast_rendering_with_defaults(rendering))
|
237
237
|
end
|
238
238
|
|
239
239
|
# Same as <tt>#broadcast_append_later_to</tt>, but the designated stream is automatically set to the current model.
|
@@ -243,7 +243,7 @@ module Turbo::Broadcastable
|
|
243
243
|
|
244
244
|
# Same as <tt>broadcast_prepend_to</tt> but run asynchronously via a <tt>Turbo::Streams::BroadcastJob</tt>.
|
245
245
|
def broadcast_prepend_later_to(*streamables, target: broadcast_target_default, **rendering)
|
246
|
-
Turbo::StreamsChannel.broadcast_prepend_later_to
|
246
|
+
Turbo::StreamsChannel.broadcast_prepend_later_to(*streamables, target: target, **broadcast_rendering_with_defaults(rendering))
|
247
247
|
end
|
248
248
|
|
249
249
|
# Same as <tt>#broadcast_prepend_later_to</tt>, but the designated stream is automatically set to the current model.
|
@@ -283,7 +283,7 @@ module Turbo::Broadcastable
|
|
283
283
|
# Same as <tt>broadcast_render_later</tt> but run with the added option of naming the stream using the passed
|
284
284
|
# <tt>streamables</tt>.
|
285
285
|
def broadcast_render_later_to(*streamables, **rendering)
|
286
|
-
Turbo::StreamsChannel.broadcast_render_later_to
|
286
|
+
Turbo::StreamsChannel.broadcast_render_later_to(*streamables, **broadcast_rendering_with_defaults(rendering))
|
287
287
|
end
|
288
288
|
|
289
289
|
|
@@ -1,6 +1,16 @@
|
|
1
1
|
if (cable_config_path = Rails.root.join("config/cable.yml")).exist?
|
2
2
|
say "Enable redis in bundle"
|
3
|
-
|
3
|
+
|
4
|
+
gemfile_content = File.read(Rails.root.join("Gemfile"))
|
5
|
+
pattern = /gem ['"]redis['"]/
|
6
|
+
|
7
|
+
if gemfile_content.match?(pattern)
|
8
|
+
uncomment_lines "Gemfile", pattern
|
9
|
+
else
|
10
|
+
gem 'redis', '~> 4.0', comment: "Use Redis as Action Cable adapter instead of default Async. The Async adapter\ndoes not support Turbo Stream broadcasting."
|
11
|
+
end
|
12
|
+
|
13
|
+
run_bundle
|
4
14
|
|
5
15
|
say "Switch development cable to use redis"
|
6
16
|
gsub_file cable_config_path.to_s, /development:\n\s+adapter: async/, "development:\n adapter: redis\n url: redis://localhost:6379/1"
|
data/lib/tasks/turbo_tasks.rake
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
def run_turbo_install_template(path)
|
2
|
-
system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../install/#{path}.rb",
|
2
|
+
system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../install/#{path}.rb", __dir__)}"
|
3
3
|
end
|
4
4
|
|
5
5
|
def redis_installed?
|
6
|
-
system('which redis-server')
|
6
|
+
system('which redis-server > /dev/null')
|
7
7
|
end
|
8
8
|
|
9
9
|
def switch_on_redis_if_available
|
data/lib/turbo/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: turbo-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Stephenson
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2021-09-
|
13
|
+
date: 2021-09-24 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|