modal-responder-rails 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/CHANGELOG.md +10 -0
- data/Dockerfile +37 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +100 -0
- data/Rakefile +2 -0
- data/app/views/layouts/_modal_bootstrap_3.html.erb +16 -0
- data/app/views/layouts/_modal_bootstrap_4.html.erb +16 -0
- data/app/views/layouts/modal.html.erb +1 -0
- data/lib/modal-responder-rails.rb +23 -0
- data/lib/modal-responder-rails/controller.rb +11 -0
- data/lib/modal-responder-rails/modal_responder.rb +28 -0
- data/lib/modal-responder-rails/version.rb +5 -0
- data/make_new_release.sh +38 -0
- data/modal-responder-rails.gemspec +29 -0
- data/vendor/assets/javascripts/modal-responder.js +24 -0
- metadata +126 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7d16a03d6a8fa368a92bdae0db89e0ba418a81c6
|
4
|
+
data.tar.gz: 06f51ce292630c580201da0d36578be18c764150
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 88cf0e0a53d29d64ac2fa348e77c4320359516b88a5f96d3d94b9fc3f49b5c3320a86dda0e35b2d0e8685d38d61a0bc6d3b45ff972fc1a2a23afaa883d04e53f
|
7
|
+
data.tar.gz: 2f08191693e2bc9fd16d9ed288a634233243fe4f85dbe3658b361e66cc5e0d17ce70f35c55a2ff62c0bf257f4fe800dc4bf73d460350d118735a0a12e0fc0f73
|
data/.gitignore
ADDED
data/CHANGELOG.md
ADDED
data/Dockerfile
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# How to use it
|
2
|
+
# =============
|
3
|
+
#
|
4
|
+
# Visit http://blog.zedroot.org/using-docker-to-maintain-a-ruby-gem/
|
5
|
+
|
6
|
+
# ~~~~ Image base ~~~~
|
7
|
+
# Base image with the latest Ruby only
|
8
|
+
FROM ruby:2.3.0-slim
|
9
|
+
MAINTAINER Guillaume Hain zedtux@zedroot.org
|
10
|
+
|
11
|
+
|
12
|
+
# ~~~~ Set up the environment ~~~~
|
13
|
+
ENV DEBIAN_FRONTEND noninteractive
|
14
|
+
|
15
|
+
RUN mkdir -p /gem/
|
16
|
+
WORKDIR /gem/
|
17
|
+
ADD . /gem/
|
18
|
+
|
19
|
+
# ~~~~ OS Maintenance & Rails Preparation ~~~~
|
20
|
+
# Rubygems and Bundler
|
21
|
+
RUN apt-get update && \
|
22
|
+
apt-get install -y git build-essential unzip && \
|
23
|
+
touch ~/.gemrc && \
|
24
|
+
echo "gem: --no-ri --no-rdoc" >> ~/.gemrc && \
|
25
|
+
gem install rubygems-update && \
|
26
|
+
update_rubygems && \
|
27
|
+
gem install bundler && \
|
28
|
+
bundle install && \
|
29
|
+
apt-get remove --purge -y build-essential && \
|
30
|
+
apt-get autoclean -y && \
|
31
|
+
apt-get clean
|
32
|
+
|
33
|
+
# Import the gem source code
|
34
|
+
VOLUME .:/gem/
|
35
|
+
|
36
|
+
ENTRYPOINT ["bundle", "exec"]
|
37
|
+
CMD ["rake", "-T"]
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Guillaume Hain
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
# Modal Responder for Rails
|
2
|
+
|
3
|
+
This gem ease the use of modal in your Rails application thanks to a Responder.
|
4
|
+
This code is built based on [Dmitriy Dudkin](https://github.com/tmwh)'s
|
5
|
+
[article](http://www.jetthoughts.com/blog/tech/2014/08/27/5-steps-to-add-remote-modals-to-your-rails-app.html)
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'modal-responder-rails'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install modal-responder-rails
|
22
|
+
|
23
|
+
Add the JavaScript to your `app/assets/javascripts/application.js`:
|
24
|
+
|
25
|
+
```javascript
|
26
|
+
//= require modal-responder
|
27
|
+
```
|
28
|
+
|
29
|
+
Add the modal container to your layout file:
|
30
|
+
|
31
|
+
```html
|
32
|
+
<html>
|
33
|
+
<head>...</head>
|
34
|
+
<body>
|
35
|
+
...
|
36
|
+
<div id="modal-holder"></div>
|
37
|
+
</body>
|
38
|
+
</html>
|
39
|
+
```
|
40
|
+
|
41
|
+
By default, this gem is building the modal for Bootstrap 4 but it also
|
42
|
+
supports Bootstrap 3.
|
43
|
+
You can configure this by creating the new file
|
44
|
+
`config/initializers/modal_responder.rb` with the following:
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
ModalResponder.configure do |config|
|
48
|
+
config.bootstrap = 3
|
49
|
+
end
|
50
|
+
```
|
51
|
+
|
52
|
+
## Usage
|
53
|
+
|
54
|
+
Add `data: { modal: true }` to the link opening the modal:
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
<%= link_to 'Create category', new_category_path, data: { modal: true } %>
|
58
|
+
```
|
59
|
+
|
60
|
+
In the controller generating the modal content, set the `resond_to` format to
|
61
|
+
`:json` and in the action uses the `respond_modal_with` helper:
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
class CategoriesController < ApplicationController
|
65
|
+
respond_to :html, :json
|
66
|
+
|
67
|
+
def show
|
68
|
+
@category = Category.first
|
69
|
+
respond_modal_with @category
|
70
|
+
end
|
71
|
+
end
|
72
|
+
```
|
73
|
+
|
74
|
+
Finally, in the `app/views/categories/show.html.erb` file set the modal title,
|
75
|
+
body and footer:
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
<%= content_for :title, @category.name %>
|
79
|
+
|
80
|
+
<div class="modal-body">
|
81
|
+
<%# Your code here ... %>
|
82
|
+
</div>
|
83
|
+
<div class="modal-footer">
|
84
|
+
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
|
85
|
+
<button type="button" class="btn btn-primary">Save changes</button>
|
86
|
+
</div>
|
87
|
+
```
|
88
|
+
|
89
|
+
## Contributing
|
90
|
+
|
91
|
+
1. Fork it
|
92
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
93
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
94
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
95
|
+
5. Create new Pull Request
|
96
|
+
|
97
|
+
## License
|
98
|
+
|
99
|
+
The gem is available as open source under the terms of the
|
100
|
+
[MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
<div class="modal fade" id="mainModal" tabindex="-1" role="dialog">
|
2
|
+
<div class="modal-dialog" role="document">
|
3
|
+
<div class="modal-content">
|
4
|
+
<div class="modal-header">
|
5
|
+
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
6
|
+
<span aria-hidden="true">×</span>
|
7
|
+
</button>
|
8
|
+
<h4 class="modal-title">
|
9
|
+
<%= yield :title if content_for? :title %>
|
10
|
+
</h4>
|
11
|
+
</div>
|
12
|
+
|
13
|
+
<%= yield %>
|
14
|
+
</div>
|
15
|
+
</div>
|
16
|
+
</div>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<div class="modal fade" id="mainModal">
|
2
|
+
<div class="modal-dialog" role="document">
|
3
|
+
<div class="modal-content">
|
4
|
+
<div class="modal-header">
|
5
|
+
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
6
|
+
<span aria-hidden="true">×</span>
|
7
|
+
</button>
|
8
|
+
<h4 class="modal-title">
|
9
|
+
<%= yield :title if content_for? :title %>
|
10
|
+
</h4>
|
11
|
+
</div>
|
12
|
+
|
13
|
+
<%= yield %>
|
14
|
+
</div>
|
15
|
+
</div>
|
16
|
+
</div>
|
@@ -0,0 +1 @@
|
|
1
|
+
<% render partial: "modal_bootstrap_#{ModalResponder.bootstrap}" %>
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'modal-responder-rails/version'
|
2
|
+
|
3
|
+
require 'responders'
|
4
|
+
|
5
|
+
require 'modal-responder-rails/controller'
|
6
|
+
require 'modal-responder-rails/modal_responder'
|
7
|
+
|
8
|
+
module ModalResponder
|
9
|
+
# Bootstrap version to be used
|
10
|
+
mattr_accessor :bootstrap
|
11
|
+
@@bootstrap = 4
|
12
|
+
|
13
|
+
def self.configure
|
14
|
+
yield self
|
15
|
+
end
|
16
|
+
|
17
|
+
module Rails
|
18
|
+
class Engine < ::Rails::Engine
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
ActionController::Base.send(:include, ModalResponder::Rails::Controller)
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module ModalResponder
|
2
|
+
module Rails
|
3
|
+
class ModalResponder < ActionController::Responder
|
4
|
+
cattr_accessor :modal_layout
|
5
|
+
self.modal_layout = 'modal'
|
6
|
+
|
7
|
+
def render(*args)
|
8
|
+
options = args.extract_options!
|
9
|
+
if request.xhr?
|
10
|
+
options.merge! layout: modal_layout
|
11
|
+
end
|
12
|
+
controller.render *args, options
|
13
|
+
end
|
14
|
+
|
15
|
+
def default_render(*args)
|
16
|
+
render(*args)
|
17
|
+
end
|
18
|
+
|
19
|
+
def redirect_to(options)
|
20
|
+
if request.xhr?
|
21
|
+
head :ok, location: controller.url_for(options)
|
22
|
+
else
|
23
|
+
controller.redirect_to(options)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/make_new_release.sh
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
DOCKER_IMAGE_NAME="$USER/modal-responder-rails"
|
4
|
+
LIBRARY_NEW_VERSION=`cat lib/**/*.rb | grep VERSION | awk '{ print $3 }' | tr -d "'"`
|
5
|
+
|
6
|
+
LIBRARY_UPDATED=`git status --porcelain | grep -v "CHANGELOG.md" | grep -v "lib/modal-responder-rails/version.rb"`
|
7
|
+
if [[ -n "$LIBRARY_UPDATED" ]]; then
|
8
|
+
echo "Your repository is not clean !"
|
9
|
+
exit 1
|
10
|
+
fi
|
11
|
+
|
12
|
+
echo "Ensuring Docker image $DOCKER_IMAGE_NAME exists ..."
|
13
|
+
EXISTING_DOCKER_IMAGE=`docker images | grep "$DOCKER_IMAGE_NAME"`
|
14
|
+
if [[ -z "$EXISTING_DOCKER_IMAGE" ]]; then
|
15
|
+
echo "Building the Docker image ..."
|
16
|
+
docker build -t "$DOCKER_IMAGE_NAME" .
|
17
|
+
fi
|
18
|
+
|
19
|
+
echo "Updating library code to version $LIBRARY_NEW_VERSION ..."
|
20
|
+
docker run --rm -v `pwd`:/gem/ "$DOCKER_IMAGE_NAME" rake update
|
21
|
+
|
22
|
+
LIBRARY_UPDATED=`git status --porcelain | grep -v make_new_release.sh`
|
23
|
+
if [[ -z "$LIBRARY_UPDATED" ]]; then
|
24
|
+
echo "No update found, stopping release creation."
|
25
|
+
exit 1
|
26
|
+
elif [[ "$LIBRARY_UPDATED" == " M lib/modal-responder-rails/version.rb" ]]; then
|
27
|
+
echo "None of the JS or CSS files have been updated."
|
28
|
+
exit 1
|
29
|
+
fi
|
30
|
+
|
31
|
+
echo "Committing new version ..."
|
32
|
+
git commit -am "Import version $LIBRARY_NEW_VERSION"
|
33
|
+
|
34
|
+
echo "Releasing gem ..."
|
35
|
+
docker run --rm -v ~/.gitconfig:/root/.gitconfig \
|
36
|
+
-v ~/.ssh/:/root/.ssh/ \
|
37
|
+
-v ~/.gem/:/root/.gem/ \
|
38
|
+
-v `pwd`:/gem/ "$DOCKER_IMAGE_NAME" rake release
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'modal-responder-rails/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'modal-responder-rails'
|
8
|
+
spec.version = ModalResponder::Rails::VERSION
|
9
|
+
spec.authors = ['Guillaume Hain']
|
10
|
+
spec.email = ['zedtux@zedroot.org']
|
11
|
+
|
12
|
+
spec.summary = %q{Ease the use of modal in your Rails}
|
13
|
+
spec.description = %q{This gem ease the use of modal in your Rails
|
14
|
+
application thanks to a Responder. This code is built
|
15
|
+
based on Dmitriy Dudkin's article}
|
16
|
+
spec.homepage = 'https://github.com/Sento/modal-responder-rails'
|
17
|
+
spec.license = 'MIT'
|
18
|
+
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
20
|
+
f.match(%r{^(test|spec|features)/})
|
21
|
+
end
|
22
|
+
spec.require_paths = ['lib']
|
23
|
+
|
24
|
+
spec.add_dependency 'responders', '~> 2.3.0'
|
25
|
+
spec.add_dependency 'railties', '>= 3.2', '< 6.0'
|
26
|
+
|
27
|
+
spec.add_development_dependency 'bundler', '~> 1.13'
|
28
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
29
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
$(function() {
|
2
|
+
var modal_holder_selector, modal_selector;
|
3
|
+
modal_holder_selector = '#modal-holder';
|
4
|
+
modal_selector = '.modal';
|
5
|
+
$(document).on('click', 'a[data-modal]', function() {
|
6
|
+
var location;
|
7
|
+
location = $(this).attr('href');
|
8
|
+
$.get(location, function(data) {
|
9
|
+
return $(modal_holder_selector).html(data).find(modal_selector).modal();
|
10
|
+
});
|
11
|
+
return false;
|
12
|
+
});
|
13
|
+
return $(document).on('ajax:success', 'form[data-modal]', function(event, data, status, xhr) {
|
14
|
+
var url;
|
15
|
+
url = xhr.getResponseHeader('Location');
|
16
|
+
if (url) {
|
17
|
+
window.location = url;
|
18
|
+
} else {
|
19
|
+
$('.modal-backdrop').remove();
|
20
|
+
$(modal_holder_selector).html(data).find(modal_selector).modal();
|
21
|
+
}
|
22
|
+
return false;
|
23
|
+
});
|
24
|
+
});
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: modal-responder-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Guillaume Hain
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-11-27 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.3.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.3.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: railties
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.2'
|
34
|
+
- - "<"
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '6.0'
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '3.2'
|
44
|
+
- - "<"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '6.0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: bundler
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '1.13'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '1.13'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rake
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '10.0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '10.0'
|
75
|
+
description: |-
|
76
|
+
This gem ease the use of modal in your Rails
|
77
|
+
application thanks to a Responder. This code is built
|
78
|
+
based on Dmitriy Dudkin's article
|
79
|
+
email:
|
80
|
+
- zedtux@zedroot.org
|
81
|
+
executables: []
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files: []
|
84
|
+
files:
|
85
|
+
- ".gitignore"
|
86
|
+
- CHANGELOG.md
|
87
|
+
- Dockerfile
|
88
|
+
- Gemfile
|
89
|
+
- LICENSE.txt
|
90
|
+
- README.md
|
91
|
+
- Rakefile
|
92
|
+
- app/views/layouts/_modal_bootstrap_3.html.erb
|
93
|
+
- app/views/layouts/_modal_bootstrap_4.html.erb
|
94
|
+
- app/views/layouts/modal.html.erb
|
95
|
+
- lib/modal-responder-rails.rb
|
96
|
+
- lib/modal-responder-rails/controller.rb
|
97
|
+
- lib/modal-responder-rails/modal_responder.rb
|
98
|
+
- lib/modal-responder-rails/version.rb
|
99
|
+
- make_new_release.sh
|
100
|
+
- modal-responder-rails.gemspec
|
101
|
+
- vendor/assets/javascripts/modal-responder.js
|
102
|
+
homepage: https://github.com/Sento/modal-responder-rails
|
103
|
+
licenses:
|
104
|
+
- MIT
|
105
|
+
metadata: {}
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
requirements: []
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 2.6.8
|
123
|
+
signing_key:
|
124
|
+
specification_version: 4
|
125
|
+
summary: Ease the use of modal in your Rails
|
126
|
+
test_files: []
|