formgroups-rails 0.0.2 → 0.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.
- checksums.yaml +4 -4
- data/lib/form_groups/configuration.rb +25 -0
- data/lib/form_groups/field_builder.rb +11 -22
- data/lib/form_groups/field_tag.rb +2 -2
- data/lib/form_groups/version.rb +1 -1
- data/lib/formgroups-rails.rb +2 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 294fa8ac75fd2c282df2c5a438fee7d7bf82b20b
|
4
|
+
data.tar.gz: 576085dc9ede62d2509edb986a834c211d05bf68
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: debba5e7b956cd1fbd1355b670bdc290f71adfa859ed5f2d28aaf5bb2a09c96c229e0af17dcc192adae10ed439fcb48e275dfaa2f1b1fc010aa84d76114fec14
|
7
|
+
data.tar.gz: 1631d4029713fbe661be3f3410e3cd97fa651a9c226cdd696ccd901138e99600371ca8cb744f1c617b491d51db6798d3f9e8850471f2012e9670435ea4338f17
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module FormGroups
|
2
|
+
mattr_accessor(:field_class) { 'field' }
|
3
|
+
mattr_accessor(:field_error_class) { 'field-error' }
|
4
|
+
mattr_accessor(:map_validators) { true }
|
5
|
+
|
6
|
+
mattr_reader :validator_mapping do
|
7
|
+
mappings = {}
|
8
|
+
|
9
|
+
mappings['ActiveModel::Validations::LengthValidator'] = Proc.new do |validator, result|
|
10
|
+
result['minlength'] = validator.options[:minimum] if validator.options[:minimum]
|
11
|
+
result['maxlength'] = validator.options[:maximum] if validator.options[:maximum]
|
12
|
+
end
|
13
|
+
|
14
|
+
mappings['ActiveModel::Validations::PresenceValidator'] = Proc.new do |validator, result|
|
15
|
+
result['required'] = 'true'
|
16
|
+
result['aria-required'] = 'true'
|
17
|
+
end
|
18
|
+
|
19
|
+
mappings
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.configure &block
|
23
|
+
yield self
|
24
|
+
end
|
25
|
+
end
|
@@ -42,6 +42,12 @@ module FormGroups
|
|
42
42
|
@template.text_area @method, validated_options(options)
|
43
43
|
end
|
44
44
|
|
45
|
+
def select placeholder = nil, **options, &block
|
46
|
+
options['data-placeholder'] = placeholder
|
47
|
+
|
48
|
+
@template.select @method, nil, {}, validated_options(options), &block
|
49
|
+
end
|
50
|
+
|
45
51
|
private
|
46
52
|
|
47
53
|
def unvalidated_options options
|
@@ -49,7 +55,7 @@ module FormGroups
|
|
49
55
|
end
|
50
56
|
|
51
57
|
def validated_options options
|
52
|
-
options = unvalidated_options(options).merge(validations)
|
58
|
+
options = unvalidated_options(options).merge(validations) if FormGroups.map_validators
|
53
59
|
options = options.merge('aria-invalid' => 'true') if errors.any?
|
54
60
|
|
55
61
|
options
|
@@ -57,27 +63,10 @@ module FormGroups
|
|
57
63
|
|
58
64
|
def validations
|
59
65
|
validations = validators.map do |validator|
|
60
|
-
result
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
result['data-min'] = validator.options[:minimum] if validator.options[:minimum]
|
65
|
-
result['data-max'] = validator.options[:maximum] if validator.options[:maximum]
|
66
|
-
when ActiveRecord::Validations::PresenceValidator
|
67
|
-
result['data-required'] = 'true'
|
68
|
-
result['aria-required'] = 'true'
|
69
|
-
when EmailValidator
|
70
|
-
pattern = EmailValidator::PATTERN.source
|
71
|
-
pattern = pattern.sub('\\A','^')
|
72
|
-
.sub('\\Z','$')
|
73
|
-
.sub('\\z','$')
|
74
|
-
.sub(/^\//,'')
|
75
|
-
.sub(/\/[a-z]*$/,'')
|
76
|
-
.gsub(/\(\?#.+\)/, '')
|
77
|
-
.gsub(/\(\?-\w+:/,'(')
|
78
|
-
|
79
|
-
result['data-pattern'] = pattern
|
80
|
-
end
|
66
|
+
result = {}
|
67
|
+
|
68
|
+
mapping = FormGroups.validator_mapping[validator.class.name]
|
69
|
+
mapping.call(validator, result) if mapping
|
81
70
|
|
82
71
|
result
|
83
72
|
end
|
@@ -10,8 +10,8 @@ module FormGroups
|
|
10
10
|
html_options = @options.delete(:html) || {}
|
11
11
|
|
12
12
|
classes = (html_options[:class] || '').split(' ')
|
13
|
-
classes <<
|
14
|
-
classes <<
|
13
|
+
classes << FormGroups.field_class
|
14
|
+
classes << FormGroups.field_error_class if object.errors.has_key?(@method_name.to_sym)
|
15
15
|
|
16
16
|
html_options[:class] = classes
|
17
17
|
|
data/lib/form_groups/version.rb
CHANGED
data/lib/formgroups-rails.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: formgroups-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexey Chernetsov
|
@@ -81,8 +81,8 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '10.0'
|
83
83
|
description: |-
|
84
|
-
This gem for Ruby on Rails
|
85
|
-
This allows to simplify syntax, show errors, add errors classes and
|
84
|
+
This gem for Ruby on Rails 4.0+ allows to create blocks for each field of the form.
|
85
|
+
This allows to simplify syntax, show errors, add errors classes and validation attributes.
|
86
86
|
email:
|
87
87
|
- chernetsov0@gmail.com
|
88
88
|
executables: []
|
@@ -91,6 +91,7 @@ extra_rdoc_files: []
|
|
91
91
|
files:
|
92
92
|
- MIT-LICENSE
|
93
93
|
- Rakefile
|
94
|
+
- lib/form_groups/configuration.rb
|
94
95
|
- lib/form_groups/field_builder.rb
|
95
96
|
- lib/form_groups/field_tag.rb
|
96
97
|
- lib/form_groups/group_builder.rb
|