judge 2.0.6 → 2.1.0
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 +4 -4
- data/README.md +0 -2
- data/app/assets/javascripts/judge.js +10 -5
- data/lib/judge.rb +2 -1
- data/lib/judge/confirmation_validator.rb +35 -0
- data/lib/judge/form_builder.rb +4 -4
- data/lib/judge/validator_collection.rb +27 -9
- data/lib/judge/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7746ff63f79624cba084792b725bc8b70c30ec8b
|
4
|
+
data.tar.gz: fe99a88f47c70dcb900230c0d307bcbff8a8173f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0d8848464312ae4e0c2797399335b41f990f162c450698b6b74641b1efee11b8f64e6aad73a00f3cb6ab4595289f3fa8097411064713fa351dc0a7669b9019f
|
7
|
+
data.tar.gz: 15f8d536e8431785c0cde1f7125ad647a3f5d824a47b1cd59dc827685d1d6d8caffa5394b0ef63faeeb75059d7f3e04596e791111f323fcede6d4367d5d3f74f
|
data/README.md
CHANGED
@@ -2,8 +2,6 @@
|
|
2
2
|
|
3
3
|
[](http://travis-ci.org/joecorcoran/judge)
|
4
4
|
|
5
|
-
Looking for a nice open source project to contribute to? **[Maintainers needed!](https://github.com/joecorcoran/judge/issues/47)**
|
6
|
-
|
7
5
|
Judge allows easy client side form validation for Rails by porting many `ActiveModel::Validation` features to JavaScript. The most common validations work through JSON strings stored within HTML5 data attributes and are executed purely on the client side. Wherever you need to, Judge provides a simple interface for AJAX validations too.
|
8
6
|
|
9
7
|
## Rationale
|
@@ -1,4 +1,4 @@
|
|
1
|
-
// Judge 2.0
|
1
|
+
// Judge 2.1.0
|
2
2
|
// (c) 2011-2013 Joe Corcoran
|
3
3
|
// http://raw.github.com/joecorcoran/judge/master/LICENSE.txt
|
4
4
|
|
@@ -14,7 +14,7 @@
|
|
14
14
|
var judge = root.judge = {},
|
15
15
|
_ = root._;
|
16
16
|
|
17
|
-
judge.VERSION = '2.0
|
17
|
+
judge.VERSION = '2.1.0';
|
18
18
|
|
19
19
|
// Trying to be a bit more descriptive than the basic error types allow.
|
20
20
|
var DependencyError = function(message) {
|
@@ -78,7 +78,7 @@
|
|
78
78
|
var convertRegExp = function(string) {
|
79
79
|
var parts = string.slice(1, -1).split(':'),
|
80
80
|
flags = parts.shift().replace('?', ''),
|
81
|
-
source = parts.join(':').replace(/\\\\/g, '\\');
|
81
|
+
source = parts.join(':').replace(/\\\\/g, '\\').replace('\\A', '^').replace('\\z', '$');
|
82
82
|
return new RegExp(source, convertFlags(flags));
|
83
83
|
};
|
84
84
|
|
@@ -256,7 +256,12 @@
|
|
256
256
|
judge.eachValidators = {
|
257
257
|
// ActiveModel::Validations::PresenceValidator
|
258
258
|
presence: function(options, messages) {
|
259
|
-
|
259
|
+
if (this.type === 'radio') {
|
260
|
+
var is_selected = root.document.querySelectorAll('[name="'+this.name+'"]:checked').length;
|
261
|
+
return closed(is_selected ? [] : [messages.blank]);
|
262
|
+
} else {
|
263
|
+
return closed(this.value.length ? [] : [messages.blank]);
|
264
|
+
}
|
260
265
|
},
|
261
266
|
|
262
267
|
// ActiveModel::Validations::LengthValidator
|
@@ -350,7 +355,7 @@
|
|
350
355
|
// ActiveModel::Validations::ConfirmationValidator
|
351
356
|
confirmation: function(options, messages) {
|
352
357
|
var id = this.getAttribute('id'),
|
353
|
-
confId = id
|
358
|
+
confId = id.replace('_confirmation', ''),
|
354
359
|
confElem = root.document.getElementById(confId);
|
355
360
|
return closed(
|
356
361
|
this.value === confElem.value ? [] : [messages.confirmation]
|
data/lib/judge.rb
CHANGED
@@ -0,0 +1,35 @@
|
|
1
|
+
module Judge
|
2
|
+
class ConfirmationValidator
|
3
|
+
|
4
|
+
include Judge::EachValidator
|
5
|
+
|
6
|
+
attr_reader :object, :method, :amv
|
7
|
+
|
8
|
+
def initialize(object, method)
|
9
|
+
@object = object
|
10
|
+
@method = method
|
11
|
+
@amv = amv_from_original
|
12
|
+
end
|
13
|
+
|
14
|
+
def kind
|
15
|
+
@amv.kind if @amv.present?
|
16
|
+
end
|
17
|
+
|
18
|
+
def options
|
19
|
+
@amv.options if @amv.present?
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def amv_from_original
|
25
|
+
original_amv = nil
|
26
|
+
original_method = method.to_s.gsub('_confirmation', '').to_sym
|
27
|
+
object.class.validators_on(original_method).each do |v|
|
28
|
+
original_amv = v if v.class.name['ConfirmationValidator']
|
29
|
+
end
|
30
|
+
|
31
|
+
original_amv
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
data/lib/judge/form_builder.rb
CHANGED
@@ -3,8 +3,8 @@ module Judge
|
|
3
3
|
class FormBuilder < ActionView::Helpers::FormBuilder
|
4
4
|
|
5
5
|
include Judge::Html
|
6
|
-
|
7
|
-
%w{text_field text_area password_field}.each do |type|
|
6
|
+
|
7
|
+
%w{text_field text_area password_field email_field}.each do |type|
|
8
8
|
helper = <<-END
|
9
9
|
def #{type}(method, options = {})
|
10
10
|
add_validate_attr!(self.object, method, options)
|
@@ -18,7 +18,7 @@ module Judge
|
|
18
18
|
add_validate_attr!(self.object, method, options)
|
19
19
|
super
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
def check_box(method, options = {}, checked_value = "1", unchecked_value = "0")
|
23
23
|
add_validate_attr!(self.object, method, options)
|
24
24
|
super
|
@@ -62,7 +62,7 @@ module Judge
|
|
62
62
|
options_to_merge.merge! attrs_for(object, method)
|
63
63
|
end
|
64
64
|
end
|
65
|
-
|
65
|
+
|
66
66
|
end
|
67
67
|
|
68
68
|
end
|
@@ -4,12 +4,11 @@ module Judge
|
|
4
4
|
|
5
5
|
include Enumerable
|
6
6
|
|
7
|
-
attr_reader :validators
|
8
|
-
|
7
|
+
attr_reader :validators, :object, :method
|
8
|
+
|
9
9
|
def initialize(object, method)
|
10
|
-
|
11
|
-
|
12
|
-
amvs = amvs.reject { |amv| unsupported_options?(amv) && reject?(amv) != false } if Judge.config.ignore_unsupported_validators?
|
10
|
+
@object = object
|
11
|
+
@method = method
|
13
12
|
@validators = amvs.map { |amv| Judge::Validator.new(object, method, amv) }
|
14
13
|
end
|
15
14
|
|
@@ -22,11 +21,26 @@ module Judge
|
|
22
21
|
def to_json
|
23
22
|
validators.map { |v| v.to_hash }.to_json
|
24
23
|
end
|
25
|
-
|
24
|
+
|
26
25
|
protected
|
27
|
-
|
26
|
+
|
28
27
|
UNSUPPORTED_OPTIONS = [:if, :on, :unless, :tokenizer, :scope, :case_sensitive]
|
29
28
|
|
29
|
+
# returns an array of ActiveModel::Validations
|
30
|
+
# starts with all Validations attached to method and removes one that are:
|
31
|
+
# ignored based on a config
|
32
|
+
# ConfirmationValidators, which are moved directly to the confirmation method
|
33
|
+
# unsupported by Judge
|
34
|
+
# if it's a confirmation field, an AM::V like class is added to handle the confirmation validations
|
35
|
+
def amvs
|
36
|
+
amvs = object.class.validators_on(method)
|
37
|
+
amvs = amvs.reject { |amv| reject?(amv) || amv.class.name['ConfirmationValidator'] }
|
38
|
+
amvs = amvs.reject { |amv| unsupported_options?(amv) && reject?(amv) != false } if Judge.config.ignore_unsupported_validators?
|
39
|
+
amvs << Judge::ConfirmationValidator.new(object, method) if is_confirmation?
|
40
|
+
|
41
|
+
amvs
|
42
|
+
end
|
43
|
+
|
30
44
|
def unsupported_options?(amv)
|
31
45
|
unsupported = !(amv.options.keys & UNSUPPORTED_OPTIONS).empty?
|
32
46
|
return false unless unsupported
|
@@ -36,7 +50,7 @@ module Judge
|
|
36
50
|
unsupported = amv.options.keys & UNSUPPORTED_OPTIONS
|
37
51
|
unsupported.length > 1 || unsupported != [:case_sensitive] || amv.options[:case_sensitive] == false
|
38
52
|
end
|
39
|
-
|
53
|
+
|
40
54
|
# decides whether to reject a validation based on the presence of the judge option.
|
41
55
|
# return values:
|
42
56
|
# true when :judge => :ignore is present in the options
|
@@ -44,7 +58,11 @@ module Judge
|
|
44
58
|
# nil otherwise (e.g. when no :judge option or an unknown option is present)
|
45
59
|
def reject?(amv)
|
46
60
|
return unless [:force, :ignore].include?( amv.options[:judge] )
|
47
|
-
amv.options[:judge] == :ignore
|
61
|
+
amv.options[:judge] == :ignore
|
62
|
+
end
|
63
|
+
|
64
|
+
def is_confirmation?
|
65
|
+
method.to_s['_confirmation']
|
48
66
|
end
|
49
67
|
|
50
68
|
end
|
data/lib/judge/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: judge
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joe Corcoran
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -122,6 +122,7 @@ files:
|
|
122
122
|
- lib/generators/judge/install/install_generator.rb
|
123
123
|
- lib/judge.rb
|
124
124
|
- lib/judge/config.rb
|
125
|
+
- lib/judge/confirmation_validator.rb
|
125
126
|
- lib/judge/controller.rb
|
126
127
|
- lib/judge/each_validator.rb
|
127
128
|
- lib/judge/engine.rb
|