faw_toast 1.3.0 → 1.4.1
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20b5f4ba4431cccf4fb2e389d96eb476f6bcad0e647510b7efd45c0dc6e739b6
|
4
|
+
data.tar.gz: f59a37ec861743eedfa4a7a1d6eb71f681a395345c60fc34f2ed4dfbae34c5dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 40a6bcadcc29476e6b7c3caf40f8b06e41a48c283ba6ed28e945c2923181896da92d8169d21f90ec91ac92a41ab05395f2cd4d5d420ba2a4cdb4e00381273385
|
7
|
+
data.tar.gz: 777749653a1c46b020e285cd39c25767d45a7040f52d6a02dc58bdb81a852c05cbd86d261d145aed7916ebd83a72c0c78c66970be0f09e5e9074fbaf9a3fd469
|
data/README.md
CHANGED
@@ -40,16 +40,13 @@ rails generate faw_toast:install
|
|
40
40
|
|
41
41
|
This will:
|
42
42
|
1. Create a configuration initializer at `config/initializers/faw_toast.rb`
|
43
|
-
2.
|
43
|
+
2. Include the following into your `application.html.erb`
|
44
|
+
* Add a style tag for the configurable css variables
|
45
|
+
* `<%= stylesheet_link_tag "faw_toast", "data-turbo-track": "reload" %>`
|
46
|
+
* `<%= javascript_include_tag "faw_toast", "data-turbo-track": "reload", type: "module" %>`
|
47
|
+
* Add the toast container div
|
44
48
|
|
45
|
-
|
46
|
-
|
47
|
-
For `propshaft`
|
48
|
-
```erb
|
49
|
-
<%= stylesheet_link_tag "faw_toast", "data-turbo-track": "reload" %>
|
50
|
-
<%= javascript_include_tag "faw_toast", "data-turbo-track": "reload", type: "module" %>
|
51
|
-
```
|
52
|
-
and if you are using `sprockets` include the following lines in your `config/manifest.js`
|
49
|
+
If you are using `sprockets` you may need to add the following lines to your `app/config/manifest.js`
|
53
50
|
```javascript
|
54
51
|
//= link faw_toast.js
|
55
52
|
//= link faw_toast.css
|
@@ -57,6 +54,8 @@ and if you are using `sprockets` include the following lines in your `config/man
|
|
57
54
|
|
58
55
|
## Usage
|
59
56
|
|
57
|
+
### Basic Usage
|
58
|
+
|
60
59
|
FawToast works with Rails flash messages. You can use it like this
|
61
60
|
|
62
61
|
```ruby
|
@@ -85,6 +84,28 @@ Turbo::StreamsChannel.broadcast_append_to(
|
|
85
84
|
)
|
86
85
|
```
|
87
86
|
|
87
|
+
### With Turbo Streams
|
88
|
+
|
89
|
+
For Turbo Streams applications, you can use the built-in `render_message` helper:
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
# In your controller
|
93
|
+
def create
|
94
|
+
# Your logic here
|
95
|
+
render_message(:success, :ok, "Item was successfully created!")
|
96
|
+
end
|
97
|
+
```
|
98
|
+
|
99
|
+
The `render_message` method takes three parameters:
|
100
|
+
- `flash_type`: The type of flash message (:success, :alert, :danger, etc.)
|
101
|
+
- `status`: The HTTP status code to return (:ok, :created, etc.)
|
102
|
+
- `message`: The message to display in the toast
|
103
|
+
|
104
|
+
This helper automatically:
|
105
|
+
1. Sets the flash message
|
106
|
+
2. Renders a Turbo Stream that appends the toast to the toast container
|
107
|
+
3. Sets the appropriate HTTP status code
|
108
|
+
|
88
109
|
FawToast supports the following flash types out of the box:
|
89
110
|
- `:success` - Green border
|
90
111
|
- `:alert` - Red border
|
@@ -1,6 +1,14 @@
|
|
1
|
-
<%
|
1
|
+
<% if local_assigns[:type] && local_assigns[:message] %>
|
2
2
|
<div class="faw-toast <%= flash_class(type) %>">
|
3
3
|
<%= message %>
|
4
4
|
<div class="faw-toast-progress"></div>
|
5
5
|
</div>
|
6
|
+
<% else %>
|
7
|
+
<% flash.each do |type, message| %>
|
8
|
+
<div class="faw-toast <%= flash_class(type) %>">
|
9
|
+
<%= message %>
|
10
|
+
<div class="faw-toast-progress"></div>
|
11
|
+
</div>
|
12
|
+
<% end %>
|
6
13
|
<% end %>
|
14
|
+
|
@@ -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
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faw_toast
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- alexwebgr
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-06-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|