render_turbo_stream 4.4.1 → 4.4.2

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: 2751555dcedccddcd194a704306282dd4a7f9e8dfce3da98fff1f3f43008826b
4
- data.tar.gz: 40c7a231488efdd817a0143234188189e51c9dd27917c22858c637e7cce823ae
3
+ metadata.gz: f51ba85d359e9d879308ec309dbbf5ef7a8794fd56dc0046358d409c5ac35910
4
+ data.tar.gz: 34c7a35b5e35718dffffbdf413c3aa83056b8d23114887562b704713942b9a01
5
5
  SHA512:
6
- metadata.gz: 5c31b229cf1e1b14915c20e0a8b93ee5fe5f685fd3e1a2ae9b07d335d7b7a0b84a84b72138fa40e2ea71aa280f38cb66565ed3a3906e87d3d6f86b7ee0b58a15
7
- data.tar.gz: a8fd505b93f9ebe97b1fcac9540bf4bd6bdc8181f05b4ba719dda2c38fb0984c4b2d8ece9b023e95f2ae218cca10db0838807679bada4a3820350abeac05bd94
6
+ metadata.gz: 53b0e5e43f71d9737d9ccd0ee5559da2c82511940ddf716e673df31b0ba848a0a1e72a4cf1a22f40d339d592436102e465297f7e953f9b825218216c02970f23
7
+ data.tar.gz: 413575d69259ac12cf7ca07ca8cee548dfdd84405577bb89501f14cfcf443eaa7aed22b0537e6c8879683dae42297f075a10e8e2f3818d18eb595a910ab6a7e0
@@ -1,28 +1,29 @@
1
1
  <% error = false %>
2
- <% control = [] %>
2
+ <% tests = [] %>
3
3
  <% streams = local_assigns[:streams] %>
4
4
  <% streams.each do |args| %>
5
5
 
6
6
 
7
7
  <% if args.is_a?(Array) %>
8
8
 
9
- <% ctl = "turbo_stream.#{args.first}, #{args[1..-1].join(', ')}" %>
9
+ <% test = { type: 'stream-command', array: args, action: args.first } %>
10
10
  <%= turbo_stream.send args.first, *(args[1..-1]) %>
11
11
 
12
12
 
13
13
  <% else %>
14
- <% ctl = { partial: args[:partial], target_id: args[:target_id], action: args[:action] } %>
15
-
16
14
 
17
15
  <% locals = args[:locals]&.symbolize_keys %>
18
16
 
19
17
  <% if args[:partial].present? %>
20
18
  <% rendered_html = render(partial: args[:partial], locals: locals, formats: [:html]) %>
19
+ <% test = { partial: args[:partial], type: 'stream-partial' } %>
21
20
  <% else %>
22
21
  <% rendered_html = render(template: args[:template], locals: locals, formats: [:html]) %>
22
+ <% test = { template: args[:template], type: 'stream-template' } %>
23
23
  <% end %>
24
24
 
25
25
 
26
+
26
27
  <% unless args[:target].present? %>
27
28
  <% args[:target] = RenderTurboStream::Libs.fetch_arguments_from_rendered_string(rendered_html)[:target] %>
28
29
  <% if args[:target].present? %>
@@ -31,11 +32,12 @@
31
32
  <% raise "No target specified by arguments and no target found inside the rendered #{args[:partial].present? ? "partial: #{args[:partial]}" : "template: #{args[:template]}"}: «#{rendered_html}»" %>
32
33
  <% end %>
33
34
  <% end %>
35
+ <% test = test.merge(action: args[:action], html_response: rendered_html, target: args[:target] ) %>
34
36
 
35
37
 
36
38
  <% target_id = RenderTurboStream::Libs.target_to_target_id(args[:target]) %>
37
39
 
38
- <% info = { target_id: args[:target_id], partial: args[:partial], locals: args[:locals] } %>
40
+ <%# info = { target_id: args[:target_id], partial: args[:partial], locals: args[:locals] } %>
39
41
 
40
42
 
41
43
  <% if args[:action].present? %>
@@ -51,13 +53,16 @@
51
53
  <% end %>
52
54
  <% end %>
53
55
 
54
- <% control.push(ctl) %>
56
+ <% tests.push(test) %>
55
57
 
56
58
  <% end %>
57
59
 
58
60
  <% if error %>
59
61
  <% Rails.logger.error(" RENDER TURBO STREAM HAD ERRORS, REPEATING WHOLE ARRAY: ") %>
60
- <% control.each do |c| %>
61
- <% Rails.logger.error(" #{c}") %>
62
+ <% tests.each do |t| %>
63
+ <% Rails.logger.error(" #{t}") %>
62
64
  <% end %>
63
65
  <% end %>
66
+ <% if Rails.env.test? %>
67
+ <% RenderTurboStream::Test::Request::Libs.set_test_responses(response, tests) %>
68
+ <% end %>
@@ -88,7 +88,7 @@ module RenderTurboStream
88
88
  partial: _partial,
89
89
  locals: loc
90
90
  )
91
- RenderTurboStream::Libs.set_test_responses(response, libs.test_responses)
91
+ RenderTurboStream::Test::Request::Libs.set_test_responses(response, libs.test_responses)
92
92
 
93
93
  res
94
94
  end
@@ -132,7 +132,7 @@ module RenderTurboStream
132
132
  def action_to_channel(channel, command, arguments)
133
133
  libs = RenderTurboStream::ChannelLibs.new
134
134
  r = libs.action_to_channel(channel, command, arguments)
135
- RenderTurboStream::Libs.set_test_responses(response, libs.test_responses)
135
+ RenderTurboStream::Test::Request::Libs.set_test_responses(response, libs.test_responses)
136
136
  r
137
137
  end
138
138
 
@@ -209,7 +209,7 @@ module RenderTurboStream
209
209
  "authenticated_user_#{helpers.current_user.id}",
210
210
  turbo_actions
211
211
  )
212
- RenderTurboStream::Libs.set_test_responses(response, libs.test_responses)
212
+ RenderTurboStream::Test::Request::Libs.set_test_responses(response, libs.test_responses)
213
213
  end
214
214
 
215
215
  if save_action && if_success_redirect_to.present?
@@ -118,7 +118,7 @@ module RenderTurboStream
118
118
  Rails.logger.debug(" • Send actions through Turbo::StreamsChannel")
119
119
  c_libs = RenderTurboStream::ChannelLibs.new
120
120
  c_libs.send_actions_to_channel("authenticated_user_#{helpers.current_user.id}", streams)
121
- set_test_responses(c_libs.test_responses)
121
+ RenderTurboStream::Test::Request::Libs.set_test_responses(response, c_libs.test_responses)
122
122
  else
123
123
  flash[:alert] = flashes[:alerts]
124
124
  flash[:notice] = flashes[:notices]
@@ -177,12 +177,16 @@ module RenderTurboStream
177
177
  Rails.logger.debug(" • Stream => #{cmd}")
178
178
  end
179
179
 
180
- if request.format.to_sym == :turbo_stream
180
+
181
+
182
+
183
+ #if request.format.to_sym == :turbo_stream
181
184
  render template: 'render_turbo_stream', locals: { streams: ary }, layout: false, formats: :turbo_stream
182
- else
183
- Rails.logger.debug(" • Render Turbo Stream RENDERING AS HTML because request.format => #{request.format}")
184
- render template: 'render_turbo_stream_request_test', locals: { streams: ary }, layout: false, formats: :html
185
- end
185
+ # else
186
+ # Rails.logger.debug(" • Render Turbo Stream RENDERING AS HTML because request.format => #{request.format}")
187
+ # render template: 'render_turbo_stream_request_test', locals: { streams: ary }, layout: false, formats: :html
188
+ # end
189
+
186
190
 
187
191
  end
188
192
 
@@ -190,23 +194,5 @@ module RenderTurboStream
190
194
  render_turbo_stream([{ partial: partial, locals: locals, id: id, action: action }])
191
195
  end
192
196
 
193
-
194
- def set_test_responses(test_responses)
195
- if Rails.env.test?
196
- h = response.headers.to_h
197
- i = 1
198
- test_responses.each do |test_response|
199
- loop do
200
- k = "turbo-response-test-#{i}"
201
- unless h.keys.include?(k)
202
- response.headers[k] = test_response.to_json
203
- break
204
- end
205
- i += 1
206
- end
207
- end
208
- end
209
- end
210
-
211
197
  end
212
198
  end
@@ -99,22 +99,5 @@ module RenderTurboStream
99
99
  end
100
100
  end
101
101
 
102
- def self.set_test_responses(response, test_responses)
103
- if Rails.env.test?
104
- h = response.headers.to_h
105
- i = 1
106
- test_responses.each do |test_response|
107
- loop do
108
- k = "turbo-response-test-#{i}"
109
- unless h.keys.include?(k)
110
- response.headers[k] = test_response.to_json
111
- break
112
- end
113
- i += 1
114
- end
115
- end
116
- end
117
- end
118
-
119
102
  end
120
103
  end
@@ -7,10 +7,26 @@ module RenderTurboStream
7
7
  @response = response
8
8
  end
9
9
 
10
+ def self.set_test_responses(response, test_responses)
11
+ if Rails.env.test?
12
+ h = response.headers.to_h
13
+ i = 1
14
+ test_responses.each do |test_response|
15
+ loop do
16
+ k = "turbo-response-test-#{i}"
17
+ unless h.keys.include?(k)
18
+ response.headers[k] = test_response.to_json
19
+ break
20
+ end
21
+ i += 1
22
+ end
23
+ end
24
+ end
25
+ end
26
+
10
27
  def all_turbo_responses
11
28
 
12
- e = Nokogiri::HTML(@response.body).search('#rendered-partials').first
13
- res = (e.present? ? JSON.parse(e.inner_html) : [])
29
+ res = []
14
30
  @response.headers.each do |k, v|
15
31
  next unless k.match(/^turbo-response-test-[\d]+$/)
16
32
  h = JSON.parse(v)
@@ -1,3 +1,3 @@
1
1
  module RenderTurboStream
2
- VERSION = "4.4.1"
2
+ VERSION = "4.4.2"
3
3
  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: 4.4.1
4
+ version: 4.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - christian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-19 00:00:00.000000000 Z
11
+ date: 2024-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -46,7 +46,6 @@ files:
46
46
  - app/views/render_turbo_stream.turbo_stream.erb
47
47
  - app/views/render_turbo_stream_command.html.erb
48
48
  - app/views/render_turbo_stream_empty_template.html.erb
49
- - app/views/render_turbo_stream_request_test.html.erb
50
49
  - db/migrate/20230616070450_create_render_turbo_stream_options.rb
51
50
  - lib/render_turbo_stream.rb
52
51
  - lib/render_turbo_stream/channel.rb
@@ -1,41 +0,0 @@
1
- <% rendered_partials = [] %>
2
-
3
-
4
- <% streams.each do |s| %>
5
-
6
- <% if s.is_a?(Array) %>
7
- <% attr_id = RenderTurboStream::Test::Request::Libs.first_arg_is_html_id(s.first) %>
8
- <% h = { array: s, type: 'stream-command', action: s.first } %>
9
- <% h[:target] = "##{s.second[0] == '#' ? s.second[1..-1] : s.second}" if attr_id %>
10
- <% rendered_partials.push(h) %>
11
- <% else %>
12
-
13
-
14
- <% locals = s[:locals]&.symbolize_keys %>
15
- <% if s[:partial].present? %>
16
- <% html = (render partial: s[:partial], locals: locals, formats: [:html]) %>
17
- <% else %>
18
- <% html = (render template: s[:template], locals: locals, formats: [:html]) %>
19
- <% end %>
20
-
21
-
22
-
23
- <% unless s[:target].present? %>
24
- <% s[:target] = RenderTurboStream::Libs.fetch_arguments_from_rendered_string(html)[:target] %>
25
- <% if !s[:target].present? && html.present? %>
26
- <% raise "No target specified by arguments and no target found inside the rendered #{s[:partial].present? ? "partial: #{s[:partial]}" : "template: #{s[:template]}"}: «#{html}»" %>
27
- <% end %>
28
- <% end %>
29
-
30
-
31
-
32
- <% s[:target] = s[:target] %>
33
- <% s.delete(:id) %>
34
- <% rendered_partials.push({ html_response: html, type: 'stream-partial' }.merge(s)) %>
35
- <% end %>
36
-
37
-
38
- <% end %>
39
-
40
- <%= content_tag :div, rendered_partials.to_json, id: 'rendered-partials' %>
41
-