judge-simple_form 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +5 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +20 -0
- data/README.md +19 -0
- data/Rakefile +6 -0
- data/judge-simple_form.gemspec +28 -0
- data/lib/judge/simple_form.rb +21 -0
- data/lib/judge/simple_form/version.rb +5 -0
- data/spec/factories.rb +5 -0
- data/spec/judge-simple_form_spec.rb +21 -0
- data/spec/setup.rb +20 -0
- data/spec/spec_helper.rb +17 -0
- metadata +165 -0
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Joe Corcoran
|
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,19 @@
|
|
1
|
+
# judge-simple_form
|
2
|
+
|
3
|
+
This is an adapter gem which allows you to use [Judge](http://judge.joecorcoran.co.uk) from within your [SimpleForm](http://github.com/plataformatec/simple_form) forms.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
Do this in your Gemfile:
|
8
|
+
|
9
|
+
gem "judge-simple_form", "~> x.x.x", :require => "judge/simple_form"
|
10
|
+
|
11
|
+
Then add <code>:validate => true</code> to the input options in your views. That's all.
|
12
|
+
|
13
|
+
<%= simple_form_for(@user) do |f| %>
|
14
|
+
<%= f.input :name, :validate => true %>
|
15
|
+
<% end %>
|
16
|
+
|
17
|
+
## Judge
|
18
|
+
|
19
|
+
Judge is a client-side validation gem for Rails 3. You can read more about it at [judge.joecorcoran.co.uk](http://judge.joecorcoran.co.uk).
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "judge/simple_form/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "judge-simple_form"
|
7
|
+
s.version = Judge::SimpleForm::VERSION
|
8
|
+
s.authors = ["Joe Corcoran"]
|
9
|
+
s.email = "joe@tribesports.com"
|
10
|
+
s.homepage = "http://github.com/joecorcoran/judge-simple_form"
|
11
|
+
s.summary = "SimpleForm adapter for Judge"
|
12
|
+
s.description = "Easily add Judge client side validation to your SimpleForm forms"
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- spec/*`.split("\n")
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
|
18
|
+
s.add_runtime_dependency "judge", "~> 1.1"
|
19
|
+
s.add_runtime_dependency "simple_form", "~> 2.0"
|
20
|
+
|
21
|
+
s.add_development_dependency "rake"
|
22
|
+
s.add_development_dependency "rails", "~> 3.2"
|
23
|
+
s.add_development_dependency "sqlite3-ruby", "~> 1.3.3"
|
24
|
+
s.add_development_dependency "judge", "~> 1.1"
|
25
|
+
s.add_development_dependency "formtastic", "~> 2.0"
|
26
|
+
s.add_development_dependency "rspec", "~> 2.8"
|
27
|
+
s.add_development_dependency "factory_girl", "~> 2.6"
|
28
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "simple_form/version"
|
2
|
+
|
3
|
+
module Judge
|
4
|
+
module SimpleForm
|
5
|
+
module Inputs
|
6
|
+
|
7
|
+
def self.included(base)
|
8
|
+
base.send(:alias_method, :old_input_html_options, :input_html_options)
|
9
|
+
base.send(:alias_method, :input_html_options, :new_input_html_options)
|
10
|
+
end
|
11
|
+
|
12
|
+
def new_input_html_options
|
13
|
+
attrs = options[:validate].present? ? Judge::HTML.attrs_for(object, attribute_name) : {}
|
14
|
+
attrs.merge(old_input_html_options)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
::SimpleForm::Inputs::Base.send(:include, Judge::SimpleForm::Inputs) if defined?(::SimpleForm::Inputs::Base)
|
data/spec/factories.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Judge::SimpleForm do
|
4
|
+
let(:template) do
|
5
|
+
ActionView::Base.new(nil, {}, UsersController.new)
|
6
|
+
end
|
7
|
+
let(:builder) do
|
8
|
+
SimpleForm::FormBuilder.new(:user, FactoryGirl.build(:user), template, {}, nil)
|
9
|
+
end
|
10
|
+
let(:expected) do
|
11
|
+
/data\-validate\=\"\[.+\]\"/
|
12
|
+
end
|
13
|
+
|
14
|
+
it "adds data attribute when :validate option is true" do
|
15
|
+
builder.input(:name, :validate => true).should match expected
|
16
|
+
end
|
17
|
+
|
18
|
+
it "does not add data attribute otherwise" do
|
19
|
+
builder.input(:name).should_not match expected
|
20
|
+
end
|
21
|
+
end
|
data/spec/setup.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# setup simple schema and class
|
2
|
+
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
|
3
|
+
ActiveRecord::Schema.define(:version => 1) do
|
4
|
+
create_table :users do |t|
|
5
|
+
t.string :name
|
6
|
+
end
|
7
|
+
end
|
8
|
+
class User < ActiveRecord::Base
|
9
|
+
validates :name, :presence => true
|
10
|
+
end
|
11
|
+
|
12
|
+
# hack to stop #url_for error
|
13
|
+
module ActionDispatch::Routing::PolymorphicRoutes
|
14
|
+
def polymorphic_path(record_or_hash_or_array, options = {})
|
15
|
+
""
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class UsersController < ActionController::Base
|
20
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require "bundler/setup"
|
2
|
+
|
3
|
+
require "active_record"
|
4
|
+
require "action_view"
|
5
|
+
require "action_controller"
|
6
|
+
require "judge"
|
7
|
+
require "simple_form"
|
8
|
+
require "judge/simple_form"
|
9
|
+
require "factory_girl"
|
10
|
+
require "rspec"
|
11
|
+
|
12
|
+
require_relative "setup"
|
13
|
+
require_relative "factories"
|
14
|
+
|
15
|
+
RSpec.configure do |config|
|
16
|
+
config.color_enabled = true
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,165 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: judge-simple_form
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Joe Corcoran
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-03-06 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: judge
|
16
|
+
requirement: &2153228000 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.1'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2153228000
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: simple_form
|
27
|
+
requirement: &2153227100 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2.0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2153227100
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rake
|
38
|
+
requirement: &2153226620 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *2153226620
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rails
|
49
|
+
requirement: &2153225620 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.2'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *2153225620
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: sqlite3-ruby
|
60
|
+
requirement: &2153224740 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ~>
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 1.3.3
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *2153224740
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: judge
|
71
|
+
requirement: &2153224160 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ~>
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '1.1'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *2153224160
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: formtastic
|
82
|
+
requirement: &2153223600 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ~>
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '2.0'
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *2153223600
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: rspec
|
93
|
+
requirement: &2153222940 !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ~>
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '2.8'
|
99
|
+
type: :development
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: *2153222940
|
102
|
+
- !ruby/object:Gem::Dependency
|
103
|
+
name: factory_girl
|
104
|
+
requirement: &2153222460 !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '2.6'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: *2153222460
|
113
|
+
description: Easily add Judge client side validation to your SimpleForm forms
|
114
|
+
email: joe@tribesports.com
|
115
|
+
executables: []
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- .travis.yml
|
120
|
+
- Gemfile
|
121
|
+
- LICENSE.txt
|
122
|
+
- README.md
|
123
|
+
- Rakefile
|
124
|
+
- judge-simple_form.gemspec
|
125
|
+
- lib/judge/simple_form.rb
|
126
|
+
- lib/judge/simple_form/version.rb
|
127
|
+
- spec/factories.rb
|
128
|
+
- spec/judge-simple_form_spec.rb
|
129
|
+
- spec/setup.rb
|
130
|
+
- spec/spec_helper.rb
|
131
|
+
homepage: http://github.com/joecorcoran/judge-simple_form
|
132
|
+
licenses: []
|
133
|
+
post_install_message:
|
134
|
+
rdoc_options: []
|
135
|
+
require_paths:
|
136
|
+
- lib
|
137
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
138
|
+
none: false
|
139
|
+
requirements:
|
140
|
+
- - ! '>='
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
segments:
|
144
|
+
- 0
|
145
|
+
hash: -2996361724237842793
|
146
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
|
+
none: false
|
148
|
+
requirements:
|
149
|
+
- - ! '>='
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
segments:
|
153
|
+
- 0
|
154
|
+
hash: -2996361724237842793
|
155
|
+
requirements: []
|
156
|
+
rubyforge_project:
|
157
|
+
rubygems_version: 1.8.15
|
158
|
+
signing_key:
|
159
|
+
specification_version: 3
|
160
|
+
summary: SimpleForm adapter for Judge
|
161
|
+
test_files:
|
162
|
+
- spec/factories.rb
|
163
|
+
- spec/judge-simple_form_spec.rb
|
164
|
+
- spec/setup.rb
|
165
|
+
- spec/spec_helper.rb
|