render_turbo_stream 2.0.0 → 2.0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f1923db5dbed0c8a3f0cc583ba8de9469b16f0d09fdf3d46b48002ee1099537a
4
- data.tar.gz: 7c2bdf446e15de06c2704311fc2725b84613592ac91827eaa4df69a51d383d1a
3
+ metadata.gz: 00fd3b24190028352872dce17416ff89c2c31a416ae8f7a349de68193f39d10c
4
+ data.tar.gz: a1e51c47081672b873a5883fe580b31144aacdd3a33835dfd5e4d19db27e950e
5
5
  SHA512:
6
- metadata.gz: f2258c4ae8b77734f82837a883011591a5d6798d1110f3b63cf7ea557a3a3c60e8f5a358dd9a3dc963c02e0215979d91842d25dd94dfaf6c79e8cc3cc4483e59
7
- data.tar.gz: 1495b280772066632effbc8bf484c9d5aa867e3c8fe86d745b6264fb1e0b029420be850bfe432765ade82bc0d5617fcb1dcce2ca2a5611e4c8e01b150483f5bb
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 cable_to_all_authenticated_users
5
- if user_signed_in?
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
- end
8
- end
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
- k = "test-turbo-cable-#{i}"
35
- unless h.keys.include?(k)
36
- response.headers[k] = args.to_json
37
- break
38
- end
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
- if [:append, :prepend, :replace].include?(action.to_sym)
43
- Turbo::StreamsChannel.send(
44
- "broadcast_#{action}_to",
45
- "current_user_#{helpers.current_user.id}",
46
- *args,
47
- target: id,
48
- partial: partial,
49
- locals: locals&.symbolize_keys,
50
- layout: false
51
- )
52
- else
53
- # Turbo::StreamsChannel.broadcast_action_to(
54
- # "current_user_#{helpers.current_user.id}",
55
- # action:'toggle_css_class',
56
- # 'colored-element'
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
- 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
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)
@@ -1,3 +1,3 @@
1
1
  module RenderTurboStream
2
- VERSION = "2.0.0"
2
+ VERSION = "2.0.1"
3
3
  end
@@ -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
- cable_to_me(
165
+ cable_partial_to_me(
166
+ s[:partial],
166
167
  s[:id],
167
- :prepend,
168
- partial: s[:partial],
168
+ action: flash_action,
169
169
  locals: s[:locals]
170
170
  )
171
171
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: render_turbo_stream
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - christian