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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '087b5154db888a207a6396af1e508245b50e652513ad89be3b048f3951578398'
4
- data.tar.gz: c54c8bd50712af73d95f75d614e46a2ff15346b50b95dfbc8a2294b341978fa2
3
+ metadata.gz: ac522064ae87773819b4fdd059166e10a8bbb805de1dbbd020781f806ac6faeb
4
+ data.tar.gz: a78259d9e2468305da273618929296735f3217592ed0ac2f0311e14b9c913eaf
5
5
  SHA512:
6
- metadata.gz: 69fd9f948bcc9e4b2c7f4a252f0958667a9cf8876b8185f307f02325f295f4023096d4991b0fa5b1f0648fb34074d9102d5741cbed5a52c09c0bb5d5b81b5043
7
- data.tar.gz: e2ebc9166c0ec6a5e37d7d8d574b42345fb7f1429dfed8026c295963fe47b5fd21913c048f2164897e2a974ee33e6254590814b5392728a9836ce81fc823701d
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
- args = {
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] = args.to_json
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
@@ -1,3 +1,3 @@
1
1
  module RenderTurboStream
2
- VERSION = "2.1.0"
2
+ VERSION = "2.1.1"
3
3
  end
@@ -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
- if e.present?
241
- res = JSON.parse(e.inner_html)
242
- else
243
- res = []
244
- end
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,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.1.0
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - christian