protected_form 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e564e480434ce2b4573b1faafb8373477ac47b0b
4
+ data.tar.gz: 5ef415e1f41d9e40c6e96e5419b0b29fd593956f
5
+ SHA512:
6
+ metadata.gz: e65798e616a74ce46a48f6cb0776d011ffd31b0614be12b3d4ca97aaba942bdf1162117c31025074240b8dfaeb6b6e03c8ed01f09e6d15f3c6419a22c1f55840
7
+ data.tar.gz: cfb3256f219071f0d2eefa7120c237d5004123501402be2a73e80c39941ee3f25b96ddea0a51e080f1bbda1c70c2f28862673d8ce0d849235791355184025dc5
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in protected_form.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Alexandr Subbotin
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # ProtectedForm
2
+
3
+ Simple spam-protection wrapper for rails forms.
4
+
5
+ # How it works
6
+
7
+ This gem replaces your html form with html like:
8
+
9
+ <form>
10
+ <content>
11
+ <form>
12
+
13
+ to html like
14
+
15
+ <div style="display: none">
16
+ <form id="pf_123123_form"></form>
17
+ </div>
18
+ <content id="pf_123123"></content>
19
+
20
+ and after user submits form in `<content>`, javascript inserts content into form and triggers `submit` event on form. Users see the same form, but for robots your form is empty. Profit!
21
+
22
+ ## Usage
23
+
24
+ Just replace your `form_for` method to `protected_form_for` and load `protected_form.js` on page with your form.
25
+
26
+ ## Installation
27
+
28
+ Add this line to your application's Gemfile:
29
+
30
+ gem 'protected_form'
31
+
32
+ And then execute:
33
+
34
+ $ bundle
35
+
36
+ Or install it yourself as:
37
+
38
+ $ gem install protected_form
39
+
40
+ ## Contributing
41
+
42
+ 1. Fork it ( https://github.com/KELiON/protected_form/fork )
43
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
44
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
45
+ 4. Push to the branch (`git push origin my-new-feature`)
46
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,5 @@
1
+ module ProtectedForm
2
+ class Engine < ::Rails::Engine
3
+ # Get rails to add app, lib, vendor to load path
4
+ end
5
+ end
@@ -0,0 +1,18 @@
1
+ module ProtectedForm
2
+ module Helpers
3
+ def protected_form_for *attrs, &block
4
+ options = attrs.extract_options!
5
+
6
+ id = 'pf_' + SecureRandom.hex(10)
7
+
8
+ out = content_tag(:div, :id => id + '_form', :style => 'display:none;') do
9
+ form_for(*attrs, options.dup, &(Proc.new {}))
10
+ end
11
+
12
+ form_content = fields_for(*attrs, options.dup, &block)
13
+
14
+ out << content_tag(:div, form_content, :class => options[:html][:class] + ' js-protected-form', :id => id)
15
+ out.html_safe
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ module ProtectedForm
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,11 @@
1
+ require 'action_view'
2
+ require "protected_form/version"
3
+ require "protected_form/helpers"
4
+ require "protected_form/engine"
5
+
6
+ module ProtectedForm
7
+ end
8
+
9
+ ActiveSupport.on_load(:action_view) do
10
+ include ProtectedForm::Helpers
11
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "protected_form/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "protected_form"
7
+ spec.version = ProtectedForm::VERSION
8
+ spec.authors = ["Alexandr Subbotin"]
9
+ spec.email = ["kelionweb@gmail.com"]
10
+ spec.summary = %q{Spam protection for rails forms}
11
+ spec.description = %q{Simple wrapper for `form_for` with javascript form submission with changing html structure of form.}
12
+ spec.homepage = "http://github.com/KELiON/protected_form"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = []
18
+ spec.require_paths = ["lib"]
19
+ end
@@ -0,0 +1,52 @@
1
+ ;(function(window, undefined){
2
+
3
+ var matches;
4
+
5
+ (function(doc) {
6
+ matches =
7
+ doc.matchesSelector ||
8
+ doc.webkitMatchesSelector ||
9
+ doc.mozMatchesSelector ||
10
+ doc.oMatchesSelector ||
11
+ doc.msMatchesSelector;
12
+ })(document.documentElement);
13
+
14
+ // simple implementation of $(document).delegate
15
+ function delegate(event, selector, callback) {
16
+ document.addEventListener(event, function(e){
17
+ if (matches.call(e.target, selector)) {
18
+ callback.call(e.target, e);
19
+ }
20
+ });
21
+ }
22
+
23
+ //Form Submit
24
+ function sendProtectedForm() {
25
+ // looking for closest .js-protected-form block
26
+ var container = this;
27
+ do {
28
+ container = container.parentNode;
29
+ }
30
+ while (!container.className.match('js-protected-form'));
31
+ var form = document.getElementById(container.id + '_form').firstChild;
32
+ var submitEvent = new Event('submit', {
33
+ 'bubbles' : true,
34
+ 'cancelable' : true
35
+ });
36
+
37
+ // change html structure: return content into form
38
+ container.parentNode.insertBefore(form, container[0]);
39
+ form.firstChild.appendChild(container);
40
+
41
+ // and than trigger submit for this form
42
+ form.dispatchEvent(submitEvent);
43
+ return false;
44
+ }
45
+
46
+ delegate('click', '.js-protected-form input[type=submit]', sendProtectedForm);
47
+ delegate('keyup', '.js-protected-form input[type=text], .js-protected-form input[type=email]', function(e){
48
+ if (e.keyCode == 13) {
49
+ sendProtectedForm.call(e.target);
50
+ }
51
+ });
52
+ }(this));
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: protected_form
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Alexandr Subbotin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-12 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Simple wrapper for `form_for` with javascript form submission with changing
14
+ html structure of form.
15
+ email:
16
+ - kelionweb@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".gitignore"
22
+ - Gemfile
23
+ - LICENSE.txt
24
+ - README.md
25
+ - Rakefile
26
+ - lib/protected_form.rb
27
+ - lib/protected_form/engine.rb
28
+ - lib/protected_form/helpers.rb
29
+ - lib/protected_form/version.rb
30
+ - protected_form.gemspec
31
+ - vendor/assets/javascripts/protected_form.js
32
+ homepage: http://github.com/KELiON/protected_form
33
+ licenses:
34
+ - MIT
35
+ metadata: {}
36
+ post_install_message:
37
+ rdoc_options: []
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements: []
51
+ rubyforge_project:
52
+ rubygems_version: 2.2.2
53
+ signing_key:
54
+ specification_version: 4
55
+ summary: Spam protection for rails forms
56
+ test_files: []