casey_jones 0.1.0 → 0.1.1

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.
@@ -4,9 +4,98 @@ class JQueryValidatingFormBuilder < ActionView::Helpers::FormBuilder
4
4
  super(object_name, object, template, options, proc)
5
5
  end
6
6
 
7
+ # Renders form fields for the named arguments, complete with divs for styling
8
+ # and labels for each field.
9
+ #
10
+ # = f.form_fields :name, :address
11
+ #
12
+ # Will output:
13
+ # <div class="field">
14
+ # <div class="fieldName">
15
+ # <label>Field Name</label>
16
+ # </div>
17
+ # <div class="fieldValue">
18
+ # <input type=... />
19
+ # </div>
20
+ # </div>
21
+ #
22
+ #
23
+ # = f.form_fields({"Edit your profile" => [:name, :address]})
24
+ #
25
+ # Will output:
26
+ # <div class="fieldGroup">
27
+ # <div class="fieldGroupTitle">Edit your profile</div>
28
+ # <div class="field">
29
+ # <div class="fieldName">
30
+ # <label>Field Name</label>
31
+ # </div>
32
+ # <div class="fieldValue">
33
+ # <input type=... />
34
+ # </div>
35
+ # </div>
36
+ # </div>
37
+ #
38
+ #
39
+ # = f.form_fields({"Edit your profile" => [{:name=>{:label=>"What is your name", :type=>:text_area}}, :address]})
40
+ #
41
+ # Will output:
42
+ # <div class="fieldGroup">
43
+ # <div class="fieldGroupTitle">Edit your profile</div>
44
+ # <div class="field">
45
+ # <div class="fieldName">
46
+ # <label>What is your name</label>
47
+ # </div>
48
+ # <div class="fieldValue">
49
+ # <textarea type=... />
50
+ # </div>
51
+ # </div>
52
+ # </div>
53
+ #
54
+ # = f.form_fields({"Edit your profile" => :profile_attributes})
55
+ #
56
+ # Will output:
57
+ # <div class="fieldGroup">
58
+ # <div class="fieldGroupTitle">Edit your profile</div>
59
+ # <div class="field">
60
+ # <div class="fieldName">
61
+ # <label>What is your name</label>
62
+ # </div>
63
+ # <div class="fieldValue">
64
+ # <textarea type=... />
65
+ # </div>
66
+ # </div>
67
+ # </div>
68
+ #
69
+ #
70
+ #
71
+ #
72
+ def form_fields(*args)
73
+ concat capture do
74
+ args.each do |arg|
75
+ if arg.is_a? Hash
76
+ arg.each do |key, value|
77
+
78
+
79
+ end
80
+ elsif arg.is_a? Array
81
+
82
+ else
83
+
84
+ end
85
+ end
86
+ end
87
+ end
88
+
7
89
  attr_accessor :form_validations
8
90
  cattr_accessor :validation_methods
9
91
 
92
+ def div_tag(contents, html_options={})
93
+ capture do
94
+ content_tag('div', contents, html_options)
95
+ end
96
+ end
97
+
98
+
10
99
  #Adds error message directly inline to a form label
11
100
  #Accepts all the options normall passed to form.label as well as:
12
101
  # :hide_errors - true if you don't want errors displayed on this label
@@ -15,7 +104,17 @@ class JQueryValidatingFormBuilder < ActionView::Helpers::FormBuilder
15
104
  #Check to see if text for this label has been supplied and humanize the field name if not.
16
105
  text = text || method.to_s.humanize
17
106
  #Get a reference to the model object
18
- object = @template.instance_variable_get("@#{@object_name}")
107
+ object_name = @object_name.to_s
108
+ if object_name.include? '['
109
+ ivar_name = '@' + @object_name[0..object_name.index('[')-1]
110
+ object = @template.instance_variable_get(ivar_name)
111
+
112
+ object_name.scan(/\[([\w_-]+)\]/) do |m|
113
+ object = object.send(m[0].gsub(/_attributes/, ''))
114
+ end
115
+ else
116
+ object = @template.instance_variable_get("@#{@object_name}")
117
+ end
19
118
 
20
119
  #Make sure we have an object and we're not told to hide errors for this label
21
120
  unless object.nil? || options[:hide_errors]
@@ -104,10 +203,13 @@ class JQueryValidatingFormBuilder < ActionView::Helpers::FormBuilder
104
203
  puts "equal_to_validator #{validation.inspect}"
105
204
  options[:equalTo] = "##{validation.other}"
106
205
  return options
206
+ },
207
+
208
+ :phone_validator => lambda{|validation, options|
209
+ options.add_class('phoneUS')
210
+ return options
107
211
  }
108
212
  }
109
-
110
-
111
213
  end
112
214
 
113
215
  module OptionsAddClass
@@ -0,0 +1,7 @@
1
+ class PhoneValidator < ActiveModel::EachValidator
2
+ def validate_each(record,attribute,value)
3
+ r= value.strip.empty? || value.gsub(/\D/, '').length.in?([9,10])
4
+ record.errors[attribute] << (options[:message] || "must have 9 or 10 numeric digits") unless r
5
+ end
6
+ end
7
+
@@ -1,5 +1,6 @@
1
1
  require 'casey_jones/validation/password_validator'
2
2
  require 'casey_jones/validation/equal_to_validator'
3
+ require 'casey_jones/validation/phone_validator'
3
4
  require 'casey_jones/validation/j_query_validator'
4
5
  require 'casey_jones/validation/sitemap_resource_validator'
5
6
  require 'casey_jones/validation/j_query_validating_form_builder'
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Tyler Gannon
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-09-08 00:00:00 -07:00
17
+ date: 2010-09-16 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
@@ -49,6 +49,7 @@ files:
49
49
  - lib/casey_jones/validation/j_query_validating_form_builder.rb
50
50
  - lib/casey_jones/validation/j_query_validator.rb
51
51
  - lib/casey_jones/validation/password_validator.rb
52
+ - lib/casey_jones/validation/phone_validator.rb
52
53
  - lib/casey_jones/validation/sitemap_parents_validator.rb
53
54
  - lib/casey_jones/validation/sitemap_resource_validator.rb
54
55
  - lib/casey_jones/validation/validation.rb