render_turbo_stream 4.0.2 → 4.0.4

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: 35750e37d2f65c71588b62ebcd0b7986d0e0012bd8674808dd0149f81b5ee967
4
- data.tar.gz: 3937766529f3c5418b29895196c5a8acbb1bfeecf0e6464faf7c310d1a5ac097
3
+ metadata.gz: b5298cf405518f297f86cdd2581e39d618e3f750046335d425d5187035352380
4
+ data.tar.gz: 2cd649610255db9ca104884a472521f19af864f3f4f14eae5a2f55628f8b94ea
5
5
  SHA512:
6
- metadata.gz: c0cd96285c1d01d203b5afd33094f4be26606c40e70bab2161a36202219f713f273ae97534dc35bf722b5fe7091e034b68028c0f2f9513e20b3346d45c3f1b67
7
- data.tar.gz: ebdbca94432c7e14d01e93729e8d9361d5ffacba0ea90b20148d22882e2e7bd248dda610d8a840db6cfecdddffbe94eaa139f7527e432079fc8231525a709541
6
+ metadata.gz: 6a26003bfecef2adfd2b5cf263b06ce0106601e4c9893d25d3ab28d004ed7422324107c3d2f318047bb8b5b52a69e8887a36399a8bcec02761292480042b9eeb
7
+ data.tar.gz: 79810dadb98ec80ba893744767c7000b14f7bb98652c052d9ccfe8ee807ba17fc87045015c451521223aaebd51f924deef49e18546a6c04e11d143edaf2a3c36
data/README.md CHANGED
@@ -8,8 +8,6 @@ Defining templates like `(create|update).turbo_stream.haml` is a heavy mix of lo
8
8
 
9
9
  For `:replace` actions, responses must be wrapped inside a `turbo_frame_tag` with a matching `target_id`. The gem will regex the content and wrap it by a `turbo_frame_tag` if necessary but not present. This way the matching `target_id` is only defined in one place. This check only happens on the first call after restarting the application in production and on every call if precompile assets is set to true in configs.
10
10
 
11
- If the turbo stream action is `:replace' and the content is not wrapped by `turbo_frame_tag', the gem will wrap it. So the partial content is checked by regex. This check only happens on the first call after restarting the application in production and on every call if precompile assets is set to true in configs.
12
-
13
11
  There are many different ways to handle **redirects** since turbo. Some details are handled here.
14
12
 
15
13
  Execute [turbo_power](https://github.com/marcoroth/turbo_power) commands such as adding a css class to an html element, can be sent directly from the controller.
@@ -13,13 +13,16 @@
13
13
 
14
14
  <% else %>
15
15
  <% ctl = { partial: args[:partial], target_id: args[:target_id], action: args[:action] } %>
16
+
17
+ <% target_id = RenderTurboStream::Libs.target_to_target_id(args[:target]) %>
18
+
16
19
  <% info = { target_id: args[:target_id], partial: args[:partial], locals: args[:locals] } %>
17
20
 
18
21
 
19
22
 
20
23
  <% if args[:action].present? %>
21
24
  <% Rails.logger.debug(" • render-turbo-stream #{args[:action].upcase} => #{info}") %>
22
- <%= turbo_stream.send args[:action].to_sym, RenderTurboStream::Libs.target_to_target_id(args[:target]) do %>
25
+ <%= turbo_stream.send args[:action].to_sym, target_id do %>
23
26
  <% if RenderTurboStream::CheckTemplate.new(partial: args[:partial], action: args[:action]).add_turbo_frame_tag? %>
24
27
  <%= turbo_frame_tag RenderTurboStream::Libs.target_to_target_id(args[:target]) do %>
25
28
  <%= render args[:partial], locals: args[:locals]&.symbolize_keys %>
@@ -1,8 +1,6 @@
1
1
  module RenderTurboStream
2
2
  class CheckTemplate
3
3
 
4
- AUTO_ADD_TURBO_FRAME_TAG_ON_ACTION = [:replace]
5
-
6
4
  def initialize(partial: nil, template: nil, available_instance_variables: nil, action: nil)
7
5
  if !partial && !template
8
6
  raise 'missing attribute partial xor template'
@@ -69,7 +67,8 @@ module RenderTurboStream
69
67
  end
70
68
  end
71
69
 
72
- if stack_level == 1 && AUTO_ADD_TURBO_FRAME_TAG_ON_ACTION.include?(@action.to_sym)
70
+ conf = Rails.configuration.x.render_turbo_stream.auto_wrap_for_actions
71
+ if stack_level == 1 && conf.present? && conf.include?(@action.to_sym)
73
72
  unless _code.match(/(turbo_frame_tag|turbo-frame)/)
74
73
  @result[:add_turbo_frame_tag] = true
75
74
  end
@@ -137,8 +137,8 @@ module RenderTurboStream
137
137
 
138
138
  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
139
139
 
140
- if_success: nil, # hash for a partial to render or array with actions (as array) or hashes for partials within
141
- if_error: nil, # additional partials that should be rendered if save_action failed
140
+ if_success_add: nil, # hash for a partial to render or array with actions (as array) or hashes for partials within
141
+ if_error_add: nil, # additional partials that should be rendered if save_action failed
142
142
  add: [], # additional streams
143
143
 
144
144
  if_success_notices: nil, # array of strings, override default generated flash generation in the case of success
@@ -171,8 +171,8 @@ module RenderTurboStream
171
171
  )[:turbo_actions]
172
172
 
173
173
  turbo_actions += libs.additional_actions(
174
- if_success,
175
- if_error,
174
+ if_success_add,
175
+ if_error_add,
176
176
  add
177
177
  )
178
178
 
@@ -17,8 +17,8 @@ module RenderTurboStream
17
17
  action: 'replace', # options: append, prepend
18
18
  locals: {}, # locals used by the target_id
19
19
 
20
- if_success: nil, # hash for a partial to render or array with actions (as array) or hashes for partials within
21
- if_error: nil, # additional partials that should be rendered if save_action failed
20
+ if_success_add: nil, # hash for a partial to render or array with actions (as array) or hashes for partials within
21
+ if_error_add: nil, # additional partials that should be rendered if save_action failed
22
22
  add: [], # additional streams
23
23
 
24
24
  if_success_notices: nil, # array of strings, override default generated flash generation in the case of success
@@ -55,12 +55,12 @@ module RenderTurboStream
55
55
  if_error_alerts,
56
56
  add_notices,
57
57
  add_alerts,
58
- )
58
+ )
59
59
  streams += flashes[:turbo_actions]
60
60
 
61
61
  streams += libs.additional_actions(
62
- if_success,
63
- if_error,
62
+ if_success_add,
63
+ if_error_add,
64
64
  add
65
65
  )
66
66
 
@@ -124,7 +124,11 @@ module RenderTurboStream
124
124
  elsif pr.is_a?(Hash)
125
125
  props = pr.symbolize_keys
126
126
  r = props
127
- r[:target] = RenderTurboStream::Libs.target_id_to_target(props[:target_id]) if props[:target_id].present?
127
+ if props[:target_id].present?
128
+ r[:target] = RenderTurboStream::Libs.target_id_to_target(props[:target_id])
129
+ else
130
+ r[:target] = props[:target]
131
+ end
128
132
  raise "Missing attribute :target in #{props}" if !props[:target].present?
129
133
  r.delete(:target_id)
130
134
  r[:action] = (props[:action].present? ? props[:action] : :replace)
@@ -150,7 +154,7 @@ module RenderTurboStream
150
154
 
151
155
  # renders a partial to turbo_stream
152
156
 
153
- def stream_partial( target_id, partial: nil, action: :replace, locals: {} )
157
+ def stream_partial(target_id, partial: nil, action: :replace, locals: {})
154
158
  render_turbo_stream(
155
159
  [
156
160
  {
@@ -89,9 +89,9 @@ module RenderTurboStream
89
89
  { turbo_actions: turbo_actions, alerts: alerts, notices: notices }
90
90
  end
91
91
 
92
- def additional_actions( if_success, if_error, add )
92
+ def additional_actions( if_success_add, if_error_add, add )
93
93
 
94
- (@save_action ? make_actions(if_success) : make_actions(if_error)) + make_actions(add)
94
+ (@save_action ? make_actions(if_success_add) : make_actions(if_error_add)) + make_actions(add)
95
95
 
96
96
  end
97
97
 
@@ -127,7 +127,7 @@ module RenderTurboStream
127
127
  private
128
128
 
129
129
  # streamline actions to array
130
- # valid inputs for if_success or if_error or add
130
+ # valid inputs for if_success_add or if_error_add or add
131
131
  # [:add_css_class, ...]
132
132
  # [[:add_css_class, ..], ..]
133
133
  # {target_id: '..', ..}
@@ -1,3 +1,3 @@
1
1
  module RenderTurboStream
2
- VERSION = "4.0.2"
2
+ VERSION = "4.0.4"
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.0.2
4
+ version: 4.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - christian