rails-sweetalert2-confirm 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.travis.yml +17 -0
  4. data/Gemfile +3 -0
  5. data/MIT-LICENSE +20 -0
  6. data/README.md +222 -0
  7. data/Rakefile +12 -0
  8. data/lib/assets/javascripts/rails_sweetalert2_confirm.js +163 -0
  9. data/lib/rails_sweetalert2_confirm.rb +7 -0
  10. data/lib/rails_sweetalert2_confirm/rails/engine.rb +6 -0
  11. data/lib/rails_sweetalert2_confirm/railtie.rb +8 -0
  12. data/lib/rails_sweetalert2_confirm/version.rb +3 -0
  13. data/lib/rails_sweetalert2_confirm/view_helpers.rb +50 -0
  14. data/rails_sweetalert2_confirm.gemspec +29 -0
  15. data/spec/dummy/.gitignore +2 -0
  16. data/spec/dummy/.rspec +1 -0
  17. data/spec/dummy/Rakefile +6 -0
  18. data/spec/dummy/app/assets/javascripts/application.js +16 -0
  19. data/spec/dummy/app/assets/javascripts/application_turbolinks.js +17 -0
  20. data/spec/dummy/app/assets/stylesheets/application.css +3 -0
  21. data/spec/dummy/app/controllers/application_controller.rb +19 -0
  22. data/spec/dummy/app/views/application/destroy.html.erb +1 -0
  23. data/spec/dummy/app/views/application/destroy.js.erb +1 -0
  24. data/spec/dummy/app/views/application/index.html.erb +42 -0
  25. data/spec/dummy/app/views/layouts/application.html.erb +19 -0
  26. data/spec/dummy/bin/bundle +3 -0
  27. data/spec/dummy/bin/rails +4 -0
  28. data/spec/dummy/bin/rake +4 -0
  29. data/spec/dummy/config.ru +4 -0
  30. data/spec/dummy/config/application.rb +29 -0
  31. data/spec/dummy/config/boot.rb +5 -0
  32. data/spec/dummy/config/database.yml +25 -0
  33. data/spec/dummy/config/environment.rb +5 -0
  34. data/spec/dummy/config/environments/development.rb +37 -0
  35. data/spec/dummy/config/environments/production.rb +78 -0
  36. data/spec/dummy/config/environments/test.rb +43 -0
  37. data/spec/dummy/config/initializers/assets.rb +8 -0
  38. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  39. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  40. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  41. data/spec/dummy/config/initializers/inflections.rb +16 -0
  42. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  43. data/spec/dummy/config/initializers/secret_token.rb +1 -0
  44. data/spec/dummy/config/initializers/session_store.rb +3 -0
  45. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  46. data/spec/dummy/config/locales/en.yml +23 -0
  47. data/spec/dummy/config/routes.rb +5 -0
  48. data/spec/dummy/config/secrets.yml +22 -0
  49. data/spec/dummy/log/.keep +0 -0
  50. data/spec/dummy/public/404.html +67 -0
  51. data/spec/dummy/public/422.html +67 -0
  52. data/spec/dummy/public/500.html +66 -0
  53. data/spec/dummy/public/favicon.ico +0 -0
  54. data/spec/features/rails_sweetalert2_confirm_spec.rb +109 -0
  55. data/spec/spec_helper.rb +48 -0
  56. data/tags +20 -0
  57. metadata +241 -0
@@ -0,0 +1,7 @@
1
+ # require 'sweet_alert'
2
+ require 'rails_sweetalert2_confirm/version'
3
+ require 'rails_sweetalert2_confirm/railtie'
4
+ require 'rails_sweetalert2_confirm/rails/engine'
5
+
6
+ module RailsSweetAlert2Confirm
7
+ end
@@ -0,0 +1,6 @@
1
+ module RailsSweetAlert2Confirm
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,8 @@
1
+ require 'rails_sweetalert2_confirm/view_helpers'
2
+ module RailsSweetAlert2Confirm
3
+ class Railtie < Rails::Railtie
4
+ initializer 'rails_sweetalert2_confirm.view_helpers' do
5
+ ActionView::Base.send :include, ViewHelpers
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module RailsSweetAlert2Confirm
2
+ VERSION = "0.9.0"
3
+ end
@@ -0,0 +1,50 @@
1
+ module RailsSweetAlert2Confirm
2
+ SWAL_OPTIONS_MAPPINGS = {
3
+ confirm: :title,
4
+ remote: :remote
5
+ }
6
+
7
+ module ViewHelpers
8
+ def link_to(*args, &block)
9
+ options = args[block_given? ? 1 : 2] || {}
10
+ options = merge_options_into_swal(options)
11
+ super(*args, &block)
12
+ end
13
+
14
+ def submit_tag(value = 'Save changes', options = {})
15
+ options = merge_options_into_swal(options)
16
+ super value, options
17
+ end
18
+
19
+ def button_tag(*args, &block)
20
+ options = args[block_given? ? 0 : 1] || {}
21
+ options = merge_options_into_swal(options)
22
+ super(*args, &block)
23
+ end
24
+
25
+ protected
26
+
27
+ def merge_options_into_swal(options)
28
+ options = merge_confirm_into_swal(options)
29
+ merge_remote_into_swal(options)
30
+ end
31
+
32
+ %w(confirm remote).each do |option|
33
+ define_method("merge_#{option}_into_swal") do |options|
34
+ if send("options_has_#{option}?", options)
35
+ options[:data] ||= {}
36
+ options[:data][:swal] ||= {}
37
+ option = option.to_sym
38
+ options[:data][:swal][SWAL_OPTIONS_MAPPINGS[option]] =
39
+ options.delete(option) || options[:data].delete(option)
40
+ end
41
+ options
42
+ end
43
+
44
+ define_method("options_has_#{option}?") do |options|
45
+ option = option.to_sym
46
+ (options[option] || options[:data].try(:[], option)).present?
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,29 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ # Maintain your gem's version:
4
+ require "rails_sweetalert2_confirm/version"
5
+
6
+ # Describe your gem and declare its dependencies:
7
+ Gem::Specification.new do |s|
8
+ s.name = "rails-sweetalert2-confirm"
9
+ s.version = RailsSweetAlert2Confirm::VERSION
10
+ s.authors = ["Joe Woodward"]
11
+ s.email = ["j@joewoodward.me"]
12
+ s.homepage = "https://github.com/JoeWoodward/rails-sweetalert2-confirm"
13
+ s.summary = "A Rails Confirm Replacement Using SweetAlert2"
14
+ s.description = "Replace rail's built in link_to/submit/button with confirmations with SweetAlert2 confirmations"
15
+ s.license = "MIT"
16
+
17
+ s.add_development_dependency "rails", ">=4"
18
+ s.add_development_dependency "rspec-rails", '~> 3.5'
19
+ s.add_development_dependency "capybara", "~> 2.1"
20
+ s.add_development_dependency "pry", '~> 0.10'
21
+ s.add_development_dependency "jquery-rails", '~> 4.1'
22
+ s.add_development_dependency "test-unit", '~> 3.2'
23
+ s.add_development_dependency "sass-rails", '~> 5.0'
24
+ s.add_development_dependency "poltergeist", '~> 1.10'
25
+ s.add_development_dependency "rake", '~> 11.2'
26
+ s.add_development_dependency "turbolinks", '~> 5.0'
27
+ s.files = `git ls-files`.split("\n")
28
+ s.require_paths = ['lib']
29
+ end
@@ -0,0 +1,2 @@
1
+ Gemfile.lock
2
+ .Ds_Store
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Rails.application.load_tasks
@@ -0,0 +1,16 @@
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 vendor/assets/javascripts of plugins, if any, 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.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require sweetalert2
16
+ //= require rails_sweetalert2_confirm
@@ -0,0 +1,17 @@
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 vendor/assets/javascripts of plugins, if any, 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.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require turbolinks
16
+ //= require sweetalert2
17
+ //= require rails_sweetalert2_confirm
@@ -0,0 +1,3 @@
1
+ /*
2
+ *= require sweetalert2
3
+ */
@@ -0,0 +1,19 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery with: :exception
3
+
4
+ def show
5
+ redirect_to root_path, notice: 'Showing'
6
+ end
7
+
8
+ def index
9
+ end
10
+
11
+ def destroy
12
+ unless request.xhr?
13
+ redirect_to root_path, notice: 'Destroyed'
14
+ end
15
+ respond_to do |format|
16
+ format.js {}
17
+ end
18
+ end
19
+ end
@@ -0,0 +1 @@
1
+ <h1> You murdered a silly cow</h1>
@@ -0,0 +1 @@
1
+ $('#remoteConfirmTrigger').text('Destroy called asyncronously');
@@ -0,0 +1,42 @@
1
+ <%= link_to('Basic confirm', show_path, id: 'basicConfirmTrigger', data: { confirm: 'Are you sure?' }) %>
2
+ <%=
3
+ link_to(
4
+ 'Remote confirm',
5
+ destroy_path,
6
+ method: :delete,
7
+ id: 'remoteConfirmTrigger',
8
+ remote: true,
9
+ data: {
10
+ confirm: 'Are you sure?'
11
+ }
12
+ )
13
+ %>
14
+ <%=
15
+ link_to(
16
+ 'Custom confirm',
17
+ root_path,
18
+ id: 'customConfirmTrigger',
19
+ data: {
20
+ confirm: 'Do you like this customized confirm dialog?',
21
+ swal: {
22
+ text: 'This is the subtext',
23
+ html: '<h1>This is the subtext as a h1</h1>',
24
+ type: 'question',
25
+ custom_class: 'customClass',
26
+ animation: false,
27
+ allow_outside_click: false,
28
+ allow_escape_key: false,
29
+ show_confirm_button: false,
30
+ show_cancel_button: false
31
+ }
32
+ }
33
+ )
34
+ %>
35
+
36
+ <%= form_tag(destroy_path, method: :delete) do %>
37
+ <%= submit_tag('Submit Confirm', id: 'submitConfirmTrigger', data: { confirm: 'Are you sure?' }) %>
38
+ <% end %>
39
+
40
+ <%= form_tag(destroy_path, method: :delete) do %>
41
+ <%= button_tag('Button Confirm', id: 'buttonConfirmTrigger', data: { confirm: 'Are you sure?' }) %>
42
+ <% end %>
@@ -0,0 +1,19 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
6
+ <% if ENV['USE_TURBOLINKS'] %>
7
+ <%= javascript_include_tag 'application_turbolinks', "data-turbolinks-track" => true %>
8
+ <% else %>
9
+ <%= javascript_include_tag 'application', "data-turbolinks-track" => false %>
10
+ <% end %>
11
+ <%= csrf_meta_tags %>
12
+ </head>
13
+ <body>
14
+ <% flash.each do |type, msg| %>
15
+ <h1><%= msg %></h1>
16
+ <% end %>
17
+ <%= yield %>
18
+ </body>
19
+ </html>
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../config/boot'
3
+ require 'rake'
4
+ Rake.application.run
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Rails.application
@@ -0,0 +1,29 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ # Pick the frameworks you want:
4
+ #require "active_record/railtie"
5
+ require "action_controller/railtie"
6
+ require "action_mailer/railtie"
7
+ require "action_view/railtie"
8
+ require "sprockets/railtie"
9
+ # require "rails/test_unit/railtie"
10
+
11
+ Bundler.require(*Rails.groups)
12
+ require "rails_sweetalert2_confirm"
13
+
14
+ module Dummy
15
+ class Application < Rails::Application
16
+ # Settings in config/environments/* take precedence over those specified here.
17
+ # Application configuration should go into files in config/initializers
18
+ # -- all .rb files in that directory are automatically loaded.
19
+
20
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
21
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
22
+ # config.time_zone = 'Central Time (US & Canada)'
23
+
24
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
25
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
26
+ # config.i18n.default_locale = :de
27
+ end
28
+ end
29
+
@@ -0,0 +1,5 @@
1
+ # Set up gems listed in the Gemfile.
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)
3
+
4
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
5
+ $LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
@@ -0,0 +1,25 @@
1
+ # SQLite version 3.x
2
+ # gem install sqlite3
3
+ #
4
+ # Ensure the SQLite 3 gem is defined in your Gemfile
5
+ # gem 'sqlite3'
6
+ #
7
+ #default: &default
8
+ # adapter: sqlite3
9
+ # pool: 5
10
+ # timeout: 5000
11
+ #
12
+ #development:
13
+ # <<: *default
14
+ # database: db/development.sqlite3
15
+ #
16
+ ## Warning: The database defined as "test" will be erased and
17
+ ## re-generated from your development database when you run "rake".
18
+ ## Do not set this db to the same as development or production.
19
+ #test:
20
+ # <<: *default
21
+ # database: db/test.sqlite3
22
+ #
23
+ #production:
24
+ # <<: *default
25
+ # database: db/production.sqlite3
@@ -0,0 +1,5 @@
1
+ # Load the Rails application.
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the Rails application.
5
+ Rails.application.initialize!
@@ -0,0 +1,37 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb.
3
+
4
+ # In the development environment your application's code is reloaded on
5
+ # every request. This slows down response time but is perfect for development
6
+ # since you don't have to restart the web server when you make code changes.
7
+ config.cache_classes = false
8
+
9
+ # Do not eager load code on boot.
10
+ config.eager_load = false
11
+
12
+ # Show full error reports and disable caching.
13
+ config.consider_all_requests_local = true
14
+ config.action_controller.perform_caching = false
15
+
16
+ # Don't care if the mailer can't send.
17
+ config.action_mailer.raise_delivery_errors = false
18
+
19
+ # Print deprecation notices to the Rails logger.
20
+ config.active_support.deprecation = :log
21
+
22
+ # Raise an error on page load if there are pending migrations.
23
+ #config.active_record.migration_error = :page_load
24
+
25
+ # Debug mode disables concatenation and preprocessing of assets.
26
+ # This option may cause significant delays in view rendering with a large
27
+ # number of complex assets.
28
+ config.assets.debug = true
29
+
30
+ # Adds additional error checking when serving assets at runtime.
31
+ # Checks for improperly declared sprockets dependencies.
32
+ # Raises helpful error messages.
33
+ config.assets.raise_runtime_errors = true
34
+
35
+ # Raises error for missing translations
36
+ # config.action_view.raise_on_missing_translations = true
37
+ end
@@ -0,0 +1,78 @@
1
+ Rails.application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb.
3
+
4
+ # Code is not reloaded between requests.
5
+ config.cache_classes = true
6
+
7
+ # Eager load code on boot. This eager loads most of Rails and
8
+ # your application in memory, allowing both threaded web servers
9
+ # and those relying on copy on write to perform better.
10
+ # Rake tasks automatically ignore this option for performance.
11
+ config.eager_load = true
12
+
13
+ # Full error reports are disabled and caching is turned on.
14
+ config.consider_all_requests_local = false
15
+ config.action_controller.perform_caching = true
16
+
17
+ # Enable Rack::Cache to put a simple HTTP cache in front of your application
18
+ # Add `rack-cache` to your Gemfile before enabling this.
19
+ # For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid.
20
+ # config.action_dispatch.rack_cache = true
21
+
22
+ # Disable Rails's static asset server (Apache or nginx will already do this).
23
+ config.serve_static_assets = false
24
+
25
+ # Compress JavaScripts and CSS.
26
+ config.assets.js_compressor = :uglifier
27
+ # config.assets.css_compressor = :sass
28
+
29
+ # Do not fallback to assets pipeline if a precompiled asset is missed.
30
+ config.assets.compile = false
31
+
32
+ # Generate digests for assets URLs.
33
+ config.assets.digest = true
34
+
35
+ # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
36
+
37
+ # Specifies the header that your server uses for sending files.
38
+ # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
39
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
40
+
41
+ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
42
+ # config.force_ssl = true
43
+
44
+ # Set to :debug to see everything in the log.
45
+ config.log_level = :info
46
+
47
+ # Prepend all log lines with the following tags.
48
+ # config.log_tags = [ :subdomain, :uuid ]
49
+
50
+ # Use a different logger for distributed setups.
51
+ # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
52
+
53
+ # Use a different cache store in production.
54
+ # config.cache_store = :mem_cache_store
55
+
56
+ # Enable serving of images, stylesheets, and JavaScripts from an asset server.
57
+ # config.action_controller.asset_host = "http://assets.example.com"
58
+
59
+ # Ignore bad email addresses and do not raise email delivery errors.
60
+ # Set this to true and configure the email server for immediate delivery to raise delivery errors.
61
+ # config.action_mailer.raise_delivery_errors = false
62
+
63
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
64
+ # the I18n.default_locale when a translation cannot be found).
65
+ config.i18n.fallbacks = true
66
+
67
+ # Send deprecation notices to registered listeners.
68
+ config.active_support.deprecation = :notify
69
+
70
+ # Disable automatic flushing of the log to improve performance.
71
+ # config.autoflush_log = false
72
+
73
+ # Use default logging formatter so that PID and timestamp are not suppressed.
74
+ config.log_formatter = ::Logger::Formatter.new
75
+
76
+ # Do not dump schema after migrations.
77
+ config.active_record.dump_schema_after_migration = false
78
+ end