faw_toast 1.3.0 → 1.4.0
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 +24 -0
- data/lib/faw_toast/toast_helper.rb +5 -0
- data/lib/faw_toast/version.rb +1 -1
- data/lib/generators/faw_toast/install/install_generator.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 314d01dd20348f62a6246f377322f8228ef2b021a9f4fc8ce499d76987a19f64
|
4
|
+
data.tar.gz: 272d6ce0491dc17f9219050a89fcb5a8209cc61394d2c86007a74a5cf0c539ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65ee75966b4fadf82dbf968d263753f105b7bdf5a1a0970496456ab8abbfbe2663ec50911aafd7afe645dd57b3e46770a687443099545bae7e2b817b00a2d962
|
7
|
+
data.tar.gz: 92ee429a17c88b3669d62e37d001f316670e81203bdff9129ae2f83eb5478795f776ed2d14679b340aa772628ff78a1832ab4066b7d789d1ca9e436f801b0a29
|
data/README.md
CHANGED
@@ -57,6 +57,8 @@ and if you are using `sprockets` include the following lines in your `config/man
|
|
57
57
|
|
58
58
|
## Usage
|
59
59
|
|
60
|
+
### Basic Usage
|
61
|
+
|
60
62
|
FawToast works with Rails flash messages. You can use it like this
|
61
63
|
|
62
64
|
```ruby
|
@@ -85,6 +87,28 @@ Turbo::StreamsChannel.broadcast_append_to(
|
|
85
87
|
)
|
86
88
|
```
|
87
89
|
|
90
|
+
### With Turbo Streams
|
91
|
+
|
92
|
+
For Turbo Streams applications, you can use the built-in `render_message` helper:
|
93
|
+
|
94
|
+
```ruby
|
95
|
+
# In your controller
|
96
|
+
def create
|
97
|
+
# Your logic here
|
98
|
+
render_message(:success, :ok, "Item was successfully created!")
|
99
|
+
end
|
100
|
+
```
|
101
|
+
|
102
|
+
The `render_message` method takes three parameters:
|
103
|
+
- `flash_type`: The type of flash message (:success, :alert, :danger, etc.)
|
104
|
+
- `status`: The HTTP status code to return (:ok, :created, etc.)
|
105
|
+
- `message`: The message to display in the toast
|
106
|
+
|
107
|
+
This helper automatically:
|
108
|
+
1. Sets the flash message
|
109
|
+
2. Renders a Turbo Stream that appends the toast to the toast container
|
110
|
+
3. Sets the appropriate HTTP status code
|
111
|
+
|
88
112
|
FawToast supports the following flash types out of the box:
|
89
113
|
- `:success` - Green border
|
90
114
|
- `:alert` - Red border
|
@@ -20,6 +20,11 @@ module FawToast
|
|
20
20
|
render_toast
|
21
21
|
end
|
22
22
|
end
|
23
|
+
|
24
|
+
def render_message(flash_type = :success, status = :ok, message = nil)
|
25
|
+
flash.now[flash_type] = message
|
26
|
+
render turbo_stream: turbo_stream.append("faw-toast-container", partial: "faw_toast/toast"), status: status
|
27
|
+
end
|
23
28
|
|
24
29
|
def toast_css_variables
|
25
30
|
# Generate a style tag with CSS variables based on configuration
|
data/lib/faw_toast/version.rb
CHANGED