rails_toastify 1.1.1 → 1.2.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 +40 -24
- 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: 14c283b448fbee19664a9885917462b190bd9d10e8bd45d309bdcb08272cdbf6
|
4
|
+
data.tar.gz: ce0155c49d419c38ea9f56e6b14d510bc4aeca9ed85a0b4d6150211c482ac144
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ae720760510b4a59fd7c4d2af584ad914717db9c3274732d1c884dd4c3f55683cb525b9068d5b05768938b619d18e04728ac6a80c34b09fe58a64a5a4a00341
|
7
|
+
data.tar.gz: 49a0a1a84fbf79cb791c5dc1c505956f1d7eedda26b62fb8ac416ee0e3c0e6b7f079bda4fb335e50a901bad7afb8832963b14fff9893db60444c5815ea5b3ac2
|
data/README.md
CHANGED
@@ -19,11 +19,19 @@ After run:
|
|
19
19
|
rails generate rails_toastify:install
|
20
20
|
```
|
21
21
|
|
22
|
-
This will create a file *config/initializers/rails_toastify.rb* where you can define
|
22
|
+
This will create a file *config/initializers/rails_toastify.rb* where you can define what configuration you want to use:
|
23
23
|
|
24
24
|
```ruby
|
25
|
-
RailsToastify.
|
26
|
-
|
25
|
+
RailsToastify.setup do |configuration|
|
26
|
+
configuration.position = 'toast-container-top-right'
|
27
|
+
configuration.notice_animation = 'bounce' # bounce, slide, flip, zoom
|
28
|
+
configuration.alert_animation = 'slide' # bounce, slide, flip, zoom
|
29
|
+
configuration.notice_duration = 3000
|
30
|
+
configuration.alert_duration = 3000
|
31
|
+
configuration.notice_theme = 'light' # light, dark
|
32
|
+
configuration.alert_theme = 'light' # light, dark
|
33
|
+
configuration.notice_type = 'default' # default, success, warning, error, info
|
34
|
+
configuration.alert_type = 'error' # default, success, warning, error, info
|
27
35
|
end
|
28
36
|
```
|
29
37
|
|
@@ -32,39 +40,47 @@ end
|
|
32
40
|
In your *application.html.erb* add in your header:
|
33
41
|
|
34
42
|
```ruby
|
35
|
-
<%= stylesheet_link_tag 'rails_toastify', media: 'all' %>
|
36
|
-
<%= javascript_include_tag 'rails_toastify' %>
|
43
|
+
<%= stylesheet_link_tag 'rails_toastify', media: 'all', 'data-turbolinks-track': 'reload' %>
|
44
|
+
<%= javascript_include_tag 'rails_toastify', 'data-turbo-track': 'reload' %>
|
37
45
|
```
|
38
46
|
And in your body:
|
39
47
|
|
40
48
|
```html
|
41
|
-
|
49
|
+
<%= rails_toastify_container %>
|
50
|
+
<%= rails_toastify_script %>
|
42
51
|
```
|
43
|
-
|
44
|
-
|
45
|
-
In your *config/manifest.js* add:
|
46
|
-
|
47
|
-
```js
|
48
|
-
//= link rails_toastify.css
|
49
|
-
//= link rails_toastify.js
|
50
|
-
```
|
51
|
-
|
52
|
-
And call function `RailsToastify.showToast` any javascript or console:
|
52
|
+
And call function `RailsToastify.show` any javascript or console:
|
53
53
|
|
54
54
|
```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');
|
55
|
+
RailsToastify.show('This is a message!', { theme: 'light', type: 'default', animation: 'bounce', duration: 3000 });
|
59
56
|
```
|
60
57
|
|
61
|
-
To see notice in a toast add:
|
58
|
+
To see notice or alert in a toast add this in application.html.erb:
|
59
|
+
|
60
|
+
```html
|
61
|
+
<% if notice %>
|
62
|
+
<script>
|
63
|
+
RailsToastify.show('<%= notice %>',
|
64
|
+
{ theme: '<%= RailsToastify.configuration.notice_theme %>',
|
65
|
+
type: '<%= RailsToastify.configuration.notice_type %>',
|
66
|
+
animation: '<%= RailsToastify.configuration.notice_animation %>',
|
67
|
+
duration: <%= RailsToastify.configuration.notice_duration %>
|
68
|
+
})
|
69
|
+
</script>
|
70
|
+
<% end %>
|
62
71
|
|
63
|
-
|
64
|
-
|
65
|
-
|
72
|
+
<% if alert %>
|
73
|
+
<script>
|
74
|
+
RailsToastify.show('<%= alert %>',
|
75
|
+
{ theme: '<%= RailsToastify.configuration.alert_theme %>',
|
76
|
+
type: '<%= RailsToastify.configuration.alert_type %>',
|
77
|
+
animation: '<%= RailsToastify.configuration.alert_animation %>',
|
78
|
+
duration: <%= RailsToastify.configuration.alert_duration %>
|
79
|
+
})
|
80
|
+
</script>
|
66
81
|
<% end %>
|
67
82
|
```
|
83
|
+
** Note that toast can be configured for either notice type or alert type. Both types or just one of the types can be used.
|
68
84
|
|
69
85
|
## Requirements
|
70
86
|
|
@@ -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.0
|
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"
|