render_turbo_stream 4.0.4 → 4.1.0

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: b5298cf405518f297f86cdd2581e39d618e3f750046335d425d5187035352380
4
- data.tar.gz: 2cd649610255db9ca104884a472521f19af864f3f4f14eae5a2f55628f8b94ea
3
+ metadata.gz: 73c62b93b9a7cdfa27dd6c8deb1f2da481988ad5207429336b5251b84c02335c
4
+ data.tar.gz: b3504b0025f80a163bfaea60b01e5de084d2c140ab88ad7f0d0f5d4839cb6003
5
5
  SHA512:
6
- metadata.gz: 6a26003bfecef2adfd2b5cf263b06ce0106601e4c9893d25d3ab28d004ed7422324107c3d2f318047bb8b5b52a69e8887a36399a8bcec02761292480042b9eeb
7
- data.tar.gz: 79810dadb98ec80ba893744767c7000b14f7bb98652c052d9ccfe8ee807ba17fc87045015c451521223aaebd51f924deef49e18546a6c04e11d143edaf2a3c36
6
+ metadata.gz: e6f6c351f50641661a33b6e611b0bf20249663146ff43800a0cd77d68e54b27a5bf153a03b574ef06b46cfb4d0613e1430123b07c7097af8a78b37f96a9acc9a
7
+ data.tar.gz: 2d601fb99cd002a925efa4b23bfad9f27496ecf1ad8a05a8c8c1b6c99d23e89c10a738f1e409f8bf0ba438dd50a62da691587e6d6fd29e55330292d35470bbe6
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  2021 DHH annouced a great milestone in web development with [Rails 7, "Fulfilling a Vision"](https://rubyonrails.org/2021/12/15/Rails-7-fulfilling-a-vision).
4
4
 
5
- To say it up front: If you want to have all the benefits of Turbo without disturbing the handy default Rails workflow, you must use WebSockets sometimes, which are well integrated in Turbo, see [README Turbo::StreamsChannel](https://gitlab.com/sedl/renderturbostream/-/blob/main/README-channels.md). But the starting point is here. And I recommend that you download my [Quick-and-dirty test project](https://gitlab.com/sedl/renderturbostream_railsapp), set it up, see all the tests succeed, and then read through this README.
5
+ This gem has a second [README Turbo::StreamsChannel](https://gitlab.com/sedl/renderturbostream/-/blob/main/README-channels.md). Starting point is here. And I recommend that you download my [Quick-and-dirty test project](https://gitlab.com/sedl/renderturbostream_railsapp), set it up, see all the tests succeed, and then read through this README.
6
6
 
7
7
  Defining templates like `(create|update).turbo_stream.haml` is a heavy mix of logic and view. This gem separates logic and view so that `*.turbo_stream.*` templates are no longer necessary and the logic can stay on the ruby side.
8
8
 
@@ -67,15 +67,18 @@ The corresponding partials for flashes could look [like this](https://gitlab.com
67
67
  ```
68
68
  en:
69
69
  activerecord:
70
- success:
71
- successfully_created: '%<model_name>s successfully created'
72
- successfully_updated: '%<model_name>s successfully updated'
73
- errors:
74
- messages:
75
- could_not_create: '%<model_name>s could not be created'
76
- could_not_update: '%<model_name>s could not be updated'
70
+ render_turbo_stream_success:
71
+ create: '%<model_name>s successfully created'
72
+ update: '%<model_name>s successfully updated'
73
+ destroy: '%<model_name>s successfully destroyed'
74
+ render_turbo_stream_errors:
75
+ create: '%<model_name>s could not be created'
76
+ update: '%<model_name>s could not be updated'
77
+ destroy: '%<model_name>s could not be destroyed'
77
78
  ```
78
79
 
80
+ The last key (e.g. `update`) marks the controller action.
81
+
79
82
  Model name translations, see: Rails Docs.
80
83
 
81
84
  **Turbo power**
@@ -167,7 +170,7 @@ If this config is set to true, Turbo::StreamsChannel is installed and a current
167
170
 
168
171
  If an `if_success_redirect_to` argument is provided and the save action was successful, `turbo_stream_save` would send the partials by channel.
169
172
 
170
- # Testing
173
+ # Request Testing
171
174
 
172
175
  To test if the whole system works together, including javascript actions, so that finally a part reaches the surface, there is **Capybara** system testing. But it is a good practice to **break tests into smaller pieces**. So, there are helpers for **enabling the much faster request tests that are much easier to maintain**.
173
176
 
@@ -97,10 +97,10 @@ module RenderTurboStream
97
97
  c_libs = RenderTurboStream::ChannelLibs.new(response)
98
98
  c_libs.send_actions_to_channel("authenticated-user-#{helpers.current_user.id}", streams, @render_turbo_stream_evaluate_instance_variables)
99
99
  else
100
- flash[:alert] = flash_alerts
101
- flash[:notice] = flash_notices
102
- Rails.logger.debug(" • Set flash[:alert] => #{flash_alerts}") if flash_alerts.present?
103
- Rails.logger.debug(" • Set flash[:notice] => #{flash_notices}") if flash_notices.present?
100
+ flash[:alert] = flashes[:alerts]
101
+ flash[:notice] = flashes[:notices]
102
+ Rails.logger.debug(" • Set flash[:alert] => #{flashes[:alerts]}") if flashes[:alerts].present?
103
+ Rails.logger.debug(" • Set flash[:notice] => #{flashes[:notices]}") if flashes[:notices].present?
104
104
  end
105
105
  redirect_to if_success_redirect_to
106
106
 
@@ -18,22 +18,9 @@ module RenderTurboStream
18
18
  if @save_action
19
19
  notices = if if_success_notices
20
20
  if_success_notices
21
- elsif controller_action.to_sym == :create
22
- str = I18n.t(
23
- 'activerecord.success.successfully_created',
24
- default: '%<model_name>s successfully created'
25
- )
26
- [format(str, model_name: model_name)]
27
- elsif controller_action.to_sym == :update
28
- str = I18n.t(
29
- 'activerecord.success.successfully_updated',
30
- default: '%<model_name>s successfully updated'
31
- )
32
- [format(str, model_name: model_name)]
33
21
  else
34
22
  str = I18n.t(
35
- "activerecord.success.#{controller_action}",
36
- default: '%<model_name>s successfully updated'
23
+ "activerecord.render_turbo_stream_success.#{controller_action}"
37
24
  )
38
25
  [format(str, model_name: model_name)]
39
26
  end
@@ -41,22 +28,9 @@ module RenderTurboStream
41
28
  else
42
29
  alerts = if if_error_alerts
43
30
  if_error_alerts
44
- elsif controller_action.to_sym == :create
45
- str = I18n.t(
46
- 'activerecord.errors.messages.could_not_create',
47
- default: '%<model_name>s could not be created'
48
- )
49
- [format(str, model_name: model_name)]
50
- elsif controller_action.to_sym == :update
51
- str = I18n.t(
52
- 'activerecord.errors.messages.could_not_update',
53
- default: '%<model_name>s could not be updated'
54
- )
55
- [format(str, model_name: model_name)]
56
31
  else
57
32
  str = I18n.t(
58
- "activerecord.errors.messages.#{controller_action}",
59
- default: '%<model_name>s could not be updated'
33
+ "activerecord.render_turbo_stream_errors.#{controller_action}"
60
34
  )
61
35
  [format(str, model_name: model_name)]
62
36
  end
@@ -151,6 +125,9 @@ module RenderTurboStream
151
125
  if a.is_a?(Hash) && a.key?(:target_id)
152
126
  a = a.merge(target: "##{a[:target_id]}")
153
127
  a.delete(:target_id)
128
+ unless a.key?(:action)
129
+ a[:action] = :replace
130
+ end
154
131
  a
155
132
  else
156
133
  a
@@ -1,3 +1,3 @@
1
1
  module RenderTurboStream
2
- VERSION = "4.0.4"
2
+ VERSION = "4.1.0"
3
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.0.4
4
+ version: 4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - christian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-16 00:00:00.000000000 Z
11
+ date: 2023-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -24,12 +24,12 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 7.0.3
27
- description: 'It brings TurboStreams and TurboStreams::Channel together in a unified
28
- workflow with one testing strategy. It separates logic and views: All partial handling
29
- can be controlled directly from the controller. No need to write *.turbo_stream.*
30
- templates. A normal partial can be sent in any way. Execution of javascript actions
31
- can be done directly from the controller. Demo project with all this built in along
32
- with system and request tests is available.'
27
+ description: This gem brings a set of helpers that allow a unified workflow for TurboStream
28
+ and TurboStreams::Channel and a testing strategy. To avoid a heavy view and logic
29
+ mix inside *.turbo_stream.* templates, this allows to completely separate view and
30
+ logic and control all templates and partials directly from the controller. Javascript
31
+ actions can also be executed directly from the controller. A demo project with all
32
+ this built in along with system and request tests, is linked in the README.
33
33
  email:
34
34
  - christian@sedlmair.ch
35
35
  executables: []