render_turbo_stream 2.1.0 → 2.1.2
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: 92144d161ab6a0eee72442b7b848a140b9f439cbda17a3e41ad4a28aa5f0a8cb
|
4
|
+
data.tar.gz: 3b290864b96789968ab8ad704b1127cb37ab6c00985c11c1cd87c28a2cb87695
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea284231a3dd9343643a868bde136c954e32d0347354c5127f83b64e297e81309372214490df90580f32143c9a0f1422fe8f6abb2e2e1b9f7096726fb1454896
|
7
|
+
data.tar.gz: c8719357d38e4ced162e9bc2b94401ee3e7096f6097e1402b9ac9670c3b124326da0a9ac858b9ff5a434458efd010fb50d3b8104a6da6c8902cf0697cb748973
|
data/README.md
CHANGED
@@ -2,12 +2,12 @@
|
|
2
2
|
|
3
3
|
Defining templates like `(create|update).turbo_stream.haml` annoyed me.
|
4
4
|
|
5
|
-
Turbo has seamlessly integrated Action Cable. The intention here is to bring it all together in a unified workflow with a sufficient testing strategy.
|
6
|
-
|
7
5
|
Working consistently with turbo_stream or Turbo Streams Channel means shooting a lot of partials from the backend to the frontend. This always requires the same attributes: the path to the partial, the html id that turbo_stream points to, and maybe some locals, and maybe generate a translated flash message for update or create actions. All this can be done in one step directly from the controller.
|
8
6
|
|
9
7
|
There are many ways and tedious details to handle redirects since Turbo! Below described are options.
|
10
8
|
|
9
|
+
Turbo has seamlessly integrated Action Cable. The intention here is to bring it all together in a unified workflow with a sufficient testing strategy.
|
10
|
+
|
11
11
|
Execute [turbo_power](https://github.com/marcoroth/turbo_power) commands, such as adding a css class to an html element, pushing a state to the browser history, or running custom javascript actions through Turbo Stream (cable not yet integrated here) can be written in pure ruby code. No need for embeds like `.html.erb`.
|
12
12
|
|
13
13
|
This plugin is in a early state.
|
@@ -12,21 +12,21 @@ module RenderTurboStream
|
|
12
12
|
|
13
13
|
# add headers for test
|
14
14
|
if Rails.env.test?
|
15
|
-
|
15
|
+
html = RenderTurboStreamRenderController.render(partial: partial, locals: locals)
|
16
|
+
props = {
|
16
17
|
target: "##{id}",
|
17
18
|
action: action,
|
18
19
|
type: 'cable-partial',
|
19
20
|
partial: partial,
|
20
|
-
locals: locals
|
21
|
+
locals: locals,
|
22
|
+
html_response: html.to_s
|
21
23
|
}
|
22
|
-
html = RenderTurboStreamRenderController.render(partial: partial, locals: locals)
|
23
24
|
h = response.headers.to_h
|
24
25
|
i = 1
|
25
26
|
loop do
|
26
27
|
k = "test-turbo-cable-#{i}"
|
27
28
|
unless h.keys.include?(k)
|
28
|
-
response.headers[k] =
|
29
|
-
response.headers["#{k}-html"] = html.to_s
|
29
|
+
response.headers[k] = props.to_json
|
30
30
|
break
|
31
31
|
end
|
32
32
|
i += 1
|
@@ -45,6 +45,10 @@ module RenderTurboStream
|
|
45
45
|
)
|
46
46
|
end
|
47
47
|
|
48
|
+
def partial_to_all(action, partial, id, locals: nil)
|
49
|
+
partial_to_channel(action, 'all', partial, id, locals: locals)
|
50
|
+
end
|
51
|
+
|
48
52
|
def partial_to_me(partial, id, action: :replace, locals: nil)
|
49
53
|
begin
|
50
54
|
u_id = helpers.current_user&.id
|
@@ -6,6 +6,7 @@ module RenderTurboStream
|
|
6
6
|
turbo_stream_from "authenticated-user-#{current_user.id}"
|
7
7
|
else
|
8
8
|
Rails.logger.debug(" • SKIP CABLE_FROM_ME because not authenticated")
|
9
|
+
nil
|
9
10
|
end
|
10
11
|
end
|
11
12
|
|
@@ -15,11 +16,12 @@ module RenderTurboStream
|
|
15
16
|
turbo_stream_from "all-authenticated-users"
|
16
17
|
else
|
17
18
|
Rails.logger.debug(" • SKIP CABLE_FROM_ALL_AUTHENTICATED_USERS because not authenticated")
|
19
|
+
nil
|
18
20
|
end
|
19
21
|
end
|
20
22
|
|
21
23
|
def cable_from_all
|
22
|
-
|
24
|
+
turbo_stream_from "all"
|
23
25
|
end
|
24
26
|
|
25
27
|
def local_model(object)
|
data/lib/render_turbo_stream.rb
CHANGED
@@ -237,23 +237,11 @@ module RenderTurboStream
|
|
237
237
|
class Libs
|
238
238
|
def self.all_responses(response)
|
239
239
|
e = Nokogiri::HTML(response.body).search('#rendered-partials').first
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
cables = response.headers.to_h.select { |k| k.match(/^test-turbo-cable-[\d]+$/) }
|
246
|
-
cables.each do |k, v|
|
247
|
-
args = JSON.parse(v)
|
248
|
-
#html = ApplicationController.render(partial: args['partial'], locals: args['locals'].symbolize_keys)
|
249
|
-
html = response.headers["#{k}-html"]
|
250
|
-
res.push(
|
251
|
-
args.merge(
|
252
|
-
{
|
253
|
-
'html_response' => html,
|
254
|
-
}
|
255
|
-
)
|
256
|
-
)
|
240
|
+
res = (e.present? ? JSON.parse(e.inner_html) : [])
|
241
|
+
response.headers.each do |k, v|
|
242
|
+
next unless k.match(/^test-turbo-cable-[\d]+$/)
|
243
|
+
h = JSON.parse(v)
|
244
|
+
res.push(h)
|
257
245
|
end
|
258
246
|
res
|
259
247
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: render_turbo_stream
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- christian
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-05-
|
11
|
+
date: 2023-05-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|