ajax_modal 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 31726250a967b7cb40d6faabef66c801dd486112
4
+ data.tar.gz: 1f79651aec69b24f91ed3f03c5673cf3c550b88f
5
+ SHA512:
6
+ metadata.gz: dacd76bdb7f2c82699babee765e77400da8c8685b0f40b7a5a53182c89479fae8dd0f99a881f749b46fa0cdb1f21f45f1b81b8ce403ed122f35212022a8bf274
7
+ data.tar.gz: 27b06fffc675f507446f638d0dbbeb3271bd9ee5c21d58fb5dd263464188b0bb34b56b2ee8dff1fee118a1ebd6cac3ea1f26f4e228cbdc61415bb95478353eef
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.2
5
+ before_install: gem install bundler -v 1.12.5
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at it@4beauty.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ajax_modal.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Matt Rothstein
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.
@@ -0,0 +1,58 @@
1
+ # AjaxModal
2
+
3
+ AjaxModal is an AJAX scaffold generator used to provide a Bootstrap Modal workflow.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'ajax_modal'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install ajax_modal
20
+
21
+ ## Usage
22
+
23
+ $ rails g ajax_modal [RESOURCE_NAME]
24
+
25
+
26
+ ### Quick Simple Example:
27
+
28
+
29
+ 1. Add ajax_modal to your application's Gemfile:
30
+
31
+ gem 'ajax_modal'
32
+
33
+ 2. Run 'bundle' to install this gem in your project:
34
+
35
+ $ bundle
36
+
37
+ 3. Generate new scaffold called e.g. posts:
38
+
39
+ $ rails generate scaffold post title body:text published:boolean
40
+
41
+ 4. Don't forget to run migration:
42
+
43
+ $ rake db:migrate
44
+
45
+ 5. Generate ajax for posts scaffold with ajax_modal generator:
46
+
47
+ $ rails g ajax_modal post
48
+
49
+ Open your project in a browser.
50
+
51
+ ## Contributing
52
+
53
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ajax_modal. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
54
+
55
+
56
+ ## License
57
+
58
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ajax_modal/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ajax_modal"
8
+ spec.version = AjaxModal::VERSION
9
+ spec.authors = ["Matt Rothstein"]
10
+ spec.email = ["matthewrothstein@hotmail.com"]
11
+
12
+ spec.summary = %q{implements ajax modal workflow.}
13
+ spec.description = %q{implements ajax modal workflow.}
14
+ spec.homepage = "https://github.com/mattrothstein/ajax-modal"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.3"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "rails", "~> 3.2.0"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ajax_modal"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ require "ajax_modal/version"
2
+
3
+ module AjaxModal
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,3 @@
1
+ module AjaxModal
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,29 @@
1
+ Usage
2
+
3
+ $ rails g ajax_modal [RESOURCE_NAME]
4
+
5
+
6
+ ### Quick Simple Example:
7
+
8
+
9
+ 1. Add ajax_modal to your application's Gemfile:
10
+
11
+ gem 'ajax_modal'
12
+
13
+ 2. Run 'bundle' to install this gem in your project:
14
+
15
+ $ bundle
16
+
17
+ 3. Generate new scaffold called e.g. posts:
18
+
19
+ $ rails generate scaffold post title body:text published:boolean
20
+
21
+ 4. Don't forget to run migration:
22
+
23
+ $ rake db:migrate
24
+
25
+ 5. Generate ajax for posts scaffold with ajax_modal generator:
26
+
27
+ $ rails g ajax_modal post
28
+
29
+ Open your project in a browser.
@@ -0,0 +1,158 @@
1
+ class AjaxModalGenerator < Rails::Generators::NamedBase
2
+ source_root File.expand_path('../templates', __FILE__)
3
+ #application.html.erb
4
+ def modify_application_html_erb_file
5
+ file_path = "app/views/layouts/application.html.erb"
6
+ modal = <<-FOO
7
+ <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
8
+ <div class="modal-dialog" role="document">
9
+ <div class="modal-content">
10
+ <div class="modal-header">
11
+ <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
12
+ </div>
13
+ <div class="modal-body" id="ajax-modal">
14
+
15
+ </div>
16
+ </div>
17
+ </div>
18
+ </div>
19
+ FOO
20
+ inject_into_file "#{file_path}", modal, after: "<%= yield %>"
21
+ end
22
+ #show.js.erb
23
+ def create_show_js_erb_file
24
+ create_file "app/views/#{plural_name}/show.js.erb", <<-FILE
25
+ $('.modal').modal('hide')
26
+ $('.modal-backdrop').remove();
27
+ $('body').removeClass('modal-open');
28
+ $('#ajax-modal').html("<%= escape_javascript(render 'show')%>")
29
+ FILE
30
+ end
31
+ #destroy.js.erb
32
+ def create_destroy_js_erb_file
33
+ create_file "app/views/#{plural_name}/destroy.js.erb", <<-FILE
34
+ $('.modal').modal('hide')
35
+ $('.modal-backdrop').remove();
36
+ $('body').removeClass('modal-open');
37
+ $('table tr td').find('a[href="/#{plural_name}/<%= @#{plural_name.singularize}.id %>"]').parent().parent()
38
+ .remove();
39
+ $('#ajax-modal').html('');
40
+ FILE
41
+ end
42
+ #edit.js.erb
43
+ def create_edit_js_erb_file
44
+ create_file "app/views/#{plural_name}/edit.js.erb", <<-FILE
45
+ $("#ajax-modal").html("<%= escape_javascript(render 'form')%>");
46
+ FILE
47
+ end
48
+ #new.js.erb
49
+ def create_new_js_erb_file
50
+ create_file "app/views/#{plural_name}/new.js.erb", <<-FILE
51
+ $("#ajax-modal").html("<%= escape_javascript(render 'form')%>");
52
+ FILE
53
+ end
54
+ #create.js.erb
55
+ def create_create_js_erb_file
56
+ create_file "app/views/#{plural_name}/create.js.erb", <<-FILE
57
+ $('.modal').modal('hide')
58
+ $('.modal-backdrop').remove();
59
+ $('body').removeClass('modal-open');
60
+ $('table').append('<%= j render(@#{plural_name.singularize}) %>');
61
+ $("#ajax-modal").html("<%= escape_javascript(render 'show', notice:
62
+ "#{plural_name.singularize.capitalize} created successful.") %>");
63
+ FILE
64
+ end
65
+ #update.js.erb
66
+ def create_update_js_erb_file
67
+ create_file "app/views/#{plural_name}/update.js.erb", <<-FILE
68
+ $('table tr td').find('a[href="/#{plural_name}/<%= @#{plural_name.singularize}.id %>"]').
69
+ parent().parent().replaceWith("<%= escape_javascript render(@#{plural_name.singularize}) %>");
70
+ $("#ajax-modal").html("<%= escape_javascript(render 'show', notice: "Update successful.") %>");
71
+ FILE
72
+ end
73
+ #_show.html.erb
74
+ def create__show_html_erb_file
75
+ file_path = "app/views/#{plural_name}/show.html.erb"
76
+ file_in_array = IO.readlines(file_path)
77
+ file_in_array.each {|line| line.gsub!(/ ?, ?:remote=> ?true| ?, ?remote: ?true/,'')}
78
+ file_in_array.each_index do |i|
79
+ if (file_in_array[i].include?("link_to")) and (!file_in_array[i].match(/Back/i))
80
+ until file_in_array[i].sub!(/%>/,',"data-remote" => true , "data-toggle" => "modal", "data-target" => "#myModal" %>')
81
+ i+=1
82
+ end
83
+ end
84
+ end
85
+ create_file "app/views/#{plural_name}/_show.html.erb","#{file_in_array.join}"
86
+ end
87
+ #resource_controller
88
+ def modify_controller #adding forma.js ir rails version <4
89
+ file_path = "app/controllers/#{plural_name}_controller.rb"
90
+ file_in_array = IO.readlines(file_path)
91
+ file_in_array.each_index do |i|
92
+ if (file_in_array[i] =~/format.json(.*)/)
93
+ if !file_in_array[i+1].include?('format.js')
94
+ file_in_array.insert(i+1," format.js")
95
+ end
96
+ end
97
+ end
98
+ file = File.open(file_path,"w")
99
+ file.puts file_in_array
100
+ file.close
101
+ puts " \033[96mmodified \033[39m #{file_path}"
102
+ end
103
+ #index.htm.erb
104
+ def modify_index_file #add remote:true
105
+ file_path = "app/views/#{plural_name}/index.html.erb"
106
+ file_in_array = IO.readlines(file_path)
107
+ file_in_array.each {|line| line.gsub!(/ ?, ?:remote=> ?true| ?, ?remote: ?true/,'')}
108
+ file_in_array.each_index do |i|
109
+ if (file_in_array[i].include?("link_to")) and (!file_in_array[i].match(/Back/i))
110
+ until file_in_array[i].sub!(/%>/,',"data-remote" => true , "data-toggle" => "modal", "data-target" => "#myModal" %>')
111
+ i+=1
112
+ end
113
+ end
114
+ end
115
+ file = File.open(file_path,"w")
116
+ file.puts file_in_array
117
+ file.close
118
+ puts " \033[96mmodified \033[39m #{file_path}"
119
+ end
120
+ #_form.html.erb
121
+ def modify__form_file #add remote:true
122
+ file_path = "app/views/#{plural_name}/_form.html.erb"
123
+ file_in_array = IO.readlines(file_path)
124
+ file_in_array.each {|line| line.gsub!(/ ?, ?:remote=> ?true| ?, ?remote: ?true/,'')}
125
+ file_in_array.each_index do |i|
126
+ if (file_in_array[i].include?("form_for"))
127
+ until file_in_array[i].sub!("@#{plural_name.singularize}","@#{plural_name.singularize}, :remote=> true")
128
+ i+=1
129
+ end
130
+ end
131
+ end
132
+ file = File.open(file_path,"w")
133
+ file.puts file_in_array
134
+ file.close
135
+ puts " \033[96mmodified \033[39m #{file_path}"
136
+ end
137
+ #_resource.html.erb
138
+ def create_instance_partial_html_erb_file
139
+ file_in_array = IO.readlines("app/views/#{plural_name}/index.html.erb")
140
+ start_copy, stop_copy = 0
141
+ file_in_array.each_index do |i|
142
+ if (file_in_array[i].include?("@#{plural_name}.each"))
143
+ start_copy = i+1
144
+ end
145
+ if (file_in_array[i].include?("<% end %>"))
146
+ stop_copy = i
147
+
148
+ end
149
+ end
150
+ out_file = []
151
+ (start_copy...stop_copy).each{|i| out_file<<file_in_array[i]}
152
+ out_file.each do |line|
153
+ line.gsub!(" #{plural_name.singularize}."," @#{plural_name.singularize}.")
154
+ line.gsub!("(#{plural_name.singularize}","(@#{plural_name.singularize}")
155
+ end
156
+ create_file "app/views/#{plural_name}/_#{plural_name.singularize}.html.erb","#{out_file.join}"
157
+ end
158
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ajax_modal
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Matt Rothstein
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-03-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
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: rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.2.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.2.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: implements ajax modal workflow.
70
+ email:
71
+ - matthewrothstein@hotmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - CODE_OF_CONDUCT.md
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - ajax_modal.gemspec
85
+ - bin/console
86
+ - bin/setup
87
+ - lib/ajax_modal.rb
88
+ - lib/ajax_modal/version.rb
89
+ - lib/generators/ajax_modal/USAGE
90
+ - lib/generators/ajax_modal/ajax_modal_generator.rb
91
+ homepage: https://github.com/mattrothstein/ajax-modal
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.4.7
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: implements ajax modal workflow.
115
+ test_files: []