render_turbo_stream 2.0.0 → 2.0.1
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00fd3b24190028352872dce17416ff89c2c31a416ae8f7a349de68193f39d10c
|
4
|
+
data.tar.gz: a1e51c47081672b873a5883fe580b31144aacdd3a33835dfd5e4d19db27e950e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 837d310de30b519f668e171f6eed9fac087e7fba358b6583e7e38ec5f0b9494ed613b94c1ca346dd25b5da1bc45acc635a11b5bc9b6c9df9275f0c434c448607
|
7
|
+
data.tar.gz: 1aaa0b80f38260fc542d3e6ea584473661664a84853cdfc8ab2f09946e0ffff34bf643a7677475d72be1334720f641143e591c0e41c6b6c47d435dae1b2a35ed
|
@@ -1,61 +1,69 @@
|
|
1
1
|
module RenderTurboStream
|
2
2
|
module TurboCableHelpers
|
3
3
|
|
4
|
-
def
|
5
|
-
|
4
|
+
# def cable_partial_to_all_authenticated_users
|
5
|
+
# raise "Function cable_partial_to_all_authenticated_users is "
|
6
|
+
# if user_signed_in?
|
7
|
+
#
|
8
|
+
# end
|
9
|
+
# end
|
6
10
|
|
7
|
-
|
8
|
-
|
11
|
+
def cable_partial_to_channel(action, channel, partial, id, locals: nil)
|
12
|
+
|
13
|
+
# add headers for test
|
9
14
|
|
10
|
-
def cable_to_me(id, action, *args, partial: nil, locals: nil)
|
11
|
-
begin
|
12
|
-
u_id = helpers.current_user&.id
|
13
|
-
a=1
|
14
|
-
unless u_id.present?
|
15
|
-
Rails.logger.debug(' • SKIP RenderTurboStream.cable_to_me because current_user is nil')
|
16
|
-
return
|
17
|
-
end
|
18
|
-
rescue
|
19
|
-
Rails.logger.debug(' • ERROR RenderTurboStream.cable_to_me because current_user is not available')
|
20
|
-
return
|
21
|
-
end
|
22
15
|
if Rails.env.test?
|
23
16
|
args = {
|
24
17
|
target: "##{id}",
|
25
18
|
action: action,
|
26
19
|
type: 'cable-partial',
|
27
|
-
args: args,
|
28
20
|
partial: partial,
|
29
21
|
locals: locals
|
30
22
|
}
|
31
23
|
h = response.headers.to_h
|
32
24
|
i = 1
|
33
25
|
loop do
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
26
|
+
k = "test-turbo-cable-#{i}"
|
27
|
+
unless h.keys.include?(k)
|
28
|
+
response.headers[k] = args.to_json
|
29
|
+
break
|
30
|
+
end
|
39
31
|
i += 1
|
40
32
|
end
|
41
33
|
end
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
34
|
+
|
35
|
+
# send
|
36
|
+
|
37
|
+
Turbo::StreamsChannel.send(
|
38
|
+
"broadcast_#{action}_to",
|
39
|
+
channel.to_s,
|
40
|
+
target: id,
|
41
|
+
partial: partial,
|
42
|
+
locals: locals&.symbolize_keys,
|
43
|
+
layout: false
|
44
|
+
)
|
45
|
+
end
|
46
|
+
|
47
|
+
def cable_partial_to_me(partial, id, action: :replace, locals: nil)
|
48
|
+
begin
|
49
|
+
u_id = helpers.current_user&.id
|
50
|
+
a=1
|
51
|
+
unless u_id.present?
|
52
|
+
Rails.logger.debug(' • SKIP RenderTurboStream.cable_partial_to_me because current_user is nil')
|
53
|
+
return
|
54
|
+
end
|
55
|
+
rescue
|
56
|
+
Rails.logger.debug(' • ERROR RenderTurboStream.cable_partial_to_me because current_user is not available')
|
57
|
+
return
|
58
58
|
end
|
59
|
+
|
60
|
+
cable_partial_to_channel(
|
61
|
+
action,
|
62
|
+
"current_user_#{helpers.current_user.id}",
|
63
|
+
partial,
|
64
|
+
id,
|
65
|
+
locals: locals
|
66
|
+
)
|
59
67
|
end
|
60
68
|
|
61
69
|
end
|
@@ -9,12 +9,16 @@ module RenderTurboStream
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
def cable_from_all_authenticated_users
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
12
|
+
# def cable_from_all_authenticated_users
|
13
|
+
# if user_signed_in?
|
14
|
+
# turbo_stream_from "all_authenticated_users"
|
15
|
+
# else
|
16
|
+
# Rails.logger.debug(" • SKIP CABLE_FROM_ALL_AUTHENTICATED_USERS because not authenticated")
|
17
|
+
# end
|
18
|
+
# end
|
19
|
+
|
20
|
+
def cable_from_all
|
21
|
+
turbo_stream_from "all"
|
18
22
|
end
|
19
23
|
|
20
24
|
def local_model(object)
|
data/lib/render_turbo_stream.rb
CHANGED
@@ -162,10 +162,10 @@ module RenderTurboStream
|
|
162
162
|
streams.each do |s|
|
163
163
|
next unless s.is_a?(Hash)
|
164
164
|
Rails.logger.debug(" • Send by Cable => «#{s}»")
|
165
|
-
|
165
|
+
cable_partial_to_me(
|
166
|
+
s[:partial],
|
166
167
|
s[:id],
|
167
|
-
:
|
168
|
-
partial: s[:partial],
|
168
|
+
action: flash_action,
|
169
169
|
locals: s[:locals]
|
170
170
|
)
|
171
171
|
end
|