faw_toast 1.1.0 → 1.2.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 +4 -4
- data/README.md +34 -4
- data/app/assets/javascripts/faw_toast.js +5 -2
- data/lib/faw_toast/version.rb +1 -1
- data/lib/generators/faw_toast/install/install_generator.rb +12 -24
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b51a2a9ed8f15f940950a4edfaabb8268ae8f422966a085ef8d49f6780d19d5e
|
4
|
+
data.tar.gz: 44371edb70e43029d9e1004bd4f3c269a7048f5178a81e17f598d8269346bf24
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e28dd393e86c36a71baeefbb41ed25753acd5f79886b08480bae06798cc3c0f994aa94cd462ff1305948b4b4cf6afa619f92d4e9e4e6dc78ce18de098d35f6c7
|
7
|
+
data.tar.gz: a6446d7cfeaf3f4027e9914df062570d95db2ff36f1fd1d32c52ed1ade48a9020ec6923b60d3b56068f415c117a66e4f3f2cb8e028547ce352bbf5c3670f0743
|
data/README.md
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# FawToast
|
2
|
-
|
3
2
|
A simple, configurable toast notification system for Rails applications. FawToast provides an easy way to display flash messages as toast notifications with minimal setup.
|
4
3
|
|
4
|
+
[](https://badge.fury.io/rb/faw_toast)
|
5
|
+
|
5
6
|
## Features
|
6
7
|
|
7
8
|
- Easy integration with Rails 7+ applications
|
@@ -40,11 +41,23 @@ rails generate faw_toast:install
|
|
40
41
|
This will:
|
41
42
|
1. Create a configuration initializer at `config/initializers/faw_toast.rb`
|
42
43
|
2. Add the toast container to your application layout
|
43
|
-
|
44
|
+
|
45
|
+
Include the css and javascript files in your `application.html.erb` layout file.
|
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`
|
53
|
+
```javascript
|
54
|
+
//= link faw_toast.js
|
55
|
+
//= link faw_toast.css
|
56
|
+
```
|
44
57
|
|
45
58
|
## Usage
|
46
59
|
|
47
|
-
FawToast works with Rails flash messages. You can use it like this
|
60
|
+
FawToast works with Rails flash messages. You can use it like this
|
48
61
|
|
49
62
|
```ruby
|
50
63
|
# In your controller
|
@@ -53,6 +66,23 @@ def create
|
|
53
66
|
flash[:success] = "Item was successfully created!"
|
54
67
|
redirect_to items_path
|
55
68
|
end
|
69
|
+
|
70
|
+
# using Turbo Streams
|
71
|
+
flash.now[flash_type] = message
|
72
|
+
render turbo_stream: turbo_stream.append("faw-toast-container", partial: "faw_toast/toast"), status: status
|
73
|
+
|
74
|
+
```
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
# In your background job or service object
|
78
|
+
flash = {}
|
79
|
+
flash[type] = message
|
80
|
+
Turbo::StreamsChannel.broadcast_append_to(
|
81
|
+
channel,
|
82
|
+
target: "faw-toast-container",
|
83
|
+
partial: "faw_toast/toast",
|
84
|
+
locals: { flash: flash }
|
85
|
+
)
|
56
86
|
```
|
57
87
|
|
58
88
|
FawToast supports the following flash types out of the box:
|
@@ -94,7 +124,7 @@ FawToast uses CSS animations to show and hide toast notifications automatically.
|
|
94
124
|
2. The flash message content
|
95
125
|
3. A progress bar that indicates how much time is left before the toast disappears
|
96
126
|
|
97
|
-
The toast appears with a slide-in animation, stays visible for the configured duration, and then slides out automatically
|
127
|
+
The toast appears with a slide-in animation, stays visible for the configured duration, and then slides out automatically
|
98
128
|
|
99
129
|
## Development
|
100
130
|
|
@@ -1,4 +1,7 @@
|
|
1
|
-
document.addEventListener('DOMContentLoaded',
|
1
|
+
document.addEventListener('DOMContentLoaded', faw_init);
|
2
|
+
document.addEventListener('turbo:load', faw_init);
|
3
|
+
|
4
|
+
function faw_init() {
|
2
5
|
function setupToastListeners() {
|
3
6
|
const toasts = document.querySelectorAll('.faw-toast');
|
4
7
|
|
@@ -26,4 +29,4 @@ document.addEventListener('DOMContentLoaded', function() {
|
|
26
29
|
childList: true,
|
27
30
|
subtree: true
|
28
31
|
});
|
29
|
-
}
|
32
|
+
}
|
data/lib/faw_toast/version.rb
CHANGED
@@ -20,6 +20,18 @@ module FawToast
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
+
def add_stylesheet_tag
|
24
|
+
inject_into_file "app/views/layouts/application.html.erb", after: "<%= stylesheet_link_tag \"application\", \"data-turbo-track\": \"reload\" %>" do
|
25
|
+
"\n <%= stylesheet_link_tag \"faw_toast\", \"data-turbo-track\": \"reload\" %>"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def add_javascript_tag
|
30
|
+
inject_into_file "app/views/layouts/application.html.erb", before: "</head>" do
|
31
|
+
" <%= javascript_include_tag \"faw_toast\", \"data-turbo-track\": \"reload\" %>\n"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
23
35
|
def add_toast_container_to_layout
|
24
36
|
inject_into_file "app/views/layouts/application.html.erb", before: "</body>" do
|
25
37
|
<<-HTML
|
@@ -27,30 +39,6 @@ module FawToast
|
|
27
39
|
HTML
|
28
40
|
end
|
29
41
|
end
|
30
|
-
|
31
|
-
def add_stylesheet_import
|
32
|
-
if File.exist?("app/assets/stylesheets/application.scss")
|
33
|
-
append_to_file "app/assets/stylesheets/application.scss" do
|
34
|
-
"\n@import \"faw_toast\";\n"
|
35
|
-
end
|
36
|
-
else
|
37
|
-
say "Please manually import the FawToast stylesheet in your application", :red
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
# def add_javascript_import
|
42
|
-
# if File.exist?("app/javascript/application.js")
|
43
|
-
# append_to_file "app/javascript/application.js" do
|
44
|
-
# "import \"faw_toast\"\n"
|
45
|
-
# end
|
46
|
-
# elsif File.exist?("app/assets/javascripts/application.js")
|
47
|
-
# append_to_file "app/assets/javascripts/application.js" do
|
48
|
-
# "//= require faw_toast\n"
|
49
|
-
# end
|
50
|
-
# else
|
51
|
-
# say "Please manually import the FawToast JavaScript in your application", :red
|
52
|
-
# end
|
53
|
-
# end
|
54
42
|
end
|
55
43
|
end
|
56
44
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faw_toast
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- alexwebgr
|
@@ -30,6 +30,20 @@ dependencies:
|
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '9.0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: sassc
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '2.4'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '2.4'
|
33
47
|
description: FawToast provides an easy way to display flash messages as toast notifications
|
34
48
|
in Rails applications
|
35
49
|
email:
|