render_turbo_stream 4.3.2 → 4.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9f3b950cec2aadef6d1acea45b6d15e0bb10a2b6c47adaf49bad4e4ed909ffba
4
- data.tar.gz: a1ec0bf02392b4cebf5416aed80723f9a2d2c34f2996262bc451733dc56c9442
3
+ metadata.gz: d66f0d9cb7dc4822dbcaf38e286b855386e8637b07a922db1714b14ab63d0c6d
4
+ data.tar.gz: 017a6047f0c07a1f2847f7be92d810483c00690e1c31f0cb31581004d48f8f18
5
5
  SHA512:
6
- metadata.gz: f9ca2767f8ac34efd99bdb31f3abb5bc5654c0d130482d3a999f815b435a08cb3eecce4eec88272919feefc0e4e5584fa7a61970b3e9535ba2550945c10bac9a
7
- data.tar.gz: 97b79f7d79095632faa08dc7838e959188e3342ce9eb62168e0a2e2cacac1de67eb6279dd2fecb31b289aa4d6a84799f3a129c3ee6a7692db4c6a16f4e8ee9c5
6
+ metadata.gz: a3853c69389798f965cb41e629fb208e6926b3a4ce2d5f0f925554cec41d470fa5963ad6d88dd1712e787be3db683f1e61cce7411c78f8dda574069f7d5a9b55
7
+ data.tar.gz: 78719ff0ab9c7299639161ba2a966786d18dc79b9f401e8112b58656f2270436c51119c3eb6297f73c4df4e40dc7843bebe4496a9a5cbcc6d187b6898fa00245
data/README.md CHANGED
@@ -31,6 +31,8 @@ gem 'render_turbo_stream'
31
31
  bundle install
32
32
  ```
33
33
 
34
+ **Include the helpers**
35
+
34
36
  ApplicationController
35
37
 
36
38
  ```ruby
@@ -40,10 +42,10 @@ include RenderTurboStream::ControllerHelpers
40
42
  Create a Initializer
41
43
 
42
44
  ```ruby
43
- ActionView::Base.send :include, RenderTurboStream::ChannelViewHelpers
45
+ ActionView::Base.send :include, RenderTurboStream::ViewHelpers
44
46
  ```
45
47
 
46
- spec/rails_helper.rb
48
+ spec/rails_helper.rb (We are using rspec instead of minitest)
47
49
 
48
50
  ```ruby
49
51
  RSpec.configure do |config|
@@ -61,6 +63,8 @@ Required Configurations for Flash Partial
61
63
  config.x.render_turbo_stream.flash_partial = 'layouts/flash'
62
64
  config.x.render_turbo_stream.flash_target_id = 'flash-box'
63
65
  config.x.render_turbo_stream.flash_turbo_action = 'prepend'
66
+
67
+ # In case of redirection a flash cannot be sent by TurboStream
64
68
  config.x.render_turbo_stream.allow_channel_to_me_for_turbo_stream_save = true
65
69
  ```
66
70
 
@@ -181,19 +185,25 @@ If an `if_success_redirect_to` argument is provided and the save action was succ
181
185
 
182
186
  **Target-ID**
183
187
 
184
- The target ID for turbo has to be safely unique, and it has to be nice, because at least during testing the developer has to deal with it. Since the default ID builder `dom_id` is too simple for this, there are some helpers. How it works is best shown by the `request-test helper target_id`:
188
+ The target ID for turbo has to be unique for sure, and it has to be nice, because, at least during testing the developer has to deal with it. Since the default ID builder dom_id is too simple for this, there are some helpers. How it works is best shown by the `request-test helper target_id`:
185
189
 
186
190
  ```ruby
187
191
  # target_id(virtual_view_path, object)
188
192
  target_id('customers/_form', Customer.new) #=> 'new-customer-form'
189
193
  target_id('customers/_form', Customer.first) #=> 'customer-1-form'
190
194
  target_id('customers/_form', nil) #=> 'customers-form'
195
+ target_id('customers/_form', 'hi-joe') #=> 'hi-joe'
191
196
  ```
192
- View-helpers, assuming we are inside `customers/_form`:
197
+
198
+ View-helper: Assuming we are inside `customers/_my_form`:
193
199
 
194
200
  ```ruby
195
- target_id #=> this checks automatically for @customer => if present => 'customer-1-form'
196
- target_id(Customer.new) #=> 'new-customer-form'
201
+ #=> Assuming controller-name "customers" and variable @customer is present
202
+ target_id
203
+ #=> 'customer-1-my-form'
204
+
205
+ target_id(Customer.new)
206
+ #=> 'new-customer-my-form'
197
207
  ```
198
208
 
199
209
  **Target-ID: Avoid the same definition in multiple places**
@@ -7,7 +7,6 @@
7
7
  <% if args.is_a?(Array) %>
8
8
 
9
9
  <% ctl = "turbo_stream.#{args.first}, #{args[1..-1].join(', ')}" %>
10
- <% Rails.logger.debug(" • render-turbo-stream => #{ctl}") %>
11
10
  <%= turbo_stream.send args.first, *(args[1..-1]) %>
12
11
 
13
12
 
@@ -26,7 +25,9 @@
26
25
 
27
26
  <% unless args[:target].present? %>
28
27
  <% args[:target] = RenderTurboStream::Libs.fetch_arguments_from_rendered_string(rendered_html)[:target] %>
29
- <% unless args[:target].present? %>
28
+ <% if args[:target].present? %>
29
+ <% Rails.logger.debug(" • Target #{args[:target]} found in #{args[:partial]}") %>
30
+ <% else %>
30
31
  <% raise 'No target specified by arguments and no target found inside the rendered partial' %>
31
32
  <% end %>
32
33
  <% end %>
@@ -38,7 +39,6 @@
38
39
 
39
40
 
40
41
  <% if args[:action].present? %>
41
- <% Rails.logger.debug(" • render-turbo-stream #{args[:action].upcase} => #{info}") %>
42
42
  <%= turbo_stream.send args[:action].to_sym, target_id do %>
43
43
 
44
44
  <%= rendered_html %>
@@ -37,6 +37,7 @@ module RenderTurboStream
37
37
  r = RenderTurboStream::Libs.fetch_arguments_from_rendered_string(rendered_html)
38
38
  target_id = r[:target_id]
39
39
  target = r[:target]
40
+ Rails.logger.debug(" • Target #{r[:target]} found in #{partial.to_s + template.to_s}")
40
41
  end
41
42
  end
42
43
 
@@ -79,6 +79,7 @@ module RenderTurboStream
79
79
  response.status = 302
80
80
  flash[:alert] = flashes[:alerts]
81
81
  flash[:notice] = flashes[:notices]
82
+ Rails.logger.debug(" • Successful saved && Redirect by «turbo_redirect_to»")
82
83
  Rails.logger.debug(" • Set flash[:alert] => #{flashes[:alerts]}") if flashes[:alerts].present?
83
84
  Rails.logger.debug(" • Set flash[:notice] => #{flashes[:notices]}") if flashes[:notices].present?
84
85
  render_turbo_stream([
@@ -91,18 +92,21 @@ module RenderTurboStream
91
92
  elsif save_action && if_success_redirect_to.present?
92
93
  response.status = 303
93
94
  if allow_channel
94
- Rails.logger.debug(" • Sent #{streams.length} actions through Turbo::StreamsChannel because allowed in configs.")
95
+ Rails.logger.debug(" • Send actions through Turbo::StreamsChannel")
95
96
  c_libs = RenderTurboStream::ChannelLibs.new(response)
96
97
  c_libs.send_actions_to_channel("authenticated-user-#{helpers.current_user.id}", streams, @render_turbo_stream_evaluate_instance_variables)
97
98
  else
98
99
  flash[:alert] = flashes[:alerts]
99
100
  flash[:notice] = flashes[:notices]
101
+ Rails.logger.debug(" • Turbo::StreamsChannel NOT ALLOWED BY CONFIGS!")
100
102
  Rails.logger.debug(" • Set flash[:alert] => #{flashes[:alerts]}") if flashes[:alerts].present?
101
103
  Rails.logger.debug(" • Set flash[:notice] => #{flashes[:notices]}") if flashes[:notices].present?
104
+ Rails.logger.debug(" • Could not send #{streams.length} actions => #{streams}")
102
105
  end
103
106
  redirect_to if_success_redirect_to
104
107
 
105
108
  else
109
+ Rails.logger.debug(" • Respond by TurboStream in #{streams.length} #{'action'.pluralize(streams.length)}")
106
110
  streams += libs.generate_action(controller_path, target_id, action, partial, (partial ? nil : action_name), locals)
107
111
  render_turbo_stream(streams)
108
112
 
@@ -114,6 +118,7 @@ module RenderTurboStream
114
118
 
115
119
  ary = []
116
120
  array.each do |pr|
121
+ cmd = nil
117
122
  if !pr.present?
118
123
  Rails.logger.warn " WARNING render_turbo_stream: Empty element inside attributes: «#{array}»"
119
124
  elsif pr.is_a?(Hash)
@@ -133,13 +138,15 @@ module RenderTurboStream
133
138
  end
134
139
  r[:type] = 'stream-partial'
135
140
 
136
- ary.push(r)
141
+ cmd = r
137
142
  elsif pr.is_a?(Array)
138
143
  raise "array has to contain at least one element: #{pr}" unless pr.first.present?
139
- ary.push(pr)
144
+ cmd = pr
140
145
  else
141
146
  raise "ERROR render_turbo_stream invalid type: Only hash or array allowed"
142
147
  end
148
+ ary.push(cmd) if cmd
149
+ Rails.logger.debug(" • Stream => #{cmd}")
143
150
  end
144
151
 
145
152
  if request.format.to_sym == :turbo_stream
@@ -1,3 +1,3 @@
1
1
  module RenderTurboStream
2
- VERSION = "4.3.2"
2
+ VERSION = "4.3.3"
3
3
  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: 4.3.2
4
+ version: 4.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - christian