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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9e701bb2d6bfd26a8e51e688c051448bb68f6b09d5b0edd60e047e1c3609000f
4
- data.tar.gz: f43ef70a87f3b816c5deeab1e9ad8969d800c3ea429c9aea797539c71bfaa788
3
+ metadata.gz: 14c283b448fbee19664a9885917462b190bd9d10e8bd45d309bdcb08272cdbf6
4
+ data.tar.gz: ce0155c49d419c38ea9f56e6b14d510bc4aeca9ed85a0b4d6150211c482ac144
5
5
  SHA512:
6
- metadata.gz: 6237ad77aea9dc367aa4a21590cbcd95b01680cef1370d6db7914d9f257499c2d13cc299f958a2f722a5db9d71969d321799a680b3530f63b686c9828d779399
7
- data.tar.gz: 2c05603ad580b88f8be579fa649a8f1a1d67c8090291a7cf5e9496844fc7b2690e94447da39e535d57cdcf7eb972304547ef40e3992cea54009cf3e08dbeaae3
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 the framework you want to use:
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.configure do |config|
26
- config.framework = :tailwind # or :bootstrap
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
- <div id="toast-container" class="toast-container"></div>
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.showToast('This is a success message!', 'success');
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
- ```ruby
64
- <%= javascript_tag do %>
65
- RailsToastify.showToast('<%= notice %>', 'success')
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 show_toast(message, options = {})
23
- javascript_tag do
24
- <<-JS.html_safe
25
- RailsToastify.show(#{message.to_json}, #{options.to_json});
26
- JS
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.animation = 'bounce'
4
- configuration.duration = 5000
5
- configuration.theme = 'light'
6
- configuration.type = 'default'
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsToastify
4
- VERSION = "1.1.1"
4
+ VERSION = "1.2.0"
5
5
  end
@@ -14,24 +14,33 @@ module RailsToastify
14
14
  end
15
15
 
16
16
  class Configuration
17
- attr_accessor :position, :animation, :duration, :theme, :type
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
- @animation = 'bounce'
22
- @duration = 5000
23
- @theme = 'light'
24
- @type = 'default'
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
- animation: @animation,
31
- duration: @duration,
32
- theme: @theme,
33
- type: @type
34
- }.to_json
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.1.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-18 00:00:00.000000000 Z
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"