render_turbo_stream 1.4.9 → 1.4.11
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 +11 -7
- data/app/views/render_turbo_stream.turbo_stream.erb +4 -7
- data/lib/render_turbo_stream/version.rb +1 -1
- data/lib/render_turbo_stream.rb +4 -4
- 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: 6aaffdee6cb866e03e20f1b6d46e00d187e9f7a63b0d5f26c29b4615fae7b483
|
4
|
+
data.tar.gz: b031dbf2eac68543ddf75de146c58715abaf3e6c6e9852119e3beb4f049832cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cec6a8701b17aabe2d76006771bd0441f28617a80bc16e9987d5334c84742d5df93471a7fb89d474b071fa2bd4f2391c78ea96abc3d8da8bc206198cf0268f64
|
7
|
+
data.tar.gz: 77afb83d8a217eca87b53cfa0aee768cdd8272052540758976c266d72f7d532119e9260473d761743b57de64e252ba41c48ef927685ee90122a0ee0300749a46
|
data/README.md
CHANGED
@@ -48,7 +48,7 @@ config.x.render_turbo_stream.flash_id = 'flash-box'
|
|
48
48
|
config.x.render_turbo_stream.flash_action = 'prepend'
|
49
49
|
```
|
50
50
|
|
51
|
-
The corresponding partials for flashes could look [like this](https://gitlab.com/sedl/renderturbostream/-/wikis/
|
51
|
+
The corresponding partials for flashes could look [like this](https://gitlab.com/sedl/renderturbostream/-/wikis/Flashes-example)
|
52
52
|
|
53
53
|
**Translations**
|
54
54
|
|
@@ -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,13 +142,12 @@ 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,
|
145
|
+
Suppose you have a CRUD controller that should do all its actions inside a turbo frame. Classic redirect_to, together with a turbo_stream action on the same response, 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
|
+
A workaround is to use the src attribute of the parent frame. `turbo_frame_set_src` comes from turbo_power. The code could look like this:
|
146
148
|
|
147
149
|
```ruby
|
148
150
|
def update
|
149
|
-
@car = Car.find(params['id'])
|
150
151
|
turbo_stream_save(
|
151
152
|
@car.update(car_params),
|
152
153
|
streams_on_success: [
|
@@ -154,6 +155,9 @@ def update
|
|
154
155
|
:turbo_frame_set_src,
|
155
156
|
'cars-box',
|
156
157
|
cars_path
|
158
|
+
],
|
159
|
+
[
|
160
|
+
#... more actions possible ...
|
157
161
|
]
|
158
162
|
]
|
159
163
|
)
|
@@ -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
|
|
data/lib/render_turbo_stream.rb
CHANGED
@@ -159,10 +159,9 @@ module RenderTurboStream
|
|
159
159
|
|
160
160
|
ary = []
|
161
161
|
array.each do |pr|
|
162
|
-
if
|
163
|
-
a = 1
|
164
|
-
elsif pr.is_a?(Hash)
|
162
|
+
if pr.is_a?(Hash)
|
165
163
|
props = pr.symbolize_keys
|
164
|
+
raise "missing attribute :id in #{props}" if !props[:id].present?
|
166
165
|
part = (props[:partial].present? ? props[:partial] : props[:id]).gsub('-', '_')
|
167
166
|
partial = (part.to_s.include?('/') ? part : [controller_path, part].join('/'))
|
168
167
|
r = props
|
@@ -170,6 +169,7 @@ module RenderTurboStream
|
|
170
169
|
r[:partial] = partial
|
171
170
|
ary.push(r)
|
172
171
|
elsif pr.is_a?(Array)
|
172
|
+
raise "array has to contain at least one element: #{pr}" unless pr.first.present?
|
173
173
|
ary.push(pr)
|
174
174
|
else
|
175
175
|
raise "ERROR render_turbo_stream invalid type: Only hash or array allowed"
|
@@ -289,7 +289,7 @@ module RenderTurboStream
|
|
289
289
|
:append,
|
290
290
|
:prepend
|
291
291
|
]
|
292
|
-
(config.present? ? config : default).map{|m|m.to_sym}.include?(method.to_sym)
|
292
|
+
(config.present? ? config : default).map { |m| m.to_sym }.include?(method.to_sym)
|
293
293
|
end
|
294
294
|
|
295
295
|
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: 1.4.
|
4
|
+
version: 1.4.11
|
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: []
|