html5_validators 0.1.0 → 0.2.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.
data/README.rdoc CHANGED
@@ -75,9 +75,9 @@ http://img.skitch.com/20110516-n3jhu5m4gan8iy1j8er1qb7yfa.jpg
75
75
 
76
76
  == Supported versions
77
77
 
78
- * Ruby 1.8.7, 1.9.2, 1.9.3 (trunk)
78
+ * Ruby 1.8.7, 1.9.2, 1.9.3, 2.0 (trunk)
79
79
 
80
- * Rails 3.0.x, 3.1.beta1, 3.1 (edge)
80
+ * Rails 3.0.x, 3.1.x, 3.2.x, 4.0 (edge)
81
81
 
82
82
  * HTML5 compatible browsers
83
83
 
@@ -104,4 +104,4 @@ When accessed by an HTML5 incompatible lagacy browser, these extra attributes wi
104
104
 
105
105
  == Copyright
106
106
 
107
- Copyright (c) 2011 Asakusa.rb. See MIT-LICENSE for further details.
107
+ Copyright (c) 2011 Akira Matsuda. See MIT-LICENSE for further details.
@@ -1,40 +1,85 @@
1
+ module Html5Validators
2
+ module ActionViewExtension
3
+ def inject_required_field
4
+ if object.class.ancestors.include?(ActiveModel::Validations)
5
+ @options["required"] ||= object.class.attribute_required?(@method_name)
6
+ end
7
+ end
8
+ end
9
+ end if ActionPack::VERSION::STRING >= '4'
10
+
11
+
1
12
  module ActionView
2
13
  module Helpers
3
- class InstanceTag
4
- def to_input_field_tag_with_html5_attributes(field_type, options = {})
5
- if object.class.ancestors.include?(ActiveModel::Validations)
6
- options["required"] ||= object.class.attribute_required?(method_name)
7
- options["maxlength"] ||= object.class.attribute_maxlength(method_name)
8
- options["max"] ||= object.class.attribute_max(method_name)
9
- options["min"] ||= object.class.attribute_min(method_name)
14
+ if ActionPack::VERSION::STRING >= '4'
15
+ module Tags
16
+ class Base #:nodoc:
17
+ include Html5Validators::ActionViewExtension
10
18
  end
11
- to_input_field_tag_without_html5_attributes field_type, options
12
- end
13
- alias_method_chain :to_input_field_tag, :html5_attributes
14
19
 
15
- def to_text_area_tag_with_html5_attributes(options = {})
16
- if object.class.ancestors.include?(ActiveModel::Validations)
17
- options["required"] ||= object.class.attribute_required?(method_name)
20
+ class TextField
21
+ def render_with_html5_attributes
22
+ inject_required_field
23
+
24
+ if object.class.ancestors.include?(ActiveModel::Validations)
25
+ @options["maxlength"] ||= object.class.attribute_maxlength(@method_name)
26
+ @options["max"] ||= object.class.attribute_max(@method_name)
27
+ @options["min"] ||= object.class.attribute_min(@method_name)
28
+ end
29
+ render_without_html5_attributes
30
+ end
31
+ alias_method_chain :render, :html5_attributes
18
32
  end
19
- to_text_area_tag_without_html5_attributes options
20
- end
21
- alias_method_chain :to_text_area_tag, :html5_attributes
22
33
 
23
- def to_radio_button_tag_with_html5_attributes(tag_value, options = {})
24
- if object.class.ancestors.include?(ActiveModel::Validations)
25
- options["required"] ||= object.class.attribute_required?(method_name)
34
+ #TODO probably I have to add some more classes here
35
+ [TextArea, RadioButton, CheckBox, Select, DateSelect, TimeZoneSelect].each do |kls|
36
+ kls.class_eval do
37
+ def render_with_html5_attributes
38
+ inject_required_field
39
+ render_without_html5_attributes options
40
+ end
41
+ alias_method_chain :render, :html5_attributes
42
+ end
26
43
  end
27
- to_radio_button_tag_without_html5_attributes tag_value, options
28
44
  end
29
- alias_method_chain :to_radio_button_tag, :html5_attributes
45
+ # ActionPack::VERSION::STRING == '3'
46
+ else
47
+ class InstanceTag
48
+ def to_input_field_tag_with_html5_attributes(field_type, options = {})
49
+ if object.class.ancestors.include?(ActiveModel::Validations)
50
+ options["required"] ||= object.class.attribute_required?(method_name)
51
+ options["maxlength"] ||= object.class.attribute_maxlength(method_name)
52
+ options["max"] ||= object.class.attribute_max(method_name)
53
+ options["min"] ||= object.class.attribute_min(method_name)
54
+ end
55
+ to_input_field_tag_without_html5_attributes field_type, options
56
+ end
57
+ alias_method_chain :to_input_field_tag, :html5_attributes
58
+
59
+ def to_text_area_tag_with_html5_attributes(options = {})
60
+ if object.class.ancestors.include?(ActiveModel::Validations)
61
+ options["required"] ||= object.class.attribute_required?(method_name)
62
+ end
63
+ to_text_area_tag_without_html5_attributes options
64
+ end
65
+ alias_method_chain :to_text_area_tag, :html5_attributes
66
+
67
+ def to_radio_button_tag_with_html5_attributes(tag_value, options = {})
68
+ if object.class.ancestors.include?(ActiveModel::Validations)
69
+ options["required"] ||= object.class.attribute_required?(method_name)
70
+ end
71
+ to_radio_button_tag_without_html5_attributes tag_value, options
72
+ end
73
+ alias_method_chain :to_radio_button_tag, :html5_attributes
30
74
 
31
- def to_check_box_tag_with_html5_attributes(options = {}, checked_value = "1", unchecked_value = "0")
32
- if object.class.ancestors.include?(ActiveModel::Validations)
33
- options["required"] ||= object.class.attribute_required?(method_name)
75
+ def to_check_box_tag_with_html5_attributes(options = {}, checked_value = "1", unchecked_value = "0")
76
+ if object.class.ancestors.include?(ActiveModel::Validations)
77
+ options["required"] ||= object.class.attribute_required?(method_name)
78
+ end
79
+ to_check_box_tag_without_html5_attributes options, checked_value, unchecked_value
34
80
  end
35
- to_check_box_tag_without_html5_attributes options, checked_value, unchecked_value
81
+ alias_method_chain :to_check_box_tag, :html5_attributes
36
82
  end
37
- alias_method_chain :to_check_box_tag, :html5_attributes
38
83
  end
39
84
  end
40
85
  end
@@ -1,3 +1,3 @@
1
1
  module Html5Validators
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,33 +1,24 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: html5_validators
3
- version: !ruby/object:Gem::Version
4
- hash: 27
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 1
9
- - 0
10
- version: 0.1.0
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Akira Matsuda
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-05-17 00:00:00 Z
12
+ date: 2012-03-02 00:00:00.000000000 Z
19
13
  dependencies: []
20
-
21
- description: A gem/plugin for Rails 3 that enables client-side validation using ActiveModel + HTML5
22
- email:
14
+ description: A gem/plugin for Rails 3 that enables client-side validation using ActiveModel
15
+ + HTML5
16
+ email:
23
17
  - ronnie@dio.jp
24
18
  executables: []
25
-
26
19
  extensions: []
27
-
28
20
  extra_rdoc_files: []
29
-
30
- files:
21
+ files:
31
22
  - .gitignore
32
23
  - Gemfile
33
24
  - MIT-LICENSE
@@ -41,36 +32,26 @@ files:
41
32
  - lib/html5_validators/version.rb
42
33
  homepage: https://github.com/amatsuda/html5_validators
43
34
  licenses: []
44
-
45
35
  post_install_message:
46
36
  rdoc_options: []
47
-
48
- require_paths:
37
+ require_paths:
49
38
  - lib
50
- required_ruby_version: !ruby/object:Gem::Requirement
39
+ required_ruby_version: !ruby/object:Gem::Requirement
51
40
  none: false
52
- requirements:
53
- - - ">="
54
- - !ruby/object:Gem::Version
55
- hash: 3
56
- segments:
57
- - 0
58
- version: "0"
59
- required_rubygems_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
46
  none: false
61
- requirements:
62
- - - ">="
63
- - !ruby/object:Gem::Version
64
- hash: 3
65
- segments:
66
- - 0
67
- version: "0"
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
68
51
  requirements: []
69
-
70
52
  rubyforge_project: html5_validators
71
- rubygems_version: 1.8.2
53
+ rubygems_version: 1.8.16
72
54
  signing_key:
73
55
  specification_version: 3
74
56
  summary: Automatic client side validation using HTML5 Form Validation
75
57
  test_files: []
76
-