render_turbo_stream 2.0.4 → 2.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: 22acef464fc16c9de34be6cd641963d7a400a310567e39a36a3f0172bd472e9d
4
- data.tar.gz: 82b659e72efec3e187032b15c111695dd7756ae6311c1f3af7970377f16288a2
3
+ metadata.gz: '087b5154db888a207a6396af1e508245b50e652513ad89be3b048f3951578398'
4
+ data.tar.gz: c54c8bd50712af73d95f75d614e46a2ff15346b50b95dfbc8a2294b341978fa2
5
5
  SHA512:
6
- metadata.gz: 567c9a920ca6e8fde6b7db21c31d5bd7474802df3b99ed9fe2bfa5b3316a68248813eef71d01125548f0deafc5786b38cb84fcbf5ddbb149a0822a7afc9c904c
7
- data.tar.gz: 58d1c1332ae8fc1bc7f149cbe8f748a1bc8a0af41ee4fd33fa6be96faf31f357416bbec75b50bd2c6f3bd4de9edb1b78409be186da12fe47125ce123cba05e2f
6
+ metadata.gz: 69fd9f948bcc9e4b2c7f4a252f0958667a9cf8876b8185f307f02325f295f4023096d4991b0fa5b1f0648fb34074d9102d5741cbed5a52c09c0bb5d5b81b5043
7
+ data.tar.gz: e2ebc9166c0ec6a5e37d7d8d574b42345fb7f1429dfed8026c295963fe47b5fd21913c048f2164897e2a974ee33e6254590814b5392728a9836ce81fc823701d
data/README.md CHANGED
@@ -1,12 +1,16 @@
1
1
  # RenderTurboStream
2
2
 
3
- Defining templates like `(create|update).turbo_stream.haml` annoyed me and I was looking for a testing strategy.
3
+ Defining templates like `(create|update).turbo_stream.haml` annoyed me.
4
4
 
5
- Working consistently with turbo_stream means shooting lots of partials from the backend to the frontend. This always requires the same attributes: the path to the partial, the html-id that turbo_stream points to, and maybe some locals. This gem serialises that: Partials can be controlled directly from the controller. It sets the status, generates a flash message, handles redirection, pushes it all to the front. Includes helpers for enabling request tests.
5
+ Turbo has seamlessly integrated Action Cable. The intention here is to bring it all together in a unified workflow with a sufficient testing strategy.
6
6
 
7
- And build it dynamically: Most [turbo_power](https://github.com/marcoroth/turbo_power) commands, such as adding a css class to an html element or pushing a state to the browser history, work directly from the controller. Since turbo allows it, custom javascript functions are also possible.
7
+ Working consistently with turbo_stream or Turbo Streams Channel means shooting a lot of partials from the backend to the frontend. This always requires the same attributes: the path to the partial, the html id that turbo_stream points to, and maybe some locals, and maybe generate a translated flash message for update or create actions. All this can be done in one step directly from the controller.
8
8
 
9
- ATTENTION: This plugin is in a early state.
9
+ There are many ways and tedious details to handle redirects since Turbo! Below described are options.
10
+
11
+ Execute [turbo_power](https://github.com/marcoroth/turbo_power) commands, such as adding a css class to an html element, pushing a state to the browser history, or running custom javascript actions through Turbo Stream (cable not yet integrated here) can be written in pure ruby code. No need for embeds like `.html.erb`.
12
+
13
+ This plugin is in a early state.
10
14
 
11
15
  An overview of how we design a rails-7 application with turbo
12
16
  is [published on dev.to](https://dev.to/chmich/rails-7-vite-wrapping-up-1pia).
@@ -15,6 +19,8 @@ A quick and dirty application with all the features, including tests, built in i
15
19
 
16
20
  Hope it can help you.
17
21
 
22
+ **Chris**
23
+
18
24
  ## Installation
19
25
 
20
26
  ```ruby
@@ -76,7 +82,7 @@ A comprehensive tutorial on turbo and how to check that it is working properly c
76
82
  **Turbo::StreamsChannel**
77
83
 
78
84
  The Rails team has seamlessly integrated `ActionCable` as `Turbo::StreamsChannel` into `Turbo Rails`. For installation along with this gem, see the [README](https://gitlab.com/sedl/renderturbostream/-/blob/main/README-cable.md).
79
- ## Usage
85
+ # Usage
80
86
 
81
87
  `turbo_stream_save` is a special method for streamlining `update` or `create` functions with `turbo_stream`. A controller action for update might look like this:
82
88
 
@@ -207,7 +213,7 @@ def update
207
213
  flashes_on_error: [] #=> array of strings
208
214
 
209
215
 
210
- ## Testing Scenarios
216
+ # Testing Scenarios
211
217
 
212
218
  For system testing there is Capybara. Its the only way to check if frontend and backend work together. But its a good practice to break tests into smaller pieces. The much larger number of tests we will write on the much faster request tests, examples here in rspec.
213
219
 
@@ -288,7 +294,7 @@ For more detailed testing of partials, there are view tests.
288
294
  Testing the plugin itself: There is a [quick-and-dirty app](https://gitlab.com/sedl/renderturbostream_railsapp) which
289
295
  includes the plugin and has tests done by rspec/request and capybara.
290
296
 
291
- ## More Configs
297
+ # More Configs
292
298
 
293
299
  On test helpers, the marker for a turbo-stream target is in most cases the id of the target element. This is true for the standard turbo-stream functions. On `turbo_power` it is the same in most cases. `RenderTurboStream::Libs.first_arg_is_html_id()` checks for which methods this is true. You can override this:
294
300
 
@@ -299,14 +305,14 @@ config.x.render_turbo_stream.first_argument_is_html_id = %[replace append prepen
299
305
  This setting is relevant for testing helpers.
300
306
 
301
307
 
302
- ## Contributing
308
+ # Contributing
303
309
 
304
310
  Contribution welcome.
305
311
 
306
- ## License
312
+ # License
307
313
 
308
314
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
309
315
 
310
- ## Thanks
316
+ # Thanks
311
317
 
312
318
  Thanks to Marco Roth for turbo_power and thanks to DHH and the rails team for taking a bold new step by creating turbo.
@@ -1,14 +1,14 @@
1
1
  module RenderTurboStream
2
2
  module TurboCableHelpers
3
3
 
4
- # def cable_partial_to_all_authenticated_users
5
- # raise "Function cable_partial_to_all_authenticated_users is "
6
- # if user_signed_in?
7
- #
8
- # end
9
- # end
4
+ def partial_to_all_authenticated_users
5
+ raise "Function partial_to_all_authenticated_users is not yet implemented"
6
+ if user_signed_in?
10
7
 
11
- def cable_partial_to_channel(action, channel, partial, id, locals: nil)
8
+ end
9
+ end
10
+
11
+ def partial_to_channel(action, channel, partial, id, locals: nil)
12
12
 
13
13
  # add headers for test
14
14
  if Rails.env.test?
@@ -45,22 +45,22 @@ module RenderTurboStream
45
45
  )
46
46
  end
47
47
 
48
- def cable_partial_to_me(partial, id, action: :replace, locals: nil)
48
+ def partial_to_me(partial, id, action: :replace, locals: nil)
49
49
  begin
50
50
  u_id = helpers.current_user&.id
51
51
  a=1
52
52
  unless u_id.present?
53
- Rails.logger.debug(' • SKIP RenderTurboStream.cable_partial_to_me because current_user is nil')
53
+ Rails.logger.debug(' • SKIP RenderTurboStream.partial_to_me because current_user is nil')
54
54
  return
55
55
  end
56
56
  rescue
57
- Rails.logger.debug(' • ERROR RenderTurboStream.cable_partial_to_me because current_user is not available')
57
+ Rails.logger.debug(' • ERROR RenderTurboStream.partial_to_me because current_user is not available')
58
58
  return
59
59
  end
60
60
 
61
- cable_partial_to_channel(
61
+ partial_to_channel(
62
62
  action,
63
- "current_user_#{helpers.current_user.id}",
63
+ "authenticated-user-#{helpers.current_user.id}",
64
64
  partial,
65
65
  id,
66
66
  locals: locals
@@ -3,19 +3,20 @@ module RenderTurboStream
3
3
 
4
4
  def cable_from_me
5
5
  if current_user
6
- turbo_stream_from "current_user_#{current_user.id}"
6
+ turbo_stream_from "authenticated-user-#{current_user.id}"
7
7
  else
8
8
  Rails.logger.debug(" • SKIP CABLE_FROM_ME because not authenticated")
9
9
  end
10
10
  end
11
11
 
12
- # def cable_from_all_authenticated_users
13
- # if user_signed_in?
14
- # turbo_stream_from "all_authenticated_users"
15
- # else
16
- # Rails.logger.debug(" • SKIP CABLE_FROM_ALL_AUTHENTICATED_USERS because not authenticated")
17
- # end
18
- # end
12
+ def cable_from_all_authenticated_users
13
+ raise "Function cable_from_all_authenticated_users is not yet implemented"
14
+ if user_signed_in?
15
+ turbo_stream_from "all-authenticated-users"
16
+ else
17
+ Rails.logger.debug(" • SKIP CABLE_FROM_ALL_AUTHENTICATED_USERS because not authenticated")
18
+ end
19
+ end
19
20
 
20
21
  def cable_from_all
21
22
  turbo_stream_from "all"
@@ -1,3 +1,3 @@
1
1
  module RenderTurboStream
2
- VERSION = "2.0.4"
2
+ VERSION = "2.1.0"
3
3
  end
@@ -162,7 +162,7 @@ module RenderTurboStream
162
162
  streams.each do |s|
163
163
  next unless s.is_a?(Hash)
164
164
  Rails.logger.debug(" • Send by Cable => «#{s}»")
165
- cable_partial_to_me(
165
+ partial_to_me(
166
166
  s[:partial],
167
167
  s[:id],
168
168
  action: flash_action,
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: 2.0.4
4
+ version: 2.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-01 00:00:00.000000000 Z
11
+ date: 2023-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -27,7 +27,7 @@ dependencies:
27
27
  description: Handles translated flash messages, sets status and renders partials via
28
28
  Turbo Stream or Turbo::StreamsChannel directly from the controller. No need to write
29
29
  *.turbo_stream.* templates. Together with the turbo_power gem or custom turbo_stream
30
- actions, you can run javascript. Redirects can now be handled easily and in multiple
30
+ actions, it can run javascript. Redirects can be handled easily and in multiple
31
31
  ways. Through request testing helpers, this allows for consistent testing strategy.
32
32
  email:
33
33
  - christian@sedlmair.ch