rails_toastify 0.1.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +25 -0
- data/MIT-LICENSE.md +5 -0
- data/README.md +54 -13
- data/app/assets/javascripts/rails_toastify.js +27 -0
- data/app/assets/stylesheets/rails_toastify.css +60 -0
- data/lib/generators/rails_toastify/install/install_generator.rb +13 -0
- data/lib/generators/rails_toastify/install/templates/rails_toastify.rb +3 -0
- data/lib/rails_toastify/engine.rb +7 -0
- data/lib/rails_toastify/version.rb +1 -1
- data/lib/rails_toastify.rb +17 -1
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a4c911f3af15f4890c1444105b9f61e171df86f803c36b673664876fd1b5df78
|
4
|
+
data.tar.gz: 925b7c0a30747f92a1e9f2bf7d1ee306a000a445e7d35722c35b35dcb79bd87a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 928bab3cac6f526bb1b5261a5fbedb31e33412e335344e60a377c6500c17c14496af4fbe85fb8fa4c8ce7856f29678bf386d38689a431a1cff318872dab7b11b
|
7
|
+
data.tar.gz: 4af1c98f67a8b37f05089c8d11060398a7a0046dcfd8c6d5d9361e93eff8a2a6c28eef410eb24247eda7f105c3683501bfc9bb63931c38c8f6ccd724c87313bf
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
## 0.1.3
|
2
|
+
|
3
|
+
- Change README
|
4
|
+
- Load configs on module RailsToastify
|
5
|
+
- Change engine to add initializer
|
6
|
+
- Add style for tailwind template
|
7
|
+
- Add generator
|
8
|
+
- Add template
|
9
|
+
|
10
|
+
## 0.1.2
|
11
|
+
|
12
|
+
- Change README
|
13
|
+
- Add CHANGELOG
|
14
|
+
- Add MIT LICENSE
|
15
|
+
- Create Engine
|
16
|
+
- Create Javascript
|
17
|
+
- Create Style
|
18
|
+
|
19
|
+
## 0.1.1
|
20
|
+
|
21
|
+
- Add basic structure
|
22
|
+
|
23
|
+
## 0.1.0
|
24
|
+
|
25
|
+
- First release
|
data/MIT-LICENSE.md
ADDED
@@ -0,0 +1,5 @@
|
|
1
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
2
|
+
|
3
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
4
|
+
|
5
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,31 +1,72 @@
|
|
1
1
|
# RailsToastify
|
2
2
|
|
3
|
-
|
3
|
+
**Rails Toastify** allows you to easily add notifications to your app. Please note: this gem is still under development. Please CONTRIBUTE.
|
4
4
|
|
5
|
-
|
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
6
|
|
7
7
|
## Installation
|
8
8
|
|
9
|
-
|
9
|
+
Add gem in your Gemfile:
|
10
|
+
```ruby
|
11
|
+
gem 'rails_toastify'
|
12
|
+
```
|
13
|
+
and run **bundle install**
|
10
14
|
|
11
|
-
|
15
|
+
After run:
|
12
16
|
|
13
|
-
|
17
|
+
```sh
|
18
|
+
rails generate rails_toastify:install
|
19
|
+
```
|
14
20
|
|
15
|
-
|
21
|
+
This will create a file *config/initializers/rails_toastify.rb* where you can define the framework you want to use:
|
16
22
|
|
17
|
-
|
23
|
+
```ruby
|
24
|
+
RailsToastify.configure do |config|
|
25
|
+
config.framework = :tailwind # or :bootstrap
|
26
|
+
end
|
27
|
+
```
|
18
28
|
|
19
29
|
## Usage
|
20
30
|
|
21
|
-
|
31
|
+
In your *application.html.erb* add:
|
22
32
|
|
23
|
-
|
33
|
+
```ruby
|
34
|
+
<%= stylesheet_link_tag 'rails_toastify', media: 'all' %>
|
35
|
+
<%= javascript_include_tag 'rails_toastify' %>
|
36
|
+
```
|
37
|
+
And:
|
24
38
|
|
25
|
-
|
39
|
+
```html
|
40
|
+
<div id="toast-container" class="toast-container"></div>
|
41
|
+
```
|
26
42
|
|
27
|
-
|
43
|
+
In your *config/manifest.js* add:
|
28
44
|
|
29
|
-
|
45
|
+
```js
|
46
|
+
//= link rails_toastify.css
|
47
|
+
//= link rails_toastify.js
|
48
|
+
```
|
30
49
|
|
31
|
-
|
50
|
+
And call function `RailsToastify.showToast` any javascript:
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
RailsToastify.showToast('This is a success message!', 'success');
|
54
|
+
RailsToastify.showToast('This is an error message!', 'error');
|
55
|
+
RailsToastify.showToast('This is an info message!', 'info');
|
56
|
+
RailsToastify.showToast('This is a warning message!', 'warning');
|
57
|
+
```
|
58
|
+
|
59
|
+
## Requirements
|
60
|
+
|
61
|
+
- Ruby >= 2.6.0 (recommended 2.7+)
|
62
|
+
- Rails >= 6.0 (compatible up to Rails 7)
|
63
|
+
|
64
|
+
## Contributing to Rails Toastify
|
65
|
+
|
66
|
+
Fork, fix, then send a pull request. Bug reports and pull requests are welcome on GitHub at **https://github.com/eltonsantos/rails_toastify**.
|
67
|
+
|
68
|
+
## Licence
|
69
|
+
|
70
|
+
This gem is available as open-source under the terms of The MIT License (MIT).
|
71
|
+
|
72
|
+
Copyright (c) 2024 **Elton Santos**. See **MIT-LICENSE** for further details.
|
@@ -0,0 +1,27 @@
|
|
1
|
+
document.addEventListener('DOMContentLoaded', () => {
|
2
|
+
window.RailsToastify = {
|
3
|
+
showToast(message, type = 'info', duration = 3000) {
|
4
|
+
const toastContainer = document.querySelector('.toast-container') || createToastContainer();
|
5
|
+
const toast = createToast(message, type);
|
6
|
+
toastContainer.appendChild(toast);
|
7
|
+
setTimeout(() => {
|
8
|
+
toast.classList.add('fade-out');
|
9
|
+
toast.addEventListener('transitionend', () => toast.remove());
|
10
|
+
}, duration);
|
11
|
+
}
|
12
|
+
};
|
13
|
+
|
14
|
+
function createToastContainer() {
|
15
|
+
const container = document.createElement('div');
|
16
|
+
container.className = 'toast-container';
|
17
|
+
document.body.appendChild(container);
|
18
|
+
return container;
|
19
|
+
}
|
20
|
+
|
21
|
+
function createToast(message, type) {
|
22
|
+
const toast = document.createElement('div');
|
23
|
+
toast.className = `toast toast--${type}`;
|
24
|
+
toast.textContent = message;
|
25
|
+
return toast;
|
26
|
+
}
|
27
|
+
});
|
@@ -0,0 +1,60 @@
|
|
1
|
+
<% if RailsToastify.configuration.framework == :bootstrap %>
|
2
|
+
.toast-container {
|
3
|
+
position: fixed;
|
4
|
+
z-index: 9999;
|
5
|
+
pointer-events: none;
|
6
|
+
top: 20px;
|
7
|
+
right: 20px;
|
8
|
+
}
|
9
|
+
|
10
|
+
.toast {
|
11
|
+
display: flex;
|
12
|
+
align-items: center;
|
13
|
+
background-color: #fff;
|
14
|
+
border-radius: 4px;
|
15
|
+
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
16
|
+
padding: 16px;
|
17
|
+
margin: 8px;
|
18
|
+
color: #333;
|
19
|
+
}
|
20
|
+
|
21
|
+
.toast--success {
|
22
|
+
border-left: 5px solid #4caf50;
|
23
|
+
}
|
24
|
+
|
25
|
+
.toast--error {
|
26
|
+
border-left: 5px solid #f44336;
|
27
|
+
}
|
28
|
+
|
29
|
+
.toast--info {
|
30
|
+
border-left: 5px solid #2196f3;
|
31
|
+
}
|
32
|
+
|
33
|
+
.toast--warning {
|
34
|
+
border-left: 5px solid #ff9800;
|
35
|
+
}
|
36
|
+
<% elsif RailsToastify.configuration.framework == :tailwind %>
|
37
|
+
.toast-container {
|
38
|
+
@apply fixed z-50 pointer-events-none top-4 right-4;
|
39
|
+
}
|
40
|
+
|
41
|
+
.toast {
|
42
|
+
@apply flex items-center bg-white rounded shadow p-4 my-2 text-gray-800;
|
43
|
+
}
|
44
|
+
|
45
|
+
.toast--success {
|
46
|
+
@apply border-l-4 border-green-500;
|
47
|
+
}
|
48
|
+
|
49
|
+
.toast--error {
|
50
|
+
@apply border-l-4 border-red-500;
|
51
|
+
}
|
52
|
+
|
53
|
+
.toast--info {
|
54
|
+
@apply border-l-4 border-blue-500;
|
55
|
+
}
|
56
|
+
|
57
|
+
.toast--warning {
|
58
|
+
@apply border-l-4 border-yellow-500;
|
59
|
+
}
|
60
|
+
<% end %>
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module RailsToastify
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
source_root File.expand_path('templates', __dir__)
|
5
|
+
|
6
|
+
desc "Create RailsToastify config"
|
7
|
+
|
8
|
+
def create_config_file
|
9
|
+
copy_file "rails_toastify.rb", "config/initializers/rails_toastify.rb"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/rails_toastify.rb
CHANGED
@@ -4,6 +4,22 @@ require_relative "rails_toastify/version"
|
|
4
4
|
require_relative "rails_toastify/engine"
|
5
5
|
|
6
6
|
module RailsToastify
|
7
|
+
class << self
|
8
|
+
attr_accessor :configuration
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.setup
|
12
|
+
self.configuration ||= Configuration.new
|
13
|
+
yield(configuration)
|
14
|
+
end
|
15
|
+
|
16
|
+
class Configuration
|
17
|
+
attr_accessor :framework
|
18
|
+
|
19
|
+
def initialize
|
20
|
+
@framework = :tailwind
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
7
24
|
class Error < StandardError; end
|
8
|
-
# Your code goes here...
|
9
25
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_toastify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elton Santos
|
@@ -18,10 +18,14 @@ executables: []
|
|
18
18
|
extensions: []
|
19
19
|
extra_rdoc_files: []
|
20
20
|
files:
|
21
|
+
- CHANGELOG.md
|
22
|
+
- MIT-LICENSE.md
|
21
23
|
- README.md
|
22
24
|
- Rakefile
|
23
25
|
- app/assets/javascripts/rails_toastify.js
|
24
26
|
- app/assets/stylesheets/rails_toastify.css
|
27
|
+
- lib/generators/rails_toastify/install/install_generator.rb
|
28
|
+
- lib/generators/rails_toastify/install/templates/rails_toastify.rb
|
25
29
|
- lib/rails_toastify.rb
|
26
30
|
- lib/rails_toastify/engine.rb
|
27
31
|
- lib/rails_toastify/version.rb
|