render_turbo_stream 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +8 -15
- data/lib/render_turbo_stream/version.rb +1 -1
- data/lib/render_turbo_stream.rb +6 -1
- data/lib/tasks/render_turbo_stream_tasks.rake +3 -6
- metadata +2 -7
- data/lib/render_turbo_stream/render_turbo_stream.rb +0 -144
- data/views/turbo_stream_partials.html.erb +0 -0
- data/views/turbo_stream_partials.turbo_stream.html.erb +0 -8
- data/views/turbo_stream_redirect.html.erb +0 -0
- data/views/turbo_stream_redirect.turbo_stream.html.erb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87f5dcd251760b5562bcabad8af261332a16f0eb8192cf9de5cab9686c6d352f
|
4
|
+
data.tar.gz: cd736406058d40145d96b8af326c89459f175ca9ce2b9e3ba84796ad7f5c3814
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '06319cc3a78c1e4548f298edfff5391a31eb4ebcf40de7f1d4430d0d12c76225fe03ac6d31b013b1068b9067af75129f74ddf1cea8b9a4401d9ca4dfa6a30b46'
|
7
|
+
data.tar.gz: b580d8267f40c277e78dc51893422b69534ec528f52689608ad42992ba296577a8a37e3bdd3e3c9194d314057e35d60d90a749607368727a5a6143e51a54b34e
|
data/README.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# RenderTurboStream
|
2
2
|
|
3
|
+
Creating a gem currently is not possible because of [hotwired issue](https://github.com/hotwired/turbo-rails/issues/455)
|
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,12 @@ 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
|
-
|
13
|
-
gem "render_turbo_stream"
|
14
|
-
```
|
15
|
+
Because of [that issue](https://github.com/hotwired/turbo-rails/issues/455) appying this feature is currently only possible by copy and paste following files to your app
|
15
16
|
|
16
|
-
|
17
|
-
```bash
|
18
|
-
$ bundle
|
19
|
-
```
|
20
|
-
|
21
|
-
Or install it yourself as:
|
22
|
-
```bash
|
23
|
-
$ gem install render_turbo_stream
|
24
|
-
```
|
17
|
+
[application_controller](https://gitlab.com/sedl/renderturbostream/-/wikis/application_controller)
|
25
18
|
|
26
|
-
|
19
|
+
[layout/render.turbo_stream.erb](https://gitlab.com/sedl/renderturbostream/-/wikis/layout/render.turbo_stream.erb)
|
27
20
|
|
28
21
|
## Usage
|
29
22
|
|
@@ -34,7 +27,7 @@ and follow the instructions of `turbo_power`, not rails side, but npm package an
|
|
34
27
|
render_turbo_stream(
|
35
28
|
@customer.save,
|
36
29
|
redirect_on_success_to: edit_customer_path(@customer),
|
37
|
-
|
30
|
+
id: 'customer-form-wrapper',
|
38
31
|
partial: 'customer_form',
|
39
32
|
)
|
40
33
|
|
data/lib/render_turbo_stream.rb
CHANGED
@@ -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 "
|
2
|
-
#
|
3
|
-
#
|
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
|
+
version: 0.1.5
|
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-
|
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
|
@@ -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
|