midas-g_live_validator 1.0.3
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.
- data/History.txt +12 -0
- data/Manifest.txt +22 -0
- data/PostInstall.txt +7 -0
- data/README.rdoc +83 -0
- data/Rakefile +30 -0
- data/lib/g_live_validator/active_record_extensions.rb +72 -0
- data/lib/g_live_validator/view_helpers.rb +181 -0
- data/lib/g_live_validator.rb +19 -0
- data/live_validator.gemspec +41 -0
- data/rails_generators/live_validator_assets/live_validator_assets_generator.rb +17 -0
- data/rails_generators/live_validator_assets/templates/default.css +23 -0
- data/rails_generators/live_validator_assets/templates/guilded.live_validator.js +84 -0
- data/rails_generators/live_validator_assets/templates/guilded.live_validator.min.js +18 -0
- data/rails_generators/live_validator_assets/templates/livevalidation-1.3.js +884 -0
- data/rails_generators/live_validator_assets/templates/livevalidation-1.3.min.js +4 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/spec/live_validator_spec.rb +11 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +10 -0
- data/tasks/rspec.rake +21 -0
- metadata +118 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
History.txt
|
2
|
+
Manifest.txt
|
3
|
+
PostInstall.txt
|
4
|
+
README.rdoc
|
5
|
+
Rakefile
|
6
|
+
lib/g_live_validator.rb
|
7
|
+
lib/g_live_validator/active_record_extensions.rb
|
8
|
+
lib/g_live_validator/view_helpers.rb
|
9
|
+
live_validator.gemspec
|
10
|
+
rails_generators/live_validator_assets/live_validator_assets_generator.rb
|
11
|
+
rails_generators/live_validator_assets/templates/default.css
|
12
|
+
rails_generators/live_validator_assets/templates/guilded.live_validator.js
|
13
|
+
rails_generators/live_validator_assets/templates/guilded.live_validator.min.js
|
14
|
+
rails_generators/live_validator_assets/templates/livevalidation-1.3.js
|
15
|
+
rails_generators/live_validator_assets/templates/livevalidation-1.3.min.js
|
16
|
+
script/console
|
17
|
+
script/destroy
|
18
|
+
script/generate
|
19
|
+
spec/live_validator_spec.rb
|
20
|
+
spec/spec.opts
|
21
|
+
spec/spec_helper.rb
|
22
|
+
tasks/rspec.rake
|
data/PostInstall.txt
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
= live_validator
|
2
|
+
|
3
|
+
http://github.com/midas/live_validator/tree/master
|
4
|
+
|
5
|
+
|
6
|
+
== DESCRIPTION:
|
7
|
+
|
8
|
+
Live validator is a Rails Guilded (http://github.com/midas/guilded/tree/master) component that will reflect ActiveRecord validations
|
9
|
+
and use them to live validate forms. Live validator uses the Live Validation (http://www.livevalidation.com) JavaScript library to
|
10
|
+
accomplish this task. It also uses an ActiveRecord extension authored by Michael Schuerig to mre easily reflect on the ActiveRecord
|
11
|
+
valdiations.
|
12
|
+
|
13
|
+
|
14
|
+
== FEATURES:
|
15
|
+
|
16
|
+
* Validate Rails XHTML forms without submitting form to server.
|
17
|
+
* Declare validations once in ActiveRecord model's. If JavaScript is enabled, the validation will happen live. Otherwise,
|
18
|
+
the validation will happen normally, with a submission to the server.
|
19
|
+
* The error message defined in the validation macro will be used in live validation
|
20
|
+
* The following ActiveRecrod validations are currently implemented and working: validates_presence_of (:message),
|
21
|
+
validates_numericality_of (:less_than, :less_than_or_equal_to, :equal_to, :greater_than, :greater_then_or_equal_to,
|
22
|
+
:only_integer, :notANumberMessage, :notAnIntegerMessage, :wrongNumberMessage, :tooLowMessage, :tooHighMessage),
|
23
|
+
validates_length_of / validates_size_of (:maximum, :minimum, :is, :within, :in, :too_long, :too_short, :wrong_length),
|
24
|
+
validates_confirmation_of (Only works for 2 fields, no more nor less.), validates_acceptance_of (:message),
|
25
|
+
validates_inclusion_of (:message), validates_exclusion_of (:message)
|
26
|
+
|
27
|
+
==PROBLEMS:
|
28
|
+
|
29
|
+
|
30
|
+
== INSTALL:
|
31
|
+
|
32
|
+
sudo gem install midas-live_validator
|
33
|
+
|
34
|
+
|
35
|
+
== USE:
|
36
|
+
|
37
|
+
Add gem requirement to your environment.rb file:
|
38
|
+
|
39
|
+
config.gem 'midas-live_validator', :version => '1.0.3', :lib => 'live_validator', :source => 'http://gems.github.com'
|
40
|
+
|
41
|
+
Generate the assets for live validator:
|
42
|
+
|
43
|
+
script/generate live_validator_assets
|
44
|
+
|
45
|
+
Make a call to the view_helper within a form:
|
46
|
+
|
47
|
+
<%= g_live_validator f %> # where f is the form variable passed into the form_for block
|
48
|
+
|
49
|
+
|
50
|
+
== OPTIONS:
|
51
|
+
|
52
|
+
:except - List of fields not to validate. Foreign key fields (that end in _id) are automatically excluded. Can be a string,
|
53
|
+
symbol or an array of string or sybmols.
|
54
|
+
|
55
|
+
== REQUIREMENTS:
|
56
|
+
|
57
|
+
* Guilded >= 0.1.3 (http://github.com/midas/guilded/tree/master)
|
58
|
+
* Rails >= 2.0
|
59
|
+
|
60
|
+
== LICENSE:
|
61
|
+
|
62
|
+
(The MIT License)
|
63
|
+
|
64
|
+
Copyright (c) 2009 midas (excluding included material copyrighted by others)
|
65
|
+
|
66
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
67
|
+
a copy of this software and associated documentation files (the
|
68
|
+
'Software'), to deal in the Software without restriction, including
|
69
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
70
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
71
|
+
permit persons to whom the Software is furnished to do so, subject to
|
72
|
+
the following conditions:
|
73
|
+
|
74
|
+
The above copyright notice and this permission notice shall be
|
75
|
+
included in all copies or substantial portions of the Software.
|
76
|
+
|
77
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
78
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
79
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
80
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
81
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
82
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
83
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
%w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f }
|
2
|
+
require File.dirname(__FILE__) + '/lib/g_live_validator'
|
3
|
+
|
4
|
+
# Generate all the Rake tasks
|
5
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
6
|
+
$hoe = Hoe.new('g_live_validator', GLiveValidator::VERSION) do |p|
|
7
|
+
p.developer('C. Jason Harrelson (midas)', 'jason@lookforwardenterprises.com')
|
8
|
+
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
9
|
+
p.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
|
10
|
+
p.rubyforge_name = p.name # TODO this is default value
|
11
|
+
# p.extra_deps = [
|
12
|
+
# ['activesupport','>= 2.0.2'],
|
13
|
+
# ]
|
14
|
+
p.extra_dev_deps = [
|
15
|
+
['newgem', ">= #{::Newgem::VERSION}"],
|
16
|
+
['rails', ">= 2.2.0"],
|
17
|
+
['midas-guilded', ">=0.1.4"]
|
18
|
+
]
|
19
|
+
|
20
|
+
p.clean_globs |= %w[**/.DS_Store tmp *.log]
|
21
|
+
path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
|
22
|
+
p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
|
23
|
+
p.rsync_args = '-av --delete --ignore-errors'
|
24
|
+
end
|
25
|
+
|
26
|
+
require 'newgem/tasks' # load /tasks/*.rake
|
27
|
+
Dir['tasks/**/*.rake'].each { |t| load t }
|
28
|
+
|
29
|
+
# TODO - want other tests/tasks run by default? Add them to the list
|
30
|
+
# task :default => [:spec, :features]
|
@@ -0,0 +1,72 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2006, Michael Schuerig, michael@schuerig.de
|
3
|
+
#
|
4
|
+
# == License
|
5
|
+
# This library is free software; you can redistribute it and/or
|
6
|
+
# modify it under the terms of the GNU Lesser General Public
|
7
|
+
# License as published by the Free Software Foundation; either
|
8
|
+
# version 2.1 of the License, or (at your option) any later version.
|
9
|
+
# See http://www.gnu.org/copyleft/lesser.html
|
10
|
+
#++
|
11
|
+
require 'active_record/reflection'
|
12
|
+
|
13
|
+
module GLiveValidator # :nodoc:
|
14
|
+
module ActiveRecordExtensions # :nodoc:
|
15
|
+
module ValidationReflection # :nodoc:
|
16
|
+
|
17
|
+
VALIDATIONS = %w(
|
18
|
+
validates_acceptance_of
|
19
|
+
validates_associated
|
20
|
+
validates_confirmation_of
|
21
|
+
validates_exclusion_of
|
22
|
+
validates_format_of
|
23
|
+
validates_inclusion_of
|
24
|
+
validates_length_of
|
25
|
+
validates_size_of
|
26
|
+
validates_numericality_of
|
27
|
+
validates_presence_of
|
28
|
+
validates_uniqueness_of
|
29
|
+
).freeze
|
30
|
+
|
31
|
+
def self.included( base )
|
32
|
+
base.extend( ClassMethods )
|
33
|
+
|
34
|
+
for validation_type in VALIDATIONS
|
35
|
+
base.module_eval <<-"end_eval"
|
36
|
+
class << self
|
37
|
+
alias_method :#{validation_type}_without_reflection, :#{validation_type}
|
38
|
+
|
39
|
+
def #{validation_type}_with_reflection(*attr_names)
|
40
|
+
#{validation_type}_without_reflection(*attr_names)
|
41
|
+
configuration = attr_names.last.is_a?(Hash) ? attr_names.pop : nil
|
42
|
+
for attr_name in attr_names
|
43
|
+
write_inheritable_array "validations", [ ActiveRecord::Reflection::MacroReflection.new(:#{validation_type}, attr_name, configuration, self) ]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
alias_method :#{validation_type}, :#{validation_type}_with_reflection
|
48
|
+
end
|
49
|
+
end_eval
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
module ClassMethods
|
54
|
+
|
55
|
+
# Returns an array of MacroReflection objects for all validations in the class
|
56
|
+
def reflect_on_all_validations
|
57
|
+
read_inheritable_attribute( "validations" ) || []
|
58
|
+
end
|
59
|
+
|
60
|
+
# Returns an array of MacroReflection objects for all validations defined for the field +attr_name+ (expects a symbol)
|
61
|
+
def reflect_on_validations_for( attr_name )
|
62
|
+
reflect_on_all_validations.find_all do |reflection|
|
63
|
+
reflection.name.to_s == attr_name.to_s
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,181 @@
|
|
1
|
+
module GLiveValidator
|
2
|
+
module ViewHelpers
|
3
|
+
|
4
|
+
G_VALIDATION_METHODS = {
|
5
|
+
:presence => "Validate.Presence",
|
6
|
+
:numericality => "Validate.Numericality",
|
7
|
+
:format => "Validate.Format",
|
8
|
+
:length => "Validate.Length",
|
9
|
+
:size => "Validate.Length",
|
10
|
+
:acceptance => "Validate.Acceptance",
|
11
|
+
:confirmation => "Validate.Confirmation",
|
12
|
+
:exclusion => "Validate.Exclusion"
|
13
|
+
}
|
14
|
+
|
15
|
+
# Guilded component. This reads from the server side validations and sets up client side
|
16
|
+
# validations that match utilizing the Live Validation library. The following validation
|
17
|
+
# macros and args are implemented:
|
18
|
+
#
|
19
|
+
# validates_presence_of - :message
|
20
|
+
# validates_numericality_of - :less_than, :less_than_or_equal_to, :equal_to, :greater_than,
|
21
|
+
# :greater_then_or_equal_to, :only_integer, :notANumberMessage, :notAnIntegerMessage,
|
22
|
+
# :wrongNumberMessage, :tooLowMessage, :tooHighMessage
|
23
|
+
# validates_length_of / validates_size_of - :maximum, :minimum, :is, :within, :in, :too_long,
|
24
|
+
# :too_short, :wrong_length
|
25
|
+
# validates_confirmation_of - Only works for 2 fields, no more or less.
|
26
|
+
# validates_acceptance_of - :message
|
27
|
+
# validates_inclusion_of - :message
|
28
|
+
# validates_exclusion_of - :message
|
29
|
+
#
|
30
|
+
# If you need to do custom initialization you can implement g.beforeLiveValidatorInit() or
|
31
|
+
# g.afterLiveValidatorInit().
|
32
|
+
#
|
33
|
+
# If you need custom handling of valid or invalid fields, you can implement g.liveValidatorInvalidField()
|
34
|
+
# or g. liveValidatorValidField().
|
35
|
+
#
|
36
|
+
# *parameters*
|
37
|
+
# form:: The form object from the form_for helper.
|
38
|
+
#
|
39
|
+
# *options*
|
40
|
+
# id:: (required)
|
41
|
+
# except:: List of fields to not include. A string, symbol or array of strings or symbols.
|
42
|
+
#
|
43
|
+
def g_live_validator( form, *args )
|
44
|
+
options = args.extract_options!
|
45
|
+
klass = form.object.class
|
46
|
+
class_name = klass.to_s.downcase
|
47
|
+
options.merge! :id => "live-validator-#{class_name}"
|
48
|
+
ar_obj_name = form.object.class.to_s.underscore
|
49
|
+
|
50
|
+
# TODO: Add human names to options
|
51
|
+
#options.merge! :human_names => form.object
|
52
|
+
|
53
|
+
validations = g_map_validations( klass.reflect_on_all_validations )
|
54
|
+
|
55
|
+
# Remove any foreign keys as they will not be present on the form
|
56
|
+
validations.reject! { |field, validation| field.include?( "_id" ) }
|
57
|
+
|
58
|
+
# Remove any excepts, if necessary
|
59
|
+
if options[:except]
|
60
|
+
if options[:except].is_a?( Array )
|
61
|
+
excepts = options[:except]
|
62
|
+
elsif options[:except].is_a?( String ) || options[:except].is_a?( Symbol )
|
63
|
+
excepts = Array.new << options[:except]
|
64
|
+
else
|
65
|
+
throw "'Except' option must be a string symbol or arry of strings or symbols"
|
66
|
+
end
|
67
|
+
|
68
|
+
# Add the AR object name to the field name, as Rails does this on forms
|
69
|
+
excepts.map! { |except| "#{ar_obj_name}_#{except.to_s}" }
|
70
|
+
|
71
|
+
excepts.each do |except|
|
72
|
+
validations.reject! { |field, validation| field == except }
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# Handle nested form namings, if necessary
|
77
|
+
if form.object.class.to_s.underscore != form.object_name
|
78
|
+
#field_precursor = form.object_name.gsub( /\[/, '_' ).gsub( /\]/, '_' )
|
79
|
+
field_precursor = form.object_name[0...form.object_name.index( "[" )] + '_'
|
80
|
+
nested_validations = Hash.new
|
81
|
+
validations.each do |key, value|
|
82
|
+
nested_validations[ "#{field_precursor}#{key}".to_sym ] = value
|
83
|
+
end
|
84
|
+
validations = nested_validations
|
85
|
+
end
|
86
|
+
|
87
|
+
options.merge! :validations => validations
|
88
|
+
Guilded::Guilder.instance.add( :live_validator, options, [ 'livevalidation-1.3.min.js' ] )
|
89
|
+
return ""
|
90
|
+
end
|
91
|
+
|
92
|
+
private
|
93
|
+
|
94
|
+
def g_map_validations( validation_defs )
|
95
|
+
validations = {}
|
96
|
+
confirmation_of = []
|
97
|
+
|
98
|
+
validation_defs.each do |validation_def|
|
99
|
+
klass = validation_def.active_record.to_s.underscore
|
100
|
+
temp = { :name => validation_def.macro }
|
101
|
+
options = {}
|
102
|
+
|
103
|
+
unless validation_def.options.nil?
|
104
|
+
|
105
|
+
validation_def.options.each do |key, value|
|
106
|
+
if key == :greater_than
|
107
|
+
options.merge!( :minimum => value + 1 )
|
108
|
+
elsif key == :greater_than_or_equal_to
|
109
|
+
options.merge!( :minimum => value )
|
110
|
+
elsif key == :equal_to
|
111
|
+
options.merge!( :is => value )
|
112
|
+
elsif key == :less_than
|
113
|
+
options.merge!( :maximum => value - 1 )
|
114
|
+
elsif key == :less_than_or_equal_to
|
115
|
+
options.merge!( :maximum => value )
|
116
|
+
elsif ( key == :within || key == :in ) && validation_def.macro == :validates_length_of
|
117
|
+
options.merge!( :minimum => value.begin )
|
118
|
+
options.merge!( :maximum => value.end )
|
119
|
+
elsif ( validation_def.macro == :validates_inclusion_of || validation_def.macro == :validates_exclusion_of ) && key == :in
|
120
|
+
if value.is_a?( Array )
|
121
|
+
options.merge!( :within => value )
|
122
|
+
else
|
123
|
+
options.merge!( :within => value.to_a )
|
124
|
+
end
|
125
|
+
elsif key == :message
|
126
|
+
options.merge!( :failureMessage => value )
|
127
|
+
elsif key == :allow_nil
|
128
|
+
options.merge!( :allowNull => value )
|
129
|
+
elsif key == :wrong_length
|
130
|
+
options.merge!( :wrongLengthMessage => value )
|
131
|
+
elsif key == :too_long
|
132
|
+
options.merge!( :tooLongMessage => value )
|
133
|
+
elsif key == :too_short
|
134
|
+
options.merge!( :tooShortMessage => value )
|
135
|
+
else
|
136
|
+
options.merge!( key.to_s.camelize( :lower ) => value )
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
temp.merge!( :args => options )
|
141
|
+
|
142
|
+
end
|
143
|
+
|
144
|
+
# Handle validatesconfirmation_of
|
145
|
+
if validation_def.macro.to_sym == :validates_confirmation_of
|
146
|
+
|
147
|
+
confirmation_of.push( validation_def.name )
|
148
|
+
|
149
|
+
if confirmation_of.size ==2
|
150
|
+
key = "#{klass}_#{confirmation_of[1]}"
|
151
|
+
|
152
|
+
temp[:args] = {} if temp[:options].nil?
|
153
|
+
|
154
|
+
temp[:args].merge! :match => "#{klass}_#{confirmation_of[0]}"
|
155
|
+
|
156
|
+
if validations.has_key?( key )
|
157
|
+
validations[key].push( temp )
|
158
|
+
else
|
159
|
+
validations[key] = [ temp ]
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
else # Handle others
|
164
|
+
|
165
|
+
key = "#{klass}_#{validation_def.name}"
|
166
|
+
|
167
|
+
if validations.has_key?( key )
|
168
|
+
validations[key].push( temp )
|
169
|
+
else
|
170
|
+
validations[key] = [ temp ]
|
171
|
+
end
|
172
|
+
|
173
|
+
end
|
174
|
+
|
175
|
+
end
|
176
|
+
|
177
|
+
return validations
|
178
|
+
end
|
179
|
+
|
180
|
+
end
|
181
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
|
4
|
+
require 'g_live_validator/view_helpers'
|
5
|
+
require 'g_live_validator/active_record_extensions'
|
6
|
+
|
7
|
+
module GLiveValidator
|
8
|
+
VERSION = '1.0.3'
|
9
|
+
end
|
10
|
+
|
11
|
+
if defined?( ActiveRecord::Base )
|
12
|
+
ActiveRecord::Base.class_eval do
|
13
|
+
include GLiveValidator::ActiveRecordExtensions::ValidationReflection
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
if defined?( ActionView::Base )
|
18
|
+
ActionView::Base.send( :include, GLiveValidator::ViewHelpers ) unless ActionView::Base.include?( GLiveValidator::ViewHelpers )
|
19
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{live_validator}
|
5
|
+
s.version = "1.0.2"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["C. Jason Harrelson (midas)"]
|
9
|
+
s.date = %q{2009-03-13}
|
10
|
+
s.description = %q{Live validator is a Rails Guilded (http://github.com/midas/guilded/tree/master) component that will reflect ActiveRecord validations and use them to live validate forms. Live validator uses the Live Validation (http://www.livevalidation.com) JavaScript library to accomplish this task. It also uses an ActiveRecord extension authored by Michael Schuerig to mre easily reflect on the ActiveRecord valdiations.}
|
11
|
+
s.email = ["jason@lookforwardenterprises.com"]
|
12
|
+
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "PostInstall.txt", "README.rdoc"]
|
13
|
+
s.files = ["History.txt", "Manifest.txt", "PostInstall.txt", "README.rdoc", "Rakefile", "lib/live_validator.rb", "lib/live_validator/active_record_extensions.rb", "lib/live_validator/view_helpers.rb", "live_validator.gemspec", "rails_generators/live_validator_assets/live_validator_assets_generator.rb", "rails_generators/live_validator_assets/templates/default.css", "rails_generators/live_validator_assets/templates/guilded.live_validator.js", "rails_generators/live_validator_assets/templates/guilded.live_validator.min.js", "rails_generators/live_validator_assets/templates/livevalidation-1.3.min.js", "script/console", "script/destroy", "script/generate", "spec/live_validator_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "tasks/rspec.rake"]
|
14
|
+
s.has_rdoc = true
|
15
|
+
s.homepage = %q{http://github.com/midas/live_validator/tree/master}
|
16
|
+
s.post_install_message = %q{PostInstall.txt}
|
17
|
+
s.rdoc_options = ["--main", "README.rdoc"]
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
s.rubyforge_project = %q{live_validator}
|
20
|
+
s.rubygems_version = %q{1.3.1}
|
21
|
+
s.summary = %q{Live validator is a Rails Guilded (http://github.com/midas/guilded/tree/master) component that will reflect ActiveRecord validations and use them to live validate forms}
|
22
|
+
|
23
|
+
if s.respond_to? :specification_version then
|
24
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
25
|
+
s.specification_version = 2
|
26
|
+
|
27
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
28
|
+
s.add_development_dependency(%q<newgem>, [">= 1.2.3"])
|
29
|
+
s.add_development_dependency(%q<midas-guilded>, [">= 0.1.3"])
|
30
|
+
s.add_development_dependency(%q<hoe>, [">= 1.8.0"])
|
31
|
+
else
|
32
|
+
s.add_dependency(%q<newgem>, [">= 1.2.3"])
|
33
|
+
s.add_dependency(%q<midas-guilded>, [">= 0.1.3"])
|
34
|
+
s.add_dependency(%q<hoe>, [">= 1.8.0"])
|
35
|
+
end
|
36
|
+
else
|
37
|
+
s.add_dependency(%q<newgem>, [">= 1.2.3"])
|
38
|
+
s.add_dependency(%q<midas-guilded>, [">= 0.1.3"])
|
39
|
+
s.add_dependency(%q<hoe>, [">= 1.8.0"])
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class LiveValidatorAssetsGenerator < Rails::Generator::Base
|
2
|
+
def initialize(runtime_args, runtime_options = {})
|
3
|
+
super
|
4
|
+
end
|
5
|
+
|
6
|
+
def manifest
|
7
|
+
record do |m|
|
8
|
+
m.file "guilded.live_validator.js", "public/javascripts/guilded.live_validator.js"
|
9
|
+
m.file "guilded.live_validator.min.js", "public/javascripts/guilded.live_validator.min.js"
|
10
|
+
m.file "livevalidation-1.3.min.js", "public/javascripts/livevalidation-1.3.min.js"
|
11
|
+
m.file "livevalidation-1.3.js", "public/javascripts/livevalidation-1.3.js"
|
12
|
+
m.directory "public/stylesheets/guilded/live_validator"
|
13
|
+
m.directory "public/stylesheets/guilded/live_validator/default"
|
14
|
+
m.file "default.css", "public/stylesheets/guilded/live_validator/default.css"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
.LV_valid { color:#00CC00; }
|
2
|
+
.LV_invalid { color:#CC0000; }
|
3
|
+
.LV_validation_message{ margin:0 0 0 5px; }
|
4
|
+
.LV_valid_field,
|
5
|
+
input.LV_valid_field:hover,
|
6
|
+
input.LV_valid_field:active,
|
7
|
+
textarea.LV_valid_field:hover,
|
8
|
+
textarea.LV_valid_field:active,
|
9
|
+
.fieldWithErrors input.LV_valid_field,
|
10
|
+
.fieldWithErrors textarea.LV_valid_field {
|
11
|
+
border:1px solid #00CC00 !important;
|
12
|
+
}
|
13
|
+
.LV_invalid_field,
|
14
|
+
input.LV_invalid_field:hover,
|
15
|
+
input.LV_invalid_field:active,
|
16
|
+
textarea.LV_invalid_field:hover,
|
17
|
+
textarea.LV_invalid_field:active,
|
18
|
+
.fieldWithErrors input.LV_invalid_field,
|
19
|
+
.fieldWithErrors textarea.LV_invalid_field {
|
20
|
+
border:1px solid #CC0000 !important;
|
21
|
+
}
|
22
|
+
li.error { background:#f6c1b5; border:1px solid #9e0b0f !important; }
|
23
|
+
li.error span.note { color:#9e0b0f; font-weight:bold; }
|
@@ -0,0 +1,84 @@
|
|
1
|
+
/* Guilded Live Validator 1.0.1
|
2
|
+
* Copyright (c) 2009 C. Jason Harrelson (midas)
|
3
|
+
* Guilded Live Validator is licensed under the terms of the MIT License */
|
4
|
+
|
5
|
+
g.liveValidationsByField = {}; /* The collection of live validation objects indexed by field names */
|
6
|
+
g.liveValidations = []; /* The collection of live validation objects */
|
7
|
+
|
8
|
+
g.doInvalidField = function()
|
9
|
+
{
|
10
|
+
if( g.liveValidatorInvalidField )
|
11
|
+
{
|
12
|
+
g.liveValidatorInvalidField( this );
|
13
|
+
}
|
14
|
+
else
|
15
|
+
{
|
16
|
+
this.insertMessage( this.createMessageSpan() );
|
17
|
+
this.addFieldClass();
|
18
|
+
}
|
19
|
+
};
|
20
|
+
|
21
|
+
g.doValidField = function()
|
22
|
+
{
|
23
|
+
if( g.liveValidatorValidField )
|
24
|
+
g.liveValidatorValidField( this );
|
25
|
+
else
|
26
|
+
{
|
27
|
+
this.insertMessage( this.createMessageSpan() );
|
28
|
+
this.addFieldClass();
|
29
|
+
}
|
30
|
+
};
|
31
|
+
|
32
|
+
g.liveValidatorInit = function( options )
|
33
|
+
{
|
34
|
+
if( g.beforeLiveValidatorInit )
|
35
|
+
g.beforeLiveValidatorInit( options );
|
36
|
+
|
37
|
+
var moreValidationMethods = {
|
38
|
+
presence: Validate.Presence,
|
39
|
+
numericality: Validate.Numericality,
|
40
|
+
format: Validate.Format,
|
41
|
+
length: Validate.Length,
|
42
|
+
acceptance: Validate.Acceptance,
|
43
|
+
confirmation: Validate.Confirmation
|
44
|
+
};
|
45
|
+
|
46
|
+
var validationMethods = {
|
47
|
+
validates_presence_of: Validate.Presence,
|
48
|
+
validates_numericality_of: Validate.Numericality,
|
49
|
+
validates_format_of: Validate.Format,
|
50
|
+
validates_length_of: Validate.Length,
|
51
|
+
validates_size_of: Validate.Length,
|
52
|
+
validates_acceptance_of: Validate.Acceptance,
|
53
|
+
validates_confirmation_of: Validate.Confirmation,
|
54
|
+
validates_inclusion_of: Validate.Inclusion,
|
55
|
+
validates_exclusion_of: Validate.Exclusion
|
56
|
+
};
|
57
|
+
|
58
|
+
var validations = options[ 'validations' ];
|
59
|
+
|
60
|
+
for( field in validations )
|
61
|
+
{
|
62
|
+
/* Guard against fields that we cannot find throwing errors. Just don't
|
63
|
+
* attach if you cannot find it. */
|
64
|
+
fieldEl = $j( '#' + field );
|
65
|
+
if( fieldEl.length == 0 )
|
66
|
+
continue;
|
67
|
+
|
68
|
+
var vList = validations[ field ];
|
69
|
+
var v = null;
|
70
|
+
|
71
|
+
v = new LiveValidation( field, { onlyOnBlur:true, onInvalid:g.doInvalidField, onValid:g.doValidField } );
|
72
|
+
|
73
|
+
for( var i=0; i<vList.length; i++ )
|
74
|
+
{
|
75
|
+
var validation = vList[i];
|
76
|
+
v.add( validationMethods[ validation.name ], validation.args );
|
77
|
+
g.liveValidationsByField[field] = v;
|
78
|
+
g.liveValidations.push( v );
|
79
|
+
}
|
80
|
+
}
|
81
|
+
|
82
|
+
if( g.afterLiveValidatorInit )
|
83
|
+
g.afterLiveValidatorInit( options );
|
84
|
+
};
|
@@ -0,0 +1,18 @@
|
|
1
|
+
/* Guilded Live Validator 1.0.1
|
2
|
+
* Copyright (c) 2009 C. Jason Harrelson (midas)
|
3
|
+
* Guilded Live Validator is licensed under the terms of the MIT License */
|
4
|
+
g.doInvalidField=function()
|
5
|
+
{if(g.liveValidatorInvalidField)
|
6
|
+
{g.liveValidatorInvalidField(this);}
|
7
|
+
else
|
8
|
+
{this.insertMessage(this.createMessageSpan());this.addFieldClass();}};g.doValidField=function()
|
9
|
+
{if(g.liveValidatorValidField)
|
10
|
+
g.liveValidatorValidField(this);else
|
11
|
+
{this.insertMessage(this.createMessageSpan());this.addFieldClass();}};g.liveValidatorInit=function(options)
|
12
|
+
{if(g.beforeLiveValidatorInit)
|
13
|
+
g.beforeLiveValidatorInit(options);var moreValidationMethods={presence:Validate.Presence,numericality:Validate.Numericality,format:Validate.Format,length:Validate.Length,acceptance:Validate.Acceptance,confirmation:Validate.Confirmation};var validationMethods={validates_presence_of:Validate.Presence,validates_numericality_of:Validate.Numericality,validates_format_of:Validate.Format,validates_length_of:Validate.Length,validates_size_of:Validate.Length,validates_acceptance_of:Validate.Acceptance,validates_confirmation_of:Validate.Confirmation,validates_inclusion_of:Validate.Inclusion,validates_exclusion_of:Validate.Exclusion};var validations=options['validations'];for(field in validations)
|
14
|
+
{fieldEl=$j('#'+field);if(fieldEl.length==0)
|
15
|
+
continue;var vList=validations[field];var v=null;v=new LiveValidation(field,{onlyOnBlur:true,onInvalid:g.doInvalidField,onValid:g.doValidField});for(var i=0;i<vList.length;i++)
|
16
|
+
{var validation=vList[i];v.add(validationMethods[validation.name],validation.args);}}
|
17
|
+
if(g.afterLiveValidatorInit)
|
18
|
+
g.afterLiveValidatorInit(options);};
|