render_turbo_stream 1.4.8 → 1.4.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -6
- data/app/views/render_turbo_stream.html.erb +1 -1
- data/app/views/render_turbo_stream.turbo_stream.erb +4 -7
- data/lib/render_turbo_stream/test/request_helpers.rb +1 -1
- data/lib/render_turbo_stream/version.rb +1 -1
- data/lib/render_turbo_stream.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 64b60c79e4190078560e1f08d175acfe17563316c6bf6079401841e9ac316198
|
4
|
+
data.tar.gz: 42d0f14d62ad08acb537658b2b83b113297e464da77ac95a33d41b9667e6da6a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b47e40f983bff09126f2307f0b3f40e64a16132899cdb032573b4fcfa6ab1f9fb01256a8237eb15b17ce0c1e250a25e2e9f18af7efbdc14fd94f2ca4882c5b5c
|
7
|
+
data.tar.gz: 4e0c932e70b68297d69aecdda5259abc5bcd11e0c355c9c12b27dcda204d656f90680b97b5bff2472cda64d9828d0b51c9cadf3e58415acf155f034407a9a95d
|
data/README.md
CHANGED
@@ -81,6 +81,8 @@ def update
|
|
81
81
|
turbo_stream_save(
|
82
82
|
@customer.update(customer_params),
|
83
83
|
turbo_redirect_on_success_to: edit_customer_path(@customer),
|
84
|
+
id: 'customer-form',
|
85
|
+
partial: 'form'
|
84
86
|
)
|
85
87
|
end
|
86
88
|
```
|
@@ -91,7 +93,7 @@ This will set a status, generate a flash message and perform `render_turbo_strea
|
|
91
93
|
render_turbo_stream(
|
92
94
|
[
|
93
95
|
{
|
94
|
-
id: 'form',
|
96
|
+
id: 'customer-form',
|
95
97
|
partial: 'customers/form'
|
96
98
|
},
|
97
99
|
{
|
@@ -103,7 +105,7 @@ render_turbo_stream(
|
|
103
105
|
)
|
104
106
|
```
|
105
107
|
|
106
|
-
The `stream_partial` method is
|
108
|
+
The `stream_partial` method is for rendering a partial alone.
|
107
109
|
|
108
110
|
```ruby
|
109
111
|
stream_partial(
|
@@ -118,7 +120,7 @@ stream_partial(
|
|
118
120
|
|
119
121
|
**More options**
|
120
122
|
|
121
|
-
`render_turbo_stream` interprets a hash as a partial to be sent by `turbo_stream` and an array as a command to be sent. This allows you to perform most actions from e.g
|
123
|
+
`render_turbo_stream` interprets a hash as a partial to be sent by `turbo_stream` and an array as a command to be sent. This allows you to perform most actions from, e.g., [turbo_power](https://github.com/marcoroth/turbo_power). An example of adding a css class to an html element and updating the browser history would look like this:
|
122
124
|
|
123
125
|
```ruby
|
124
126
|
render_turbo_stream(
|
@@ -140,7 +142,7 @@ Under the hood, inside a `*.turbo_stream.erb` template, it does the following: `
|
|
140
142
|
|
141
143
|
**WORKAROUND for redirects inside frame**
|
142
144
|
|
143
|
-
Suppose you have a CRUD controller that should do all its actions inside a turbo frame. Classic redirect_to, along with a Flash message, would raise
|
145
|
+
Suppose you have a CRUD controller that should do all its actions inside a turbo frame. Classic redirect_to, along with a Flash message, would raise «Render and/or redirect were called multiple times in this action». See [issue](https://gitlab.com/sedl/renderturbostream/-/issues/3).
|
144
146
|
|
145
147
|
You can handle this by reloading the parent frame's src attribute. The code might look like this:
|
146
148
|
|
@@ -154,6 +156,9 @@ def update
|
|
154
156
|
:turbo_frame_set_src,
|
155
157
|
'cars-box',
|
156
158
|
cars_path
|
159
|
+
],
|
160
|
+
[
|
161
|
+
#... more actions possible ...
|
157
162
|
]
|
158
163
|
]
|
159
164
|
)
|
@@ -276,10 +281,10 @@ includes the plugin and has tests done by rspec/request and capybara.
|
|
276
281
|
|
277
282
|
## More Configs
|
278
283
|
|
279
|
-
On test helpers, the marker for a turbo-stream target is in most cases the id of the target element. This is true for the standard turbo-stream functions. On `turbo_power` it is the same in most cases. `RenderTurboStream::Libs.
|
284
|
+
On test helpers, the marker for a turbo-stream target is in most cases the id of the target element. This is true for the standard turbo-stream functions. On `turbo_power` it is the same in most cases. `RenderTurboStream::Libs.first_arg_is_html_id()` checks for which methods this is true. You can override this:
|
280
285
|
|
281
286
|
```ruby
|
282
|
-
config.x.render_turbo_stream.
|
287
|
+
config.x.render_turbo_stream.first_argument_is_html_id = %[replace append prepend turbo_frame_set_src]
|
283
288
|
```
|
284
289
|
|
285
290
|
This setting is relevant for testing helpers.
|
@@ -4,7 +4,7 @@
|
|
4
4
|
<% streams.each do |s| %>
|
5
5
|
|
6
6
|
<% if s.is_a?(Array) %>
|
7
|
-
<% attr_id = RenderTurboStream::Libs.
|
7
|
+
<% attr_id = RenderTurboStream::Libs.first_arg_is_html_id(s.first) %>
|
8
8
|
<% h = { attributes: s, type: 'command' } %>
|
9
9
|
<% h[:target] = "##{s.second}" if attr_id %>
|
10
10
|
<% rendered_partials.push(h) %>
|
@@ -7,25 +7,22 @@
|
|
7
7
|
<% if args.is_a?(Array) %>
|
8
8
|
|
9
9
|
<% ctl = "turbo_stream.#{args.first}, #{args[1..-1].join(', ')}" %>
|
10
|
-
<% Rails.logger.debug("
|
10
|
+
<% Rails.logger.debug(" • render-turbo-stream => #{ctl}") %>
|
11
11
|
<%= turbo_stream.send args.first, *(args[1..-1]) %>
|
12
12
|
|
13
13
|
|
14
14
|
<% else %>
|
15
15
|
<% ctl = { partial: args[:partial], id: args[:id], action: args[:action] } %>
|
16
16
|
<% info = { id: args[:id], partial: args[:partial], locals: args[:locals] } %>
|
17
|
-
<% if
|
18
|
-
<% Rails.logger.error(" ERROR RENDER TURBO STREAM => MISSING ACTION => #{args}") %>
|
19
|
-
<% error = true %>
|
20
|
-
|
21
|
-
<% elsif args[:action].present? %>
|
17
|
+
<% if args[:action].present? %>
|
22
18
|
<% Rails.logger.debug(" • render-turbo-stream #{args[:action].upcase} => #{info}") %>
|
23
19
|
<%= turbo_stream.send args[:action].to_sym, args[:id] do %>
|
24
20
|
<%= render args[:partial], locals: args[:locals]&.symbolize_keys %>
|
25
21
|
<% end %>
|
26
22
|
|
27
23
|
<% else %>
|
28
|
-
<% Rails.logger.error(" ERROR RENDER TURBO STREAM =>
|
24
|
+
<% Rails.logger.error(" ERROR RENDER TURBO STREAM => MISSING ACTION => #{args}") %>
|
25
|
+
<% error = true %>
|
29
26
|
<% end %>
|
30
27
|
<% end %>
|
31
28
|
|
@@ -62,7 +62,7 @@ module RenderTurboStream
|
|
62
62
|
|
63
63
|
if r['type'] == 'command'
|
64
64
|
act = r['attributes'].first
|
65
|
-
is_id = RenderTurboStream::Libs.
|
65
|
+
is_id = RenderTurboStream::Libs.first_arg_is_html_id(act)
|
66
66
|
if action.to_s == act && is_id && r['attributes'].second == id.to_s
|
67
67
|
k = [act, r['attributes'].second].join('-')
|
68
68
|
counts[k] ||= 0
|
data/lib/render_turbo_stream.rb
CHANGED
@@ -260,8 +260,8 @@ module RenderTurboStream
|
|
260
260
|
# This method checks for that
|
261
261
|
# it includes the methods from turbo-power
|
262
262
|
# used for test helpers
|
263
|
-
def self.
|
264
|
-
config = Rails.configuration.x.render_turbo_stream.
|
263
|
+
def self.first_arg_is_html_id(method)
|
264
|
+
config = Rails.configuration.x.render_turbo_stream.first_argument_is_html_id
|
265
265
|
default = [
|
266
266
|
:graft,
|
267
267
|
:morph,
|
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: 1.4.
|
4
|
+
version: 1.4.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- christian
|
@@ -72,6 +72,6 @@ requirements: []
|
|
72
72
|
rubygems_version: 3.4.12
|
73
73
|
signing_key:
|
74
74
|
specification_version: 4
|
75
|
-
summary:
|
75
|
+
summary: Run javascripts and render partials directly from the controller. With test
|
76
76
|
helpers.
|
77
77
|
test_files: []
|