render_turbo_stream 4.4.0 → 4.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/views/render_turbo_stream.turbo_stream.erb +13 -8
- data/lib/render_turbo_stream/channel.rb +42 -40
- data/lib/render_turbo_stream/channel_controller_helpers.rb +3 -3
- data/lib/render_turbo_stream/controller_helpers.rb +10 -24
- data/lib/render_turbo_stream/libs.rb +0 -17
- data/lib/render_turbo_stream/test/request/libs.rb +18 -2
- data/lib/render_turbo_stream/version.rb +1 -1
- metadata +2 -3
- data/app/views/render_turbo_stream_request_test.html.erb +0 -41
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f51ba85d359e9d879308ec309dbbf5ef7a8794fd56dc0046358d409c5ac35910
|
4
|
+
data.tar.gz: 34c7a35b5e35718dffffbdf413c3aa83056b8d23114887562b704713942b9a01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53b0e5e43f71d9737d9ccd0ee5559da2c82511940ddf716e673df31b0ba848a0a1e72a4cf1a22f40d339d592436102e465297f7e953f9b825218216c02970f23
|
7
|
+
data.tar.gz: 413575d69259ac12cf7ca07ca8cee548dfdd84405577bb89501f14cfcf443eaa7aed22b0537e6c8879683dae42297f075a10e8e2f3818d18eb595a910ab6a7e0
|
@@ -1,28 +1,29 @@
|
|
1
1
|
<% error = false %>
|
2
|
-
<%
|
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
|
-
<%
|
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
|
-
|
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
|
-
<%
|
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
|
-
<%
|
61
|
-
<% Rails.logger.error(" #{
|
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 %>
|
@@ -1,43 +1,45 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
1
|
+
module RenderTurboStream
|
2
|
+
class Channel
|
3
|
+
|
4
|
+
def initialize(channel, partial: nil, template: nil, target_id: nil, action: :replace)
|
5
|
+
@channel = channel
|
6
|
+
@partial = partial
|
7
|
+
@template = template
|
8
|
+
@target_id = target_id
|
9
|
+
@action = action
|
10
|
+
@test_responses = []
|
11
|
+
end
|
12
|
+
|
13
|
+
def target_id=(target_id)
|
14
|
+
@target_id = target_id
|
15
|
+
end
|
16
|
+
|
17
|
+
def action=(action)
|
18
|
+
@action = action
|
19
|
+
end
|
20
|
+
|
21
|
+
def send(locals: {})
|
22
|
+
libs = RenderTurboStream::ChannelLibs.new
|
23
|
+
libs.render_to_channel(
|
24
|
+
@channel,
|
25
|
+
RenderTurboStream::Libs.target_id_to_target(@target_id),
|
26
|
+
@action,
|
27
|
+
template: @template,
|
28
|
+
partial: @partial,
|
29
|
+
locals: locals
|
30
|
+
)
|
31
|
+
@test_responses = libs.test_responses
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_responses
|
35
|
+
@test_responses
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def validate_params
|
41
|
+
raise 'Arguments partial and template cannot both be specified' if @partial && @template
|
42
|
+
end
|
15
43
|
|
16
|
-
def action=(action)
|
17
|
-
@action = action
|
18
44
|
end
|
19
|
-
|
20
|
-
def send(locals: {})
|
21
|
-
libs = RenderTurboStream::ChannelLibs.new
|
22
|
-
libs.render_to_channel(
|
23
|
-
@channel,
|
24
|
-
RenderTurboStream::Libs.target_id_to_target(@target_id),
|
25
|
-
@action,
|
26
|
-
template: @template,
|
27
|
-
partial: @partial,
|
28
|
-
locals: locals
|
29
|
-
)
|
30
|
-
@test_responses = libs.test_responses
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_responses
|
34
|
-
@test_responses
|
35
|
-
end
|
36
|
-
|
37
|
-
private
|
38
|
-
|
39
|
-
def validate_params
|
40
|
-
raise 'Arguments partial and template cannot both be specified' if @partial && @template
|
41
|
-
end
|
42
|
-
|
43
45
|
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
|
-
|
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
|
-
|
184
|
-
|
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
|
-
|
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)
|
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.
|
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-
|
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
|
-
|