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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4facfb08cf16ff46f7bb4d9052e9b52a8f331c51b05579ce85eb7faec0758ffc
4
- data.tar.gz: 32b3aacc1d3f4cef8d7051193efcba1aa372548cb7172f3009e58674cc653b79
3
+ metadata.gz: a4c911f3af15f4890c1444105b9f61e171df86f803c36b673664876fd1b5df78
4
+ data.tar.gz: 925b7c0a30747f92a1e9f2bf7d1ee306a000a445e7d35722c35b35dcb79bd87a
5
5
  SHA512:
6
- metadata.gz: dd34bf182256c88b3e7b9f4738e70d9867661620e346b24144230d4f231afe7b24d74a12779f53b33da93f20de78fac23d7c67aea18a69ddc5917c9b9c8a7de2
7
- data.tar.gz: 81720cc49549376ba3a4841f49ff94d391826ea367cdbd019b62b4e3f69881b78ac33d5d2f3d1b12ccb09b8d67d993686e2e45045cf0dd89f55549ed36f7bc15
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
- TODO: Delete this and the text below, and describe your gem
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
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rails_toastify`. To experiment with that code, run `bin/console` for an interactive prompt.
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
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
9
+ Add gem in your Gemfile:
10
+ ```ruby
11
+ gem 'rails_toastify'
12
+ ```
13
+ and run **bundle install**
10
14
 
11
- Install the gem and add to the application's Gemfile by executing:
15
+ After run:
12
16
 
13
- $ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
17
+ ```sh
18
+ rails generate rails_toastify:install
19
+ ```
14
20
 
15
- If bundler is not being used to manage dependencies, install the gem by executing:
21
+ This will create a file *config/initializers/rails_toastify.rb* where you can define the framework you want to use:
16
22
 
17
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
23
+ ```ruby
24
+ RailsToastify.configure do |config|
25
+ config.framework = :tailwind # or :bootstrap
26
+ end
27
+ ```
18
28
 
19
29
  ## Usage
20
30
 
21
- TODO: Write usage instructions here
31
+ In your *application.html.erb* add:
22
32
 
23
- ## Development
33
+ ```ruby
34
+ <%= stylesheet_link_tag 'rails_toastify', media: 'all' %>
35
+ <%= javascript_include_tag 'rails_toastify' %>
36
+ ```
37
+ And:
24
38
 
25
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
39
+ ```html
40
+ <div id="toast-container" class="toast-container"></div>
41
+ ```
26
42
 
27
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
43
+ In your *config/manifest.js* add:
28
44
 
29
- ## Contributing
45
+ ```js
46
+ //= link rails_toastify.css
47
+ //= link rails_toastify.js
48
+ ```
30
49
 
31
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rails_toastify.
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
@@ -0,0 +1,3 @@
1
+ RailsToastify.setup do |config|
2
+ config.framework = :tailwind #or :bootstrap
3
+ end
@@ -0,0 +1,7 @@
1
+ module RailsToastify
2
+ class Engine < ::Rails::Engine
3
+ initializer 'rails_toastify.assets.precompile' do |app|
4
+ app.config.assets.precompile += %w(rails_toastify.js rails_toastify.css)
5
+ end
6
+ end
7
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsToastify
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.3"
5
5
  end
@@ -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.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