render_turbo_stream 2.1.0 → 2.1.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 +4 -4
- data/README.md +2 -2
- data/lib/render_turbo_stream/turbo_cable_helpers.rb +5 -5
- data/lib/render_turbo_stream/version.rb +1 -1
- data/lib/render_turbo_stream.rb +5 -17
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac522064ae87773819b4fdd059166e10a8bbb805de1dbbd020781f806ac6faeb
|
4
|
+
data.tar.gz: a78259d9e2468305da273618929296735f3217592ed0ac2f0311e14b9c913eaf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9e22fa2a8dbb9d7bb85d9fd19993ac6511c4cf9364c20da4b950b4bb368839c48f8c6ac93f31452592bc286f717d4c63107db7757731e339f1a37b871c7332a
|
7
|
+
data.tar.gz: 5c13d3c56d66450c20920403cef30c18c18e0101ba0c3de86516d9db26d57edcd5c3a37866dc6e2c9052e0f2be34c2751486b29361dd93a5b1f54f5255660dc6
|
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
|
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
|