rails_toastify 1.1.1 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -0
- data/README.md +51 -26
- data/app/helpers/rails_toastify_helper.rb +30 -5
- data/lib/generators/rails_toastify/install/templates/rails_toastify.rb +8 -4
- data/lib/rails_toastify/version.rb +1 -1
- data/lib/rails_toastify.rb +19 -10
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0fca6e66a1b85a3f5cd57d51355f21342bca3f64b2ddc265c5e6231992c6aaa7
|
4
|
+
data.tar.gz: a789a98299bce7cd3cc6ae983f1589dc3e0e0f983c7e7d500a191f088f82770a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91597bde294f1bd803f3aa6c4f989cb639564cb15d3835d25f70a2fbc4d4af5645c5c5c6f029331588f6c0a205c974fdf84fc69093dc22b7a1ec34ab9bb21c8d
|
7
|
+
data.tar.gz: 9b6610626c2baef2458f2153a4fb33c37e402b8cbbc380e8cef37793adf1463699b55a99412b367cd32084cb9cc0ec31d7a33cc0dfd244b95c5d0af15fe8112b
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
+
## 1.2.1
|
2
|
+
|
3
|
+
- Version stable tested and approved
|
4
|
+
- Change Changelog
|
5
|
+
- Change Readme
|
6
|
+
|
7
|
+
## 1.2.0
|
8
|
+
|
9
|
+
- Add configuration to notice type and alert type
|
10
|
+
- Fix helper and methods
|
11
|
+
|
12
|
+
## 1.1.1
|
13
|
+
|
14
|
+
- Create helper and methods
|
15
|
+
- Fix javascript
|
16
|
+
|
1
17
|
## 1.1.0
|
2
18
|
|
3
19
|
- Add others configurations (position, animation, duration, theme and type)
|
data/README.md
CHANGED
@@ -2,7 +2,9 @@
|
|
2
2
|
|
3
3
|
**Rails Toastify** allows you to easily add notifications to your app. Please CONTRIBUTE.
|
4
4
|
|
5
|
-
The **Rails Toastify** gem is completely inspired by the [React Toastify](https://fkhadra.github.io/react-toastify/introduction/) lib and is specially made for those React developers who are migrating to Rails thanks to Hotwire or for any other reason, and who love using Toasts and wanted a gem that makes it as easy as it is in React. 🎉
|
5
|
+
The **Rails Toastify** gem is completely inspired by the [React Toastify](https://fkhadra.github.io/react-toastify/introduction/) lib and is specially made for those React developers who are migrating to Rails thanks to Hotwire or for any other reason, and who love using Toasts and wanted a gem that makes it as easy as it is in React. 🎉
|
6
|
+
|
7
|
+
To see the pure html, css and javascript that originated this gem, just access this **[codepen](https://codepen.io/eltin182/pen/QWXLaWj)** link.
|
6
8
|
|
7
9
|
## Installation
|
8
10
|
|
@@ -19,11 +21,19 @@ After run:
|
|
19
21
|
rails generate rails_toastify:install
|
20
22
|
```
|
21
23
|
|
22
|
-
This will create a file *config/initializers/rails_toastify.rb* where you can define
|
24
|
+
This will create a file *config/initializers/rails_toastify.rb* where you can define what configuration you want to use:
|
23
25
|
|
24
26
|
```ruby
|
25
|
-
RailsToastify.
|
26
|
-
|
27
|
+
RailsToastify.setup do |configuration|
|
28
|
+
configuration.position = 'toast-container-top-right'
|
29
|
+
configuration.notice_animation = 'bounce' # bounce, slide, flip, zoom
|
30
|
+
configuration.alert_animation = 'slide' # bounce, slide, flip, zoom
|
31
|
+
configuration.notice_duration = 3000
|
32
|
+
configuration.alert_duration = 3000
|
33
|
+
configuration.notice_theme = 'light' # light, dark
|
34
|
+
configuration.alert_theme = 'light' # light, dark
|
35
|
+
configuration.notice_type = 'default' # default, success, warning, error, info
|
36
|
+
configuration.alert_type = 'error' # default, success, warning, error, info
|
27
37
|
end
|
28
38
|
```
|
29
39
|
|
@@ -32,39 +42,54 @@ end
|
|
32
42
|
In your *application.html.erb* add in your header:
|
33
43
|
|
34
44
|
```ruby
|
35
|
-
<%= stylesheet_link_tag 'rails_toastify', media: 'all' %>
|
36
|
-
<%= javascript_include_tag 'rails_toastify' %>
|
45
|
+
<%= stylesheet_link_tag 'rails_toastify', media: 'all', 'data-turbolinks-track': 'reload' %>
|
46
|
+
<%= javascript_include_tag 'rails_toastify', 'data-turbo-track': 'reload' %>
|
37
47
|
```
|
38
48
|
And in your body:
|
39
49
|
|
40
50
|
```html
|
41
|
-
|
42
|
-
|
43
|
-
*
|
44
|
-
|
45
|
-
In your *config/manifest.js* add:
|
46
|
-
|
47
|
-
```js
|
48
|
-
//= link rails_toastify.css
|
49
|
-
//= link rails_toastify.js
|
51
|
+
<%= rails_toastify_container %>
|
52
|
+
<%= rails_toastify_script %>
|
50
53
|
```
|
51
|
-
|
52
|
-
And call function `RailsToastify.showToast` any javascript or console:
|
54
|
+
And call function `RailsToastify.show` any javascript or console:
|
53
55
|
|
54
56
|
```ruby
|
55
|
-
RailsToastify.
|
56
|
-
RailsToastify.showToast('This is an error message!', 'error');
|
57
|
-
RailsToastify.showToast('This is an info message!', 'info');
|
58
|
-
RailsToastify.showToast('This is a warning message!', 'warning');
|
57
|
+
RailsToastify.show('This is a message!', { theme: 'light', type: 'default', animation: 'bounce', duration: 3000 });
|
59
58
|
```
|
60
59
|
|
61
|
-
To see notice in a toast add:
|
60
|
+
To see notice or alert in a toast add this in application.html.erb:
|
61
|
+
|
62
|
+
```html
|
63
|
+
<% if notice %>
|
64
|
+
<script>
|
65
|
+
RailsToastify.show('<%= notice %>',
|
66
|
+
{ theme: '<%= RailsToastify.configuration.notice_theme %>',
|
67
|
+
type: '<%= RailsToastify.configuration.notice_type %>',
|
68
|
+
animation: '<%= RailsToastify.configuration.notice_animation %>',
|
69
|
+
duration: <%= RailsToastify.configuration.notice_duration %>
|
70
|
+
})
|
71
|
+
</script>
|
72
|
+
<% end %>
|
62
73
|
|
63
|
-
|
64
|
-
|
65
|
-
|
74
|
+
<% if alert %>
|
75
|
+
<script>
|
76
|
+
RailsToastify.show('<%= alert %>',
|
77
|
+
{ theme: '<%= RailsToastify.configuration.alert_theme %>',
|
78
|
+
type: '<%= RailsToastify.configuration.alert_type %>',
|
79
|
+
animation: '<%= RailsToastify.configuration.alert_animation %>',
|
80
|
+
duration: <%= RailsToastify.configuration.alert_duration %>
|
81
|
+
})
|
82
|
+
</script>
|
66
83
|
<% end %>
|
67
84
|
```
|
85
|
+
** Note that toast can be configured for either notice type or alert type. Both types or just one of the types can be used.
|
86
|
+
|
87
|
+
## Next steps
|
88
|
+
|
89
|
+
- Add tests
|
90
|
+
- Add others positions (left, center, bottom)
|
91
|
+
- Add fade in and fade out animation
|
92
|
+
- In addition to the colors, allow the user to choose any color for the progress bar
|
68
93
|
|
69
94
|
## Requirements
|
70
95
|
|
@@ -79,4 +104,4 @@ Fork, fix, then send a pull request. Bug reports and pull requests are welcome o
|
|
79
104
|
|
80
105
|
This gem is available as open-source under the terms of The MIT License (MIT).
|
81
106
|
|
82
|
-
Copyright (c) 2024 **Elton Santos**. See **MIT-LICENSE** for further details.
|
107
|
+
Copyright (c) 2024 **[Elton Santos](https://eltonmelosantos.com.br)**. See **MIT-LICENSE** for further details and see **CHANGELOG** to see what was changed.
|
@@ -19,11 +19,36 @@ module RailsToastifyHelper
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
def rails_toastify_messages
|
23
|
+
output = []
|
24
|
+
if flash[:notice]
|
25
|
+
output << javascript_tag do
|
26
|
+
<<-JS.html_safe
|
27
|
+
document.addEventListener('DOMContentLoaded', function() {
|
28
|
+
RailsToastify.show(#{flash[:notice].to_json}, {
|
29
|
+
animation: '#{RailsToastify.configuration.notice_animation}',
|
30
|
+
duration: #{RailsToastify.configuration.notice_duration},
|
31
|
+
theme: '#{RailsToastify.configuration.notice_theme}',
|
32
|
+
type: '#{RailsToastify.configuration.notice_type}'
|
33
|
+
});
|
34
|
+
});
|
35
|
+
JS
|
36
|
+
end
|
37
|
+
end
|
38
|
+
if flash[:alert]
|
39
|
+
output << javascript_tag do
|
40
|
+
<<-JS.html_safe
|
41
|
+
document.addEventListener('DOMContentLoaded', function() {
|
42
|
+
RailsToastify.show(#{flash[:alert].to_json}, {
|
43
|
+
animation: '#{RailsToastify.configuration.alert_animation}',
|
44
|
+
duration: #{RailsToastify.configuration.alert_duration},
|
45
|
+
theme: '#{RailsToastify.configuration.alert_theme}',
|
46
|
+
type: '#{RailsToastify.configuration.alert_type}'
|
47
|
+
});
|
48
|
+
});
|
49
|
+
JS
|
50
|
+
end
|
27
51
|
end
|
52
|
+
safe_join(output)
|
28
53
|
end
|
29
54
|
end
|
@@ -1,7 +1,11 @@
|
|
1
1
|
RailsToastify.setup do |configuration|
|
2
2
|
configuration.position = 'toast-container-top-right'
|
3
|
-
configuration.
|
4
|
-
configuration.
|
5
|
-
configuration.
|
6
|
-
configuration.
|
3
|
+
configuration.notice_animation = 'bounce' # bounce, slide, flip, zoom
|
4
|
+
configuration.alert_animation = 'slide' # bounce, slide, flip, zoom
|
5
|
+
configuration.notice_duration = 3000
|
6
|
+
configuration.alert_duration = 3000
|
7
|
+
configuration.notice_theme = 'light' # light, dark
|
8
|
+
configuration.alert_theme = 'light' # light, dark
|
9
|
+
configuration.notice_type = 'default' # default, success, warning, error, info
|
10
|
+
configuration.alert_type = 'error' # default, success, warning, error, info
|
7
11
|
end
|
data/lib/rails_toastify.rb
CHANGED
@@ -14,24 +14,33 @@ module RailsToastify
|
|
14
14
|
end
|
15
15
|
|
16
16
|
class Configuration
|
17
|
-
attr_accessor :position, :
|
17
|
+
attr_accessor :position, :notice_animation, :alert_animation, :notice_duration, :alert_duration,
|
18
|
+
:notice_theme, :alert_theme, :notice_type, :alert_type
|
18
19
|
|
19
20
|
def initialize
|
20
21
|
@position = 'toast-container-top-right'
|
21
|
-
@
|
22
|
-
@
|
23
|
-
@
|
24
|
-
@
|
22
|
+
@notice_animation = 'bounce'
|
23
|
+
@alert_animation = 'zoom'
|
24
|
+
@notice_duration = 3000
|
25
|
+
@alert_duration = 3000
|
26
|
+
@notice_theme = 'light'
|
27
|
+
@alert_theme = 'light'
|
28
|
+
@notice_type = 'default'
|
29
|
+
@alert_type = 'error'
|
25
30
|
end
|
26
31
|
|
27
32
|
def to_h
|
28
33
|
{
|
29
34
|
position: @position,
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
+
notice_animation: @notice_animation,
|
36
|
+
alert_animation: @alert_animation,
|
37
|
+
notice_duration: @notice_duration,
|
38
|
+
alert_duration: @alert_duration,
|
39
|
+
notice_theme: @notice_theme,
|
40
|
+
alert_theme: @alert_theme,
|
41
|
+
notice_type: @notice_type,
|
42
|
+
alert_type: @alert_type
|
43
|
+
}
|
35
44
|
end
|
36
45
|
end
|
37
46
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_toastify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elton Santos
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-10-
|
11
|
+
date: 2024-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: "\U0001F389 Rails Toastify allows you to add notifications to your app
|
14
14
|
with ease. Pay Attention: this gem still is in development. Please CONTRIBUTE"
|