simple_ajax_form 0.1.25

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
+ SHA256:
3
+ metadata.gz: c7e185217480b966b99903dac1315674049d7ed671389aa2177cb4c2fe917fb1
4
+ data.tar.gz: a30889d64a33d1e36fe0ecfecfef1454664133fe7a797c2b101c1464b64b38ec
5
+ SHA512:
6
+ metadata.gz: c7c15e2901587c047c585c8a74033d3930ab598913f54a08739080d494578929b7eb18d14a585e91a45cc92e58bb733c1d3d900428079cc309ee5b8e47f74bea
7
+ data.tar.gz: fa4b013fe97798527963dd09ec407533f949770f776eb34dcd690562ae5d3352a8ef5eb056ee820c9d7054f0f015e30a8dfb6451ebbb2c94f0667f1ef91089e1
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in simple_ajax_form.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "rubocop", "~> 1.21"
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # SimpleAjaxForm
2
+
3
+ TODO: Delete this and the text below, and describe your gem
4
+
5
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/simple_ajax_form`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Development
24
+
25
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
26
+
27
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/simple_ajax_form.
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SimpleAjaxForm
4
+ VERSION = "0.1.25"
5
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "simple_ajax_form/version"
4
+ require 'active_support/core_ext/string/output_safety.rb'
5
+
6
+ module SimpleAjaxForm
7
+ class Error < StandardError; end
8
+ class RequestHelper
9
+ def self.enable_class_use_on_forms_html
10
+ "
11
+ <script>
12
+ document.addEventListener('turbo:load', function() {
13
+
14
+ let form_elements = document.querySelectorAll('.ajaxForm');
15
+
16
+ form_elements.forEach((element)=>{
17
+ element.replaceWith(element.cloneNode(true));
18
+ });
19
+
20
+ form_elements = document.querySelectorAll('.ajaxForm');
21
+
22
+ form_elements.forEach(function(form_element){
23
+ form_element.addEventListener('submit', function (event) {
24
+ event.preventDefault();
25
+
26
+ let element = this;
27
+ let form_url = element.getAttribute('action')
28
+ let form_method = element.getAttribute('method')
29
+ let form_body = new FormData(element)
30
+
31
+ fetch(form_url,
32
+ { method: form_method,
33
+ body: form_body }
34
+ ).then(res=>res.text())
35
+ .then(data=>eval(data));
36
+
37
+ });
38
+ });
39
+ });
40
+
41
+ </script>
42
+ ".html_safe
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,4 @@
1
+ module SimpleAjaxForm
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_ajax_form
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.25
5
+ platform: ruby
6
+ authors:
7
+ - XitaRps
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-05-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '7.0'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 7.0.4.3
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '7.0'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 7.0.4.3
33
+ description: |-
34
+ Since rails 7 uses HotWire, it became a bit hard to implement ajax submissions on form;
35
+ This gem implements a vanilla js solution for it(just call it at the very end of your erb file and add the class ajaxForm to your form_with)
36
+ email:
37
+ - xitarps@gmail.com
38
+ executables: []
39
+ extensions: []
40
+ extra_rdoc_files: []
41
+ files:
42
+ - ".rspec"
43
+ - ".rubocop.yml"
44
+ - Gemfile
45
+ - README.md
46
+ - Rakefile
47
+ - lib/simple_ajax_form.rb
48
+ - lib/simple_ajax_form/version.rb
49
+ - sig/simple_ajax_form.rbs
50
+ homepage: https://github.com/xitarps/simple_ajax_form
51
+ licenses: []
52
+ metadata:
53
+ homepage_uri: https://github.com/xitarps/simple_ajax_form
54
+ source_code_uri: https://github.com/xitarps/simple_ajax_form
55
+ changelog_uri: https://github.com/xitarps/simple_ajax_form/CHANGELOG.md
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 2.6.0
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubygems_version: 3.4.6
72
+ signing_key:
73
+ specification_version: 4
74
+ summary: Add fetch submit function to form_with on rails
75
+ test_files: []