render_turbo_stream 0.1.12 → 0.1.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -22
- data/lib/render_turbo_stream/version.rb +1 -1
- data/lib/render_turbo_stream.rb +21 -4
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c53012e599712119f8dce38d60478187e1c472e35dc72667b57ce2c4fd6ff6af
|
4
|
+
data.tar.gz: 7151a27c089c6cc312b4dcd3dd3e3b89d3fc9c775c9d484f04e82fae68d32e48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a648d90c84cc4e40e9360ce99aaf16b2e230111631ee04afacb4b0346bea3d318753655bb7af7e505c8a7d9617962cb5f64a3091ff6d4ec43fcc571506086607
|
7
|
+
data.tar.gz: ba138cb22413010ef0f60a52dedf74deaa27a2dd49dc48d4741315f449fabe34527102d4fe9cfb79c6241beedfc29b11b15776a688a876e3395b4ca42f9c7e1b
|
data/README.md
CHANGED
@@ -1,14 +1,10 @@
|
|
1
1
|
# RenderTurboStream
|
2
2
|
|
3
|
-
|
3
|
+
Defining templates like `(create|update).turbo_stream.haml` annoyed me.
|
4
4
|
|
5
|
-
|
5
|
+
Working consistently with turbo_stream means shooting lots of partials from the backend to the frontend, which always needs the same attributes: ID, partial, and maybe some locals. This gem serializes that: Partials can be controlled directly from the controller.
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
Working consistently by turbo_stream means: shooting many partials to the frontend which always needs the same attributes: ID, partial and maybe some locals. This gem serializes that: Partials can be steered directly from the controller.
|
10
|
-
|
11
|
-
Currently it is only possible by copy and paste the code, see below.
|
7
|
+
It sets the status, generates a flash message, handles redirection, pushes it all to the front and prepares a response for request-specs.
|
12
8
|
|
13
9
|
## Installation
|
14
10
|
|
@@ -20,12 +16,20 @@ gem 'render_turbo_stream'
|
|
20
16
|
bundle install
|
21
17
|
```
|
22
18
|
|
23
|
-
|
19
|
+
ApplicationController
|
24
20
|
|
25
21
|
```ruby
|
26
22
|
include RenderTurboStream
|
27
23
|
```
|
28
24
|
|
25
|
+
necessary configs for flash partials
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
config.x.render_turbo_stream.flash_partial = 'layouts/flash'
|
29
|
+
config.x.render_turbo_stream.flash_id = 'flash-box'
|
30
|
+
config.x.render_turbo_stream.flash_action = 'prepend'
|
31
|
+
```
|
32
|
+
|
29
33
|
The corresponding partials for flashes could look [like this](https://gitlab.com/sedl/renderturbostream/-/wikis/flashes)
|
30
34
|
|
31
35
|
## Usage
|
@@ -150,20 +154,6 @@ example value: `"%<model_name>s successfully created"`
|
|
150
154
|
|
151
155
|
.. and Model Name Translations
|
152
156
|
|
153
|
-
**Flash configuration**
|
154
|
-
|
155
|
-
Flash messages are pushed as arrays into `flash[:alert]`, `flash.now[:alert]`, `flash[:notice]` or `flash.now[:notice]`
|
156
|
-
|
157
|
-
The corresponding partial has to be configured by
|
158
|
-
|
159
|
-
`config.x.render_turbo_stream.flash_partial` #=> example: `layouts/flashes`
|
160
|
-
|
161
|
-
and a corresponding html-ID for pushing the partial to the right destination inside the layout
|
162
|
-
|
163
|
-
`config.x.render_turbo_stream.flash_id` #=> example: `flash-wrapper`
|
164
|
-
|
165
|
-
`config.x.render_turbo_stream.flash_action` #=> example: 'prepend'
|
166
|
-
|
167
157
|
## Contributing
|
168
158
|
|
169
159
|
Contribution welcome.
|
data/lib/render_turbo_stream.rb
CHANGED
@@ -57,21 +57,38 @@ module RenderTurboStream
|
|
57
57
|
flash_notices = if flashes_on_success.present?
|
58
58
|
flashes_on_success
|
59
59
|
elsif action_name == 'create'
|
60
|
-
|
60
|
+
str = I18n.t(
|
61
|
+
'activerecord.success.successfully_created',
|
62
|
+
default: '%<model_name>s successfully created'
|
63
|
+
)
|
64
|
+
[format(str, model_name: model_name)]
|
61
65
|
elsif action_name == 'update'
|
62
|
-
|
66
|
+
str = I18n.t(
|
67
|
+
'activerecord.success.successfully_updated',
|
68
|
+
default: '%<model_name>s successfully updated'
|
69
|
+
)
|
70
|
+
[format(str, model_name: model_name)]
|
63
71
|
end
|
64
72
|
flash_alerts = []
|
65
73
|
else
|
66
74
|
flash_alerts = if flashes_on_error.present?
|
67
75
|
flashes_on_error
|
68
76
|
elsif action_name == 'create'
|
69
|
-
|
77
|
+
str = I18n.t(
|
78
|
+
'activerecord.errors.messages.could_not_create',
|
79
|
+
default: '%<model_name>s could not be created'
|
80
|
+
)
|
81
|
+
[format(str, model_name: model_name)]
|
70
82
|
elsif action_name == 'update'
|
71
|
-
|
83
|
+
str = I18n.t(
|
84
|
+
'activerecord.errors.messages.could_not_update',
|
85
|
+
default: '%<model_name>s could not be updated'
|
86
|
+
)
|
87
|
+
[format(str, model_name: model_name)]
|
72
88
|
end
|
73
89
|
flash_notices = []
|
74
90
|
end
|
91
|
+
|
75
92
|
flash_notices += add_flash_notices
|
76
93
|
flash_alerts += add_flash_alerts
|
77
94
|
_flash_id = Rails.configuration.x.render_turbo_stream.flash_id
|
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: 0.1.
|
4
|
+
version: 0.1.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- christian
|
@@ -25,9 +25,9 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 7.0.4.3
|
27
27
|
description: 'Writing views like (create|update).turbo_stream.haml annoyed me. This
|
28
|
-
gem handles translated flash messages,
|
29
|
-
You can
|
30
|
-
redirection: turbo_power is included.'
|
28
|
+
gem handles translated flash messages, sets status, and renders turbo-stream partials.
|
29
|
+
You can control your turbo-stream partials directly from the controller. It also
|
30
|
+
handles redirection: turbo_power is included.'
|
31
31
|
email:
|
32
32
|
- christian@sedlmair.ch
|
33
33
|
executables: []
|