render_turbo_stream 4.3.4 → 4.3.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -1
- data/app/views/render_turbo_stream.turbo_stream.erb +1 -1
- data/app/views/render_turbo_stream_request_test.html.erb +1 -1
- data/lib/render_turbo_stream/controller_helpers.rb +16 -4
- data/lib/render_turbo_stream/libs.rb +1 -1
- data/lib/render_turbo_stream/version.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: 50b66f69ea709549c4533179701f90c46ab72be3f94f122f1b88bf14bc2e904b
|
4
|
+
data.tar.gz: 24cfb4ca73c7250583d1eb38bf85c83d22381eb7ef06a201ac54d413cc3f4c51
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d377ad2e7c8d8a6445aba275dde712fc68687ead0c330467d5c5d14eb68889645e6dc6cfbe20cfdbdb2804a34dade175c7eac20e92c900d2b8c7ae50584fe3b
|
7
|
+
data.tar.gz: e2919553ed95baa2f4d9dca401552b656db4001bda833378f5c37a1a14d856eaa4d07c2eca2adf956fef1bb20b1f7d42143e51fa0aa420883e01335b8b96f336
|
data/README.md
CHANGED
@@ -109,7 +109,7 @@ The Rails team has integrated `ActionCable` as `Turbo::StreamsChannel` into `Tur
|
|
109
109
|
|
110
110
|
```ruby
|
111
111
|
|
112
|
-
def
|
112
|
+
def create
|
113
113
|
turbo_stream_save(
|
114
114
|
@article.update(article_params),
|
115
115
|
if_success_redirect_to: articles_path,
|
@@ -118,6 +118,8 @@ def update
|
|
118
118
|
end
|
119
119
|
```
|
120
120
|
|
121
|
+
Note that if you want to redirect to show path, but the save action fails, `article_path(@article)` would throw an error. For this, the arguments `if_success_turbo_redirect_to` and `if_success_redirect_to` accept procs that are evaluated only on success. So your line would look like this `if_success_redirect_to: ->{article_path(@article)}`.
|
122
|
+
|
121
123
|
Assuming we want to build a form that works within a turbo-frame, including flash messages and redirects, we have to build all that inside a `turbo-frame`, and, within that we need a target-id, that must not be a turbo-frame. For that, there is a helper:
|
122
124
|
|
123
125
|
```haml
|
@@ -28,7 +28,7 @@
|
|
28
28
|
<% if args[:target].present? %>
|
29
29
|
<% Rails.logger.debug(" • Target #{args[:target]} found in #{args[:partial]}") %>
|
30
30
|
<% else %>
|
31
|
-
<% raise
|
31
|
+
<% raise "No target specified by arguments and no target found inside the rendered #{args[:partial].present? ? "partial: #{args[:partial]}" : "template: #{args[:template]}"}" %>
|
32
32
|
<% end %>
|
33
33
|
<% end %>
|
34
34
|
|
@@ -23,7 +23,7 @@
|
|
23
23
|
<% unless s[:target].present? %>
|
24
24
|
<% s[:target] = RenderTurboStream::Libs.fetch_arguments_from_rendered_string(html)[:target] %>
|
25
25
|
<% unless s[:target].present? %>
|
26
|
-
<% raise
|
26
|
+
<% raise "No target specified by arguments and no target found inside the rendered #{s[:partial].present? ? "partial: #{s[:partial]}" : "template: #{s[:template]}"}" %>
|
27
27
|
<% end %>
|
28
28
|
<% end %>
|
29
29
|
|
@@ -9,8 +9,8 @@ module RenderTurboStream
|
|
9
9
|
save_action,
|
10
10
|
object: nil, # object used in save_action, example: @customer
|
11
11
|
|
12
|
-
if_success_redirect_to: nil, # does a regular redirect. Works if you are inside a turbo_frame and just want to redirect inside that frame BUT CANNOT STREAM OTHERS ACTIONS ON THE SAME RESPONSE https://github.com/rails/rails/issues/48056
|
13
|
-
if_success_turbo_redirect_to: nil, # does a full page redirect (break out of all frames by turbo_power redirect)
|
12
|
+
if_success_redirect_to: nil, # does a regular redirect. Works if you are inside a turbo_frame and just want to redirect inside that frame BUT CANNOT STREAM OTHERS ACTIONS ON THE SAME RESPONSE https://github.com/rails/rails/issues/48056. Value can be given as block like "->{article_path(@article)}"
|
13
|
+
if_success_turbo_redirect_to: nil, # does a full page redirect (break out of all frames by turbo_power redirect). Value can be given as block like "->{article_path(@article)}"
|
14
14
|
|
15
15
|
target_id: nil, # IF NIL: the gem grabs inside the rendered content for turbo-frame tag or turbo-target (element from helper of this gem) tag and takes the id from there.
|
16
16
|
partial: nil, # if nil: the gem renders the default template by turbo-stream
|
@@ -82,15 +82,23 @@ module RenderTurboStream
|
|
82
82
|
Rails.logger.debug(" • Successful saved && Redirect by «turbo_redirect_to»")
|
83
83
|
Rails.logger.debug(" • Set flash[:alert] => #{flashes[:alerts]}") if flashes[:alerts].present?
|
84
84
|
Rails.logger.debug(" • Set flash[:notice] => #{flashes[:notices]}") if flashes[:notices].present?
|
85
|
+
|
86
|
+
if if_success_turbo_redirect_to.is_a?(Proc)
|
87
|
+
redirect_path = if_success_turbo_redirect_to.call
|
88
|
+
else
|
89
|
+
redirect_path = if_success_turbo_redirect_to
|
90
|
+
end
|
91
|
+
|
85
92
|
render_turbo_stream([
|
86
93
|
[
|
87
94
|
:redirect_to,
|
88
|
-
|
95
|
+
redirect_path
|
89
96
|
]
|
90
97
|
])
|
91
98
|
|
92
99
|
elsif save_action && if_success_redirect_to.present?
|
93
100
|
response.status = 303
|
101
|
+
|
94
102
|
if allow_channel
|
95
103
|
Rails.logger.debug(" • Send actions through Turbo::StreamsChannel")
|
96
104
|
c_libs = RenderTurboStream::ChannelLibs.new(response)
|
@@ -103,7 +111,11 @@ module RenderTurboStream
|
|
103
111
|
Rails.logger.debug(" • Set flash[:notice] => #{flashes[:notices]}") if flashes[:notices].present?
|
104
112
|
Rails.logger.debug(" • Could not send #{streams.length} actions => #{streams}")
|
105
113
|
end
|
106
|
-
|
114
|
+
if if_success_redirect_to.is_a?(Proc)
|
115
|
+
redirect_to if_success_redirect_to.call
|
116
|
+
else
|
117
|
+
redirect_to if_success_redirect_to
|
118
|
+
end
|
107
119
|
|
108
120
|
else
|
109
121
|
Rails.logger.debug(" • Respond by TurboStream in #{streams.length} #{'action'.pluralize(streams.length)}")
|
@@ -1,3 +1,3 @@
|
|
1
1
|
module RenderTurboStream
|
2
|
-
VERSION = "4.3.
|
3
|
-
end
|
2
|
+
VERSION = "4.3.6"
|
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.3.
|
4
|
+
version: 4.3.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- christian
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-06-
|
11
|
+
date: 2023-06-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|