render_turbo_stream 0.1.4 → 0.1.6

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: b06017b9c29e990812a3d57b546b9a8eeb186f5f1ae5ab8171385eadd6e2758c
4
- data.tar.gz: 6d99078f970bf560e1b972f61c608ed50fb14af4e069bcf3b3d29eef7b974f66
3
+ metadata.gz: cac97d150139e91688215e97b30997a047a8f9390b64f56f2e6f570f10d6bd87
4
+ data.tar.gz: d6c539d5bce3f59669f7254c4d24ccbc21a7a5c7580cde83966ac7b88b82fb50
5
5
  SHA512:
6
- metadata.gz: 28a103e903c7a0fcee861d08253087f0d5fd7fc685a9afc7f79c19568b8dc6941b8e9afe3794b449ad844845c169f5d504ba99009a7106c48f71f8b7cf81ff83
7
- data.tar.gz: 69623d364528f03e3a0911c6a7d122d0220ad1175ab124fd1ee7458ce49c3d4317b68263caca5e6782d227fa45568d5978dbeb7128fa4d9a2fba9afff072235f
6
+ metadata.gz: 9afe5322b9a60b20f44d2950c8f01fcf37df46a5d3b886dcce02919bdbaeb544a2bfdb2b2fa20f317a10f828b89e094449ccdafffbec24caff3cb950cd09b311
7
+ data.tar.gz: 5d3d1ddb2d36a746b6ee8a60601747205b21179b4a9cd9260f002247d320a4f36036909346a85a7cc5a9b92ec84dfc64361425f3de8e55c70e951f06344d009e
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # RenderTurboStream
2
2
 
3
+ Creating a gem currently is not possible because of [rails issue](https://github.com/rails/rails/issues/47954)
4
+
5
+ So, applying this idea is currently only possible by copy and paste a method and a view, see below.
6
+
3
7
  Working consistently by turbo_stream means: shooting a lot of partials to the html which always needs the same attributes: ID, partial and maybe some locals. This gem is a attempt to serialize that, especially for `update` and `create` action.
4
8
 
5
9
  Logic is better placed inside the controller, instead of the view and it's boring to write always the same `ifs` inside the `update.turbo_stream.haml`. So this gem holds a `.turbo_stream.html.erb` view that loops through all the partials that should be rendered.
@@ -7,23 +11,16 @@ Logic is better placed inside the controller, instead of the view and it's borin
7
11
  In 90% of cases you have just define your partials, like `_form.haml` and steer them from the controller directly, without a `.turbo_stream.haml` view.
8
12
 
9
13
  ## Installation
10
- Add this line to your application's Gemfile:
11
14
 
12
- ```ruby
13
- gem "render_turbo_stream"
14
- ```
15
+ Because of [that issue](https://github.com/rails/rails/issues/47954) appying this feature is currently only possible by copy and paste following files to your app
15
16
 
16
- And then execute:
17
- ```bash
18
- $ bundle
19
- ```
17
+ [application_controller](https://gitlab.com/sedl/renderturbostream/-/wikis/application_controller)
20
18
 
21
- Or install it yourself as:
22
- ```bash
23
- $ gem install render_turbo_stream
24
- ```
19
+ [layout/render_partials.turbo_stream.erb](https://gitlab.com/sedl/renderturbostream/-/wikis/layout/render.turbo_stream.erb)
25
20
 
26
- and follow the instructions of `turbo_power`, not rails side, but npm package and imports on javascript side, for making redirects working.
21
+ [layouts/render_redirect.turbo_stream.erb](https://gitlab.com/sedl/renderturbostream/-/wikis/layouts/render_redirect.turbo_stream.erb)
22
+
23
+ The corresponding partials for flashes could look [like this](https://gitlab.com/sedl/renderturbostream/-/wikis/flashes)
27
24
 
28
25
  ## Usage
29
26
 
@@ -34,7 +31,7 @@ and follow the instructions of `turbo_power`, not rails side, but npm package an
34
31
  render_turbo_stream(
35
32
  @customer.save,
36
33
  redirect_on_success_to: edit_customer_path(@customer),
37
- frame_id: 'customer-form-wrapper',
34
+ id: 'customer-form-wrapper',
38
35
  partial: 'customer_form',
39
36
  )
40
37
 
@@ -111,6 +108,8 @@ and a corresponding html-ID for pushing the partial to the right destination ins
111
108
 
112
109
  `config.x.render_turbo_stream.flash_id` #=> example: `flash-wrapper`
113
110
 
111
+ `config.x.render_turbo_stream.flash_action` #=> example: 'prepend'
112
+
114
113
  ## Contributing
115
114
 
116
115
  Contribution welcome.
@@ -1,3 +1,3 @@
1
1
  module RenderTurboStream
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.6"
3
3
  end
@@ -1,7 +1,12 @@
1
1
  require "render_turbo_stream/version"
2
2
  require "render_turbo_stream/railtie"
3
- require "render_turbo_stream/render_turbo_stream"
4
3
 
5
4
  module RenderTurboStream
6
5
  # Your code goes here...
6
+ def testmethod
7
+ render template: 'layouts/render', layout: false
8
+ respond_to do |format|
9
+ format.turbo_stream { render template: 'layouts/render', layout: false }
10
+ end
11
+ end
7
12
  end
@@ -1,7 +1,4 @@
1
- # desc "install the turbo_stream"
2
- # namespace :render_turbo_stream do
3
- # task install: :environment do
4
- # gem_views = Bundler.rubygems.find_name('render_turbo_stream').first.full_gem_path + '/turbo_stream'
5
- # FileUtils.copy_entry gem_views, Rails.application.root.join('app', 'turbo_stream', 'test')
6
- # end
1
+ # desc "Explaining what the task does"
2
+ # task :render_turbo_stream do
3
+ # # Task goes here
7
4
  # 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: 0.1.4
4
+ version: 0.1.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-04-14 00:00:00.000000000 Z
11
+ date: 2023-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -35,13 +35,8 @@ files:
35
35
  - Rakefile
36
36
  - lib/render_turbo_stream.rb
37
37
  - lib/render_turbo_stream/railtie.rb
38
- - lib/render_turbo_stream/render_turbo_stream.rb
39
38
  - lib/render_turbo_stream/version.rb
40
39
  - lib/tasks/render_turbo_stream_tasks.rake
41
- - views/turbo_stream_partials.html.erb
42
- - views/turbo_stream_partials.turbo_stream.html.erb
43
- - views/turbo_stream_redirect.html.erb
44
- - views/turbo_stream_redirect.turbo_stream.html.erb
45
40
  homepage: https://gitlab.com/sedl/render-turbo-stream
46
41
  licenses:
47
42
  - MIT
@@ -67,5 +62,5 @@ requirements: []
67
62
  rubygems_version: 3.4.12
68
63
  signing_key:
69
64
  specification_version: 4
70
- summary: NOT USABLE YET
65
+ summary: 'NOT USABLE AS GEM, because: https://github.com/rails/rails/issues/47954'
71
66
  test_files: []
@@ -1,144 +0,0 @@
1
- module RenderTurboStream
2
- module RenderTurboStream
3
- # extend ActiveSupport::Concern
4
- #
5
- # class_methods do
6
- # def render_turbo_stream(options = {})
7
- # "doing"
8
- # end
9
- # end
10
- def render_turbo_stream(
11
- save_action,
12
- redirect_on_success_to: nil,
13
- success_message: nil,
14
- error_message: nil,
15
- object: nil,
16
- id: nil, # if no frame-id given: no partial is rendered
17
- partial: 'form',
18
- locals: {},
19
- replace_on_success: [
20
- {
21
- id: nil,
22
- partial: 'form',
23
- locals: {}
24
- }
25
- ],
26
- replace_on_error: [
27
- {
28
- id: nil,
29
- partial: 'form',
30
- locals: {}
31
- }
32
- ],
33
- add_flash_alerts: [],
34
- add_flash_notices: []
35
- )
36
-
37
- #== flash partial
38
-
39
- @render_turbo_flash_partial = Rails.configuration.x.render_turbo_stream.flash_partial
40
- @render_turbo_flash_id = Rails.configuration.x.render_turbo_stream.flash_id
41
-
42
- #== object
43
-
44
- unless object
45
- object = eval("@#{controller_name.classify.underscore}")
46
- end
47
-
48
- #== set status
49
-
50
- if save_action == false
51
- response.status = :unprocessable_entity
52
- end
53
-
54
- #== generate message
55
-
56
- if save_action
57
- _msg = if success_message
58
- success_message
59
- elsif action_name == 'create'
60
- I18n.t('activerecord.success.successfully_created')
61
- elsif action_name == 'update'
62
- I18n.t('activerecord.success.successfully_updated')
63
- end
64
- messages = [
65
- [
66
- object.model_name.human,
67
- _msg
68
- ].join(' ')
69
- ]
70
- else
71
- _msg = if error_message
72
- error_message
73
- elsif action_name == 'create'
74
- I18n.t('activerecord.errors.messages.could_not_create')
75
- elsif action_name == 'update'
76
- I18n.t('activerecord.errors.messages.could_not_update')
77
- end
78
- messages = [
79
- [
80
- object.model_name.human,
81
- _msg
82
- ].join(' ')
83
- ]
84
- end
85
-
86
- #== replace frames
87
-
88
- replace_frames = []
89
- if id
90
- replace_frames.push({
91
- id: id,
92
- partial: partial,
93
- locals: locals
94
- })
95
- end
96
- if save_action
97
- replace_on_success.each do |f|
98
- next unless f[:id]
99
- replace_frames.push(f)
100
- end
101
- else
102
- replace_on_error.each do |f|
103
- next unless f[:id]
104
- replace_frames.push(f)
105
- end
106
- end
107
-
108
- #== render
109
-
110
- views_folder = Pathname.new(Bundler.rubygems.find_name('render_turbo_stream').first.full_gem_path).join('views')
111
- suffix = (request.format.to_sym == :html ? '.html.erb' : '.turbo_stream.html.erb')
112
-
113
- if save_action && redirect_on_success_to
114
- flash[:notice] = messages.to_a + add_flash_notices.to_a
115
- flash[:alert] = add_flash_alerts
116
- render file: views_folder.join("turbo_stream_redirect#{suffix}"),
117
- locals: {
118
- url: redirect_on_success_to
119
- },
120
- layout: false,
121
- status: 302
122
-
123
- elsif save_action
124
- flash.now[:notice] = messages.to_a + add_flash_notices.to_a
125
- flash.now[:alert] = add_flash_alerts
126
- render file: views_folder.join("turbo_stream_partials#{suffix}"),
127
- locals: {
128
- replace_frames: replace_frames
129
- },
130
- layout: false
131
- else
132
- flash.now[:alert] = messages.to_a + add_flash_alerts.to_a
133
- flash.now[:notice] = add_flash_notices
134
- render file: views_folder.join("turbo_stream_partials#{suffix}"),
135
- locals: {
136
- replace_frames: replace_frames
137
- },
138
- layout: false
139
-
140
- end
141
-
142
- end
143
- end
144
- end
File without changes
@@ -1,8 +0,0 @@
1
-
2
- <% replace_frames.each do |f| %>
3
- <%= turbo_stream.replace f[:id] do %>
4
- <% Rails.logger.debug(" RENDER TURBO STREAM ERROR => REPLACE ID: #{f[:id]}") %>
5
- <%= render f[:partial], locals: f[:locals] %>
6
- <% end %>
7
- <% end %>
8
- <%= turbo_stream.prepend @render_turbo_flash_id, partial: @render_turbo_flash_partial %>
File without changes
@@ -1,5 +0,0 @@
1
-
2
- <%= turbo_stream.redirect_to(url) %>
3
- <% if Rails.env.development? %>
4
- <% Rails.logger.debug("RENDER TURBO STREAM => REDIRECT => #{url}") %>
5
- <% end %>