remote_bootstrap_modal 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 33feab5946f4216426bf5461104152fc6caff364
4
+ data.tar.gz: '0397502932e215ccc5a90598c3c9619ac5c3dd89'
5
+ SHA512:
6
+ metadata.gz: 66f5bd0f16f08da8e199ef05ff5024032e1c093c34c8b35bc0737f8d8a2b7ae490e37802d932bb1dd2ae4ccf23af5bdfb41788f416e8f7be685acab09d2a63bd
7
+ data.tar.gz: f672a062917ed95ddb525e4f6031dc1eb09b32b16ddeaa1c953e56b07ffd00ecb8efd4e1af781888f20b51953e77cb996123d4be8991cb784ca7666f1db50ed9
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2018 Glauco Custódio
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # Remote Bootstrap Modal
2
+ A tiny Rails engine that helps you loading remote links into a bootstrap modal.
3
+
4
+ It was created based on the following post: https://jtway.co/5-steps-to-add-remote-modals-to-your-rails-app-8c21213b4d0c
5
+
6
+ ## Installation
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'remote_bootstrap_modal'
11
+ ```
12
+
13
+ And then execute:
14
+ ```bash
15
+ $ bundle
16
+ ```
17
+
18
+ Or install it yourself as:
19
+ ```bash
20
+ $ gem install remote_bootstrap_modal
21
+ ```
22
+
23
+ ## Requirements
24
+
25
+ - Rails
26
+ - Bootstrap
27
+
28
+ ## Usage
29
+
30
+ 1. Make sure you have bootstrap in your application
31
+ 2. Add this gem to your Gemfile
32
+ 3. Add the following div `<div id="modal-holder"></div>` to your application layout (the modal will be rendered inside it)
33
+ 4. Add `//= require remote_bootstrap_modal/modal.js` to your `app/assets/javascripts/application.js` (after jquery)
34
+ 5. Add `include RemoteBootstrapModal::Responder` to your `ApplicationController`
35
+ 6. Set the formats you need to respond with `respond_to` (ex: `respond_to :html, :json`)
36
+ 7. Call `respond_modal_with` in your controller passing the arguments you need
37
+ 8. Pass `data: { modal: true }` to links you want to load into a modal (ex: `link_to 'Customers', customers_path, class: 'btn btn-default', data: { modal: true }`)
38
+
39
+ ## Customization
40
+
41
+ It is an engine, you can override any file to customize, you can create a `app/views/layouts/modal.html.erb` for instance with the modal layout you want.
42
+
43
+ ## License
44
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,32 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'RemoteBootstrapModal'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+ load 'rails/tasks/statistics.rake'
21
+
22
+ require 'bundler/gem_tasks'
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'test'
28
+ t.pattern = 'test/**/*_test.rb'
29
+ t.verbose = false
30
+ end
31
+
32
+ task default: :test
@@ -0,0 +1,2 @@
1
+ //= link_directory ../javascripts/remote_bootstrap_modal .js
2
+ //= link_directory ../stylesheets/remote_bootstrap_modal .css
@@ -0,0 +1,15 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file. JavaScript code in this file should be added after the last require_* statement.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require rails-ujs
14
+ //= require activestorage
15
+ //= require_tree .
@@ -0,0 +1,31 @@
1
+ $(function() {
2
+ const modal_holder_selector = '#modal-holder';
3
+ const modal_selector = '.modal';
4
+
5
+ $(document).on('click', 'a[data-modal]', function() {
6
+ const location = $(this).attr('href');
7
+ // Load modal dialog from server
8
+ $.get(
9
+ location,
10
+ data => { $(modal_holder_selector).html(data).find(modal_selector).modal() }
11
+ );
12
+ return false;
13
+ });
14
+
15
+ $(document).on('ajax:success', 'form[data-modal]', function(event){
16
+ const [data, _status, xhr] = event.detail;
17
+ const url = xhr.getResponseHeader('Location');
18
+ if (url) {
19
+ // Redirect to url
20
+ window.location = url;
21
+ } else {
22
+ // Remove old modal backdrop
23
+ $('.modal-backdrop').remove();
24
+ // Update modal content
25
+ const modal = $(data).find('body').html();
26
+ $(modal_holder_selector).html(modal).find(modal_selector).modal();
27
+ }
28
+
29
+ return false;
30
+ });
31
+ });
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,13 @@
1
+ require 'responders'
2
+
3
+ module RemoteBootstrapModal
4
+ module Responder
5
+ extend ActiveSupport::Concern
6
+
7
+ def respond_modal_with(*args, &blk)
8
+ options = args.extract_options!
9
+ options[:responder] = ModalResponder
10
+ respond_with *args, options, &blk
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ module RemoteBootstrapModal
2
+ class ApplicationController < ActionController::Base
3
+ protect_from_forgery with: :exception
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ module RemoteBootstrapModal
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module RemoteBootstrapModal
2
+ class ApplicationJob < ActiveJob::Base
3
+ end
4
+ end
@@ -0,0 +1,6 @@
1
+ module RemoteBootstrapModal
2
+ class ApplicationMailer < ActionMailer::Base
3
+ default from: 'from@example.com'
4
+ layout 'mailer'
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module RemoteBootstrapModal
2
+ class ApplicationRecord < ActiveRecord::Base
3
+ self.abstract_class = true
4
+ end
5
+ end
@@ -0,0 +1,26 @@
1
+ module RemoteBootstrapModal
2
+ class ModalResponder < ::ActionController::Responder
3
+ cattr_accessor :modal_layout
4
+ self.modal_layout = 'modal'
5
+
6
+ def render(*args)
7
+ options = args.extract_options!
8
+ if request.xhr?
9
+ options.merge! layout: modal_layout
10
+ end
11
+ controller.render *args, options
12
+ end
13
+
14
+ def default_render(*args)
15
+ render(*args)
16
+ end
17
+
18
+ def redirect_to(options)
19
+ if request.xhr?
20
+ head :ok, location: controller.url_for(options)
21
+ else
22
+ controller.redirect_to(options)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,13 @@
1
+ <div class="modal" id="mainModal" tabindex="-1" role="dialog" aria-labelledby="mainModalLabel" aria-hidden="true">
2
+ <div class="modal-dialog">
3
+ <div class="modal-content">
4
+ <div class="modal-header">
5
+ <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
6
+ <h4 class="modal-title" id="mainModalLabel">
7
+ <%= yield :title if content_for? :title %>&nbsp;
8
+ </h4>
9
+ </div>
10
+ <%= yield %>
11
+ </div>
12
+ </div>
13
+ </div>
@@ -0,0 +1,16 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Remote bootstrap modal</title>
5
+ <%= csrf_meta_tags %>
6
+ <%= csp_meta_tag %>
7
+
8
+ <%= stylesheet_link_tag "remote_bootstrap_modal/application", media: "all" %>
9
+ <%= javascript_include_tag "remote_bootstrap_modal/application" %>
10
+ </head>
11
+ <body>
12
+
13
+ <%= yield %>
14
+
15
+ </body>
16
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,2 @@
1
+ RemoteBootstrapModal::Engine.routes.draw do
2
+ end
@@ -0,0 +1,5 @@
1
+ module RemoteBootstrapModal
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace RemoteBootstrapModal
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module RemoteBootstrapModal
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,5 @@
1
+ require "remote_bootstrap_modal/engine"
2
+
3
+ module RemoteBootstrapModal
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :remote_bootstrap_modal do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: remote_bootstrap_modal
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Glauco Custódio
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-09-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: responders
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.4'
27
+ description: A tiny Rails engine that helps you loading remote links into a bootstrap
28
+ modal
29
+ email:
30
+ - glauco.custodio@gmail.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - MIT-LICENSE
36
+ - README.md
37
+ - Rakefile
38
+ - app/assets/config/remote_bootstrap_modal_manifest.js
39
+ - app/assets/javascripts/remote_bootstrap_modal/application.js
40
+ - app/assets/javascripts/remote_bootstrap_modal/modal.js
41
+ - app/assets/stylesheets/remote_bootstrap_modal/application.css
42
+ - app/controllers/concerns/remote_bootstrap_modal/responder.rb
43
+ - app/controllers/remote_bootstrap_modal/application_controller.rb
44
+ - app/helpers/remote_bootstrap_modal/application_helper.rb
45
+ - app/jobs/remote_bootstrap_modal/application_job.rb
46
+ - app/mailers/remote_bootstrap_modal/application_mailer.rb
47
+ - app/models/remote_bootstrap_modal/application_record.rb
48
+ - app/responders/remote_bootstrap_modal/modal_responder.rb
49
+ - app/views/layouts/modal.html.erb
50
+ - app/views/layouts/remote_bootstrap_modal/application.html.erb
51
+ - config/routes.rb
52
+ - lib/remote_bootstrap_modal.rb
53
+ - lib/remote_bootstrap_modal/engine.rb
54
+ - lib/remote_bootstrap_modal/version.rb
55
+ - lib/tasks/remote_bootstrap_modal_tasks.rake
56
+ homepage: http://github.com
57
+ licenses:
58
+ - MIT
59
+ metadata: {}
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 2.6.11
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: A tiny Rails engine that helps you loading remote links into a bootstrap
80
+ modal
81
+ test_files: []