maac 0.1.0.pre.alpha

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: d3de4b05f7e1941afda3621852b4d1f056fc09e9
4
+ data.tar.gz: 183ff1ce182ff9ecbe46b4f352a08bf73ad1f999
5
+ SHA512:
6
+ metadata.gz: 064a5b983facf2972ccfa9640611c29197c754c1b2cb63bac18a36af64cdf44e265cebc8e91895c5219f23d9fd9b461a8826c78c95f31d8ad0fcf1a4318ea1e3
7
+ data.tar.gz: 518dece03d42689abcd639e39e0104d5c70c01435b9e6ed3c4220a1bf1fef53d383950306415838b33f60c5d9c7b8527782b5fac8fddf892771cc5e029d0f6e1
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2018 Igor M Osipov
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,96 @@
1
+ # Modal As A Confirm (MAAC)
2
+
3
+ This gem allows you to replace standard confirm() call for data-confirm'ed page elements,
4
+ with a bootstrap modal. I.e. instead of calling confirm("Are you sure?") this code will draw
5
+ a bootstrap yes-no modal after clicking the link.
6
+ For now, you can customize dialog texts using following attributes:
7
+
8
+ - **data-confirm-title** - *dialog title text: default value is "Confirm"*
9
+
10
+ - **data-confirm-yes** - *yes-button text: default value is "Yes"*
11
+
12
+ - **data-confirm-no** - *no-button text: default value is "No"*
13
+
14
+ - **data-confirm-close** - *close cross title: default value is "Close"*
15
+
16
+ ```rhtml
17
+ <%= link_to 'A very dangerous action',
18
+ dangerous_action_path,
19
+ data: {
20
+ method: :delete,
21
+ confirm: 'Are you sure?'
22
+ } %>
23
+ ```
24
+ There are lots of gems for the same purpose, but I found nothing appropriate for Rails 5.
25
+ So I've made it for my purposes. I'll be happy if you find it useful.
26
+
27
+ ## Installation
28
+
29
+ Add this line to your application's Gemfile:
30
+
31
+ ```ruby
32
+ gem 'maac'
33
+ ```
34
+
35
+ And then execute:
36
+
37
+ $ bundle
38
+
39
+ Or install it yourself as:
40
+
41
+ $ gem install maac
42
+
43
+ ## Usage
44
+
45
+ /app/assets/javascripts/application.js:
46
+ ```javascript
47
+ //= require rails-ujs
48
+ //= require bootstrap/modal
49
+ //= require maac
50
+ ```
51
+
52
+ Somewhere in views:
53
+ ```rhtml
54
+ <%= link_to 'A very dangerous action',
55
+ dangerous_action_path,
56
+ data: {
57
+ method: :delete,
58
+ confirm: 'Are you sure?'
59
+ } %>
60
+ ```
61
+
62
+ Or:
63
+ ```rhtml
64
+ <%= link_to 'A very dangerous action',
65
+ dangerous_action_path,
66
+ data: {
67
+ method: :delete,
68
+ confirm: 'Are you sure?'
69
+ 'confirm-title': 'Danger!',
70
+ 'confirm-yes': 'Proceed',
71
+ 'confirm-no': 'Cancel',
72
+ 'confirm-close': 'Never mind'
73
+ } %>
74
+ ```
75
+
76
+ ## Development
77
+
78
+ ### Installing dependencies
79
+
80
+ $ bundle install
81
+
82
+ ### Testing
83
+
84
+ $ rake
85
+
86
+ TODO: Write other steps
87
+
88
+ 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
89
+
90
+ ## Contributing
91
+
92
+ Bug reports and pull requests are welcome on GitHub at https://github.com/igorakaamigo/rails5-bootstrap-confirm.
93
+
94
+ ## License
95
+
96
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/lib/maac.rb ADDED
@@ -0,0 +1,4 @@
1
+ module Maac
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,47 @@
1
+ (function() {
2
+ var showAModal;
3
+
4
+ Rails.delegate(document, 'a[data-confirm]', 'confirm', function(event) {
5
+ var confirm, link;
6
+ link = this;
7
+ if (link.hasAttribute('data-confirmed')) {
8
+ link.removeAttribute('data-confirmed');
9
+ confirm = function() {
10
+ return true;
11
+ };
12
+ return true;
13
+ }
14
+ showAModal(link, 'Yes', 'No', 'Close', 'Confirm');
15
+ return false;
16
+ });
17
+
18
+ showAModal = function(link, defaultYes, defaultNo, defaultClose, defaultTitle) {
19
+ var dialogClose, dialogNo, dialogTitle, dialogYes, modal;
20
+ modal = document.createElement('div');
21
+ modal.className = 'modal';
22
+ modal.setAttribute('tabindex', '-1');
23
+ modal.setAttribute('role', 'dialog');
24
+ dialogYes = link.getAttribute('data-confirm-yes') || defaultYes;
25
+ dialogNo = link.getAttribute('data-confirm-no') || defaultNo;
26
+ dialogClose = link.getAttribute('data-confirm-close') || defaultClose;
27
+ dialogTitle = link.getAttribute('data-confirm-title') || defaultTitle;
28
+ modal.innerHTML = '<div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title"></h5> <button type="button" class="close" data-dismiss="modal" aria-label=""> <span aria-hidden="true">&times;</span> </button> </div> <div class="modal-body"> <p></p> </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary"></button> <button type="button" class="btn btn-primary"></button> </div> </div> </div>';
29
+ modal.querySelector('.modal-body > p').innerText = link.getAttribute('data-confirm');
30
+ modal.querySelector('.modal-footer > .btn-secondary').innerText = dialogYes;
31
+ modal.querySelector('.modal-footer > .btn-primary').innerText = dialogNo;
32
+ modal.querySelector('.modal-header > button').setAttribute('aria-label', dialogClose);
33
+ modal.querySelector('.modal-header > h5').innerText = dialogTitle;
34
+ Rails.delegate(modal, '.btn-primary', 'click', function(event) {
35
+ Rails.stopEverything(event);
36
+ return modal.remove();
37
+ });
38
+ Rails.delegate(modal, '.btn-secondary', 'click', function(event) {
39
+ Rails.stopEverything(event);
40
+ modal.remove();
41
+ link.setAttribute('data-confirmed', true);
42
+ return Rails.fire(link, 'click');
43
+ });
44
+ return document.body.appendChild(modal);
45
+ };
46
+
47
+ }).call(this);
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: maac
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.pre.alpha
5
+ platform: ruby
6
+ authors:
7
+ - Igor M Osipov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-01-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 5.1.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 5.1.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: sqlite3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec-rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: capybara
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: factory_bot_rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: coffee-script
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: poltergeist
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: This gem allows you to replace standard confirm() call for data-confirm'ed
112
+ page elements, with a bootstrap modal.
113
+ email:
114
+ - osipov.igor.amigo@gmail.com
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - MIT-LICENSE
120
+ - README.md
121
+ - lib/maac.rb
122
+ - vendor/assets/javascripts/maac.js
123
+ homepage: https://github.com/igorakaamigo/maac
124
+ licenses:
125
+ - MIT
126
+ metadata: {}
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">"
139
+ - !ruby/object:Gem::Version
140
+ version: 1.3.1
141
+ requirements: []
142
+ rubyforge_project:
143
+ rubygems_version: 2.6.13
144
+ signing_key:
145
+ specification_version: 4
146
+ summary: Bootstrap confirmation modal for data-confirm'ed links @ Rails 5 projects
147
+ test_files: []