simple_form 3.0.4 → 3.1.0.rc2
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/CHANGELOG.md +35 -43
- data/MIT-LICENSE +1 -1
- data/README.md +179 -73
- data/lib/generators/simple_form/install_generator.rb +2 -2
- data/lib/generators/simple_form/templates/README +3 -4
- data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +25 -5
- data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +108 -24
- data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +1 -1
- data/lib/generators/simple_form/templates/config/locales/simple_form.en.yml +7 -2
- data/lib/simple_form/action_view_extensions/form_helper.rb +1 -1
- data/lib/simple_form/components/errors.rb +27 -5
- data/lib/simple_form/components/hints.rb +2 -2
- data/lib/simple_form/components/html5.rb +1 -1
- data/lib/simple_form/components/label_input.rb +20 -2
- data/lib/simple_form/components/labels.rb +10 -6
- data/lib/simple_form/components/maxlength.rb +1 -1
- data/lib/simple_form/components/min_max.rb +1 -1
- data/lib/simple_form/components/pattern.rb +1 -1
- data/lib/simple_form/components/placeholders.rb +2 -2
- data/lib/simple_form/components/readonly.rb +1 -1
- data/lib/simple_form/form_builder.rb +121 -74
- data/lib/simple_form/helpers.rb +5 -5
- data/lib/simple_form/inputs/base.rb +34 -12
- data/lib/simple_form/inputs/block_input.rb +1 -1
- data/lib/simple_form/inputs/boolean_input.rb +27 -14
- data/lib/simple_form/inputs/collection_input.rb +32 -9
- data/lib/simple_form/inputs/collection_radio_buttons_input.rb +6 -11
- data/lib/simple_form/inputs/collection_select_input.rb +4 -2
- data/lib/simple_form/inputs/date_time_input.rb +12 -2
- data/lib/simple_form/inputs/file_input.rb +4 -2
- data/lib/simple_form/inputs/grouped_collection_select_input.rb +15 -3
- data/lib/simple_form/inputs/hidden_input.rb +4 -2
- data/lib/simple_form/inputs/numeric_input.rb +5 -4
- data/lib/simple_form/inputs/password_input.rb +4 -2
- data/lib/simple_form/inputs/priority_input.rb +4 -2
- data/lib/simple_form/inputs/range_input.rb +1 -1
- data/lib/simple_form/inputs/string_input.rb +4 -2
- data/lib/simple_form/inputs/text_input.rb +4 -2
- data/lib/simple_form/railtie.rb +7 -0
- data/lib/simple_form/tags.rb +8 -0
- data/lib/simple_form/version.rb +1 -1
- data/lib/simple_form/wrappers/builder.rb +6 -6
- data/lib/simple_form/wrappers/leaf.rb +28 -0
- data/lib/simple_form/wrappers/many.rb +6 -6
- data/lib/simple_form/wrappers/root.rb +1 -1
- data/lib/simple_form/wrappers/single.rb +5 -3
- data/lib/simple_form/wrappers.rb +1 -0
- data/lib/simple_form.rb +46 -6
- data/test/action_view_extensions/builder_test.rb +5 -5
- data/test/action_view_extensions/form_helper_test.rb +13 -13
- data/test/components/label_test.rb +36 -36
- data/test/form_builder/association_test.rb +21 -4
- data/test/form_builder/button_test.rb +5 -5
- data/test/form_builder/error_notification_test.rb +1 -1
- data/test/form_builder/error_test.rb +68 -49
- data/test/form_builder/general_test.rb +67 -62
- data/test/form_builder/hint_test.rb +15 -15
- data/test/form_builder/input_field_test.rb +33 -49
- data/test/form_builder/label_test.rb +44 -12
- data/test/form_builder/wrapper_test.rb +120 -19
- data/test/generators/simple_form_generator_test.rb +2 -2
- data/test/inputs/boolean_input_test.rb +54 -6
- data/test/inputs/collection_check_boxes_input_test.rb +63 -17
- data/test/inputs/collection_radio_buttons_input_test.rb +112 -36
- data/test/inputs/collection_select_input_test.rb +141 -36
- data/test/inputs/datetime_input_test.rb +116 -49
- data/test/inputs/disabled_test.rb +15 -15
- data/test/inputs/discovery_test.rb +56 -6
- data/test/inputs/file_input_test.rb +2 -2
- data/test/inputs/general_test.rb +20 -20
- data/test/inputs/grouped_collection_select_input_test.rb +38 -2
- data/test/inputs/hidden_input_test.rb +4 -4
- data/test/inputs/numeric_input_test.rb +24 -24
- data/test/inputs/priority_input_test.rb +7 -7
- data/test/inputs/readonly_test.rb +19 -19
- data/test/inputs/required_test.rb +13 -13
- data/test/inputs/string_input_test.rb +41 -21
- data/test/inputs/text_input_test.rb +4 -4
- data/test/simple_form_test.rb +8 -0
- data/test/support/discovery_inputs.rb +32 -2
- data/test/support/misc_helpers.rb +66 -6
- data/test/support/models.rb +50 -24
- metadata +7 -7
data/test/support/models.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Association = Struct.new(:klass, :name, :macro, :options)
|
|
1
|
+
Association = Struct.new(:klass, :name, :macro, :scope, :options)
|
|
2
2
|
|
|
3
3
|
Column = Struct.new(:name, :type, :limit) do
|
|
4
4
|
# Returns +true+ if the column is either of type integer, float or decimal.
|
|
@@ -7,16 +7,36 @@ Column = Struct.new(:name, :type, :limit) do
|
|
|
7
7
|
end
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
-
Relation = Struct.new(:
|
|
10
|
+
Relation = Struct.new(:records) do
|
|
11
|
+
delegate :each, to: :records
|
|
12
|
+
|
|
11
13
|
def where(conditions = nil)
|
|
12
|
-
self.class.new conditions ?
|
|
14
|
+
self.class.new conditions ? records.first : records
|
|
13
15
|
end
|
|
14
16
|
|
|
15
17
|
def order(conditions = nil)
|
|
16
|
-
self.class.new conditions ?
|
|
18
|
+
self.class.new conditions ? records.last : records
|
|
17
19
|
end
|
|
18
20
|
|
|
19
|
-
alias_method :to_a,
|
|
21
|
+
alias_method :to_a, :records
|
|
22
|
+
alias_method :to_ary, :records
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
Picture = Struct.new(:id, :name) do
|
|
26
|
+
extend ActiveModel::Naming
|
|
27
|
+
include ActiveModel::Conversion
|
|
28
|
+
|
|
29
|
+
def self.where(conditions = nil)
|
|
30
|
+
if conditions.is_a?(Hash) && conditions[:name]
|
|
31
|
+
all.to_a.last
|
|
32
|
+
else
|
|
33
|
+
all
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def self.all
|
|
38
|
+
Relation.new((1..3).map { |i| new(i, "#{name} #{i}") })
|
|
39
|
+
end
|
|
20
40
|
end
|
|
21
41
|
|
|
22
42
|
Company = Struct.new(:id, :name) do
|
|
@@ -28,11 +48,11 @@ Company = Struct.new(:id, :name) do
|
|
|
28
48
|
end
|
|
29
49
|
|
|
30
50
|
def self._relation
|
|
31
|
-
|
|
51
|
+
all
|
|
32
52
|
end
|
|
33
53
|
|
|
34
54
|
def self.all
|
|
35
|
-
(1..3).map { |i| new(i, "#{name} #{i}") }
|
|
55
|
+
Relation.new((1..3).map { |i| new(i, "#{name} #{i}") })
|
|
36
56
|
end
|
|
37
57
|
|
|
38
58
|
def persisted?
|
|
@@ -53,7 +73,8 @@ class User
|
|
|
53
73
|
:delivery_time, :born_at, :special_company_id, :country, :tags, :tag_ids,
|
|
54
74
|
:avatar, :home_picture, :email, :status, :residence_country, :phone_number,
|
|
55
75
|
:post_count, :lock_version, :amount, :attempts, :action, :credit_card, :gender,
|
|
56
|
-
:extra_special_company_id
|
|
76
|
+
:extra_special_company_id, :pictures, :picture_ids, :special_pictures,
|
|
77
|
+
:special_picture_ids, :uuid
|
|
57
78
|
|
|
58
79
|
def self.build(extra_attributes = {})
|
|
59
80
|
attributes = {
|
|
@@ -66,7 +87,7 @@ class User
|
|
|
66
87
|
new attributes
|
|
67
88
|
end
|
|
68
89
|
|
|
69
|
-
def initialize(options={})
|
|
90
|
+
def initialize(options = {})
|
|
70
91
|
@new_record = false
|
|
71
92
|
options.each do |key, value|
|
|
72
93
|
send("#{key}=", value)
|
|
@@ -104,11 +125,12 @@ class User
|
|
|
104
125
|
when :attempts then :integer
|
|
105
126
|
when :action then :string
|
|
106
127
|
when :credit_card then :string
|
|
128
|
+
when :uuid then :uuid
|
|
107
129
|
end
|
|
108
130
|
Column.new(attribute, column_type, limit)
|
|
109
131
|
end
|
|
110
132
|
|
|
111
|
-
def self.human_attribute_name(attribute)
|
|
133
|
+
def self.human_attribute_name(attribute, options = {})
|
|
112
134
|
case attribute
|
|
113
135
|
when 'name'
|
|
114
136
|
'Super User Name!'
|
|
@@ -117,35 +139,39 @@ class User
|
|
|
117
139
|
when 'company'
|
|
118
140
|
'Company Human Name!'
|
|
119
141
|
else
|
|
120
|
-
attribute.humanize
|
|
142
|
+
attribute.to_s.humanize
|
|
121
143
|
end
|
|
122
144
|
end
|
|
123
145
|
|
|
124
146
|
def self.reflect_on_association(association)
|
|
125
147
|
case association
|
|
126
148
|
when :company
|
|
127
|
-
Association.new(Company, association, :belongs_to, {})
|
|
149
|
+
Association.new(Company, association, :belongs_to, nil, {})
|
|
128
150
|
when :tags
|
|
129
|
-
Association.new(Tag, association, :has_many, {})
|
|
151
|
+
Association.new(Tag, association, :has_many, nil, {})
|
|
130
152
|
when :first_company
|
|
131
|
-
Association.new(Company, association, :has_one, {})
|
|
153
|
+
Association.new(Company, association, :has_one, nil, {})
|
|
132
154
|
when :special_company
|
|
133
|
-
Association.new(Company, association, :belongs_to, { conditions: { id: 1 } })
|
|
155
|
+
Association.new(Company, association, :belongs_to, nil, { conditions: { id: 1 } })
|
|
134
156
|
when :extra_special_company
|
|
135
|
-
Association.new(Company, association, :belongs_to, { conditions: proc { { id:
|
|
157
|
+
Association.new(Company, association, :belongs_to, nil, { conditions: proc { { id: self.id } } })
|
|
158
|
+
when :pictures
|
|
159
|
+
Association.new(Picture, association, :has_many, nil, {})
|
|
160
|
+
when :special_pictures
|
|
161
|
+
Association.new(Picture, association, :has_many, proc { where(name: self.name) }, {})
|
|
136
162
|
end
|
|
137
163
|
end
|
|
138
164
|
|
|
139
165
|
def errors
|
|
140
166
|
@errors ||= begin
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
167
|
+
errors = ActiveModel::Errors.new(self)
|
|
168
|
+
errors.add(:name, "can't be blank")
|
|
169
|
+
errors.add(:description, 'must be longer than 15 characters')
|
|
170
|
+
errors.add(:age, 'is not a number')
|
|
171
|
+
errors.add(:age, 'must be greater than 18')
|
|
172
|
+
errors.add(:company, 'company must be present')
|
|
173
|
+
errors.add(:company_id, 'must be valid')
|
|
174
|
+
errors
|
|
149
175
|
end
|
|
150
176
|
end
|
|
151
177
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: simple_form
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.0.
|
|
4
|
+
version: 3.1.0.rc2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- José Valim
|
|
@@ -10,7 +10,7 @@ authors:
|
|
|
10
10
|
autorequire:
|
|
11
11
|
bindir: bin
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date:
|
|
13
|
+
date: 2014-07-08 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: activemodel
|
|
@@ -41,7 +41,7 @@ dependencies:
|
|
|
41
41
|
- !ruby/object:Gem::Version
|
|
42
42
|
version: '4.0'
|
|
43
43
|
description: Forms made easy!
|
|
44
|
-
email:
|
|
44
|
+
email: opensource@plataformatec.com.br
|
|
45
45
|
executables: []
|
|
46
46
|
extensions: []
|
|
47
47
|
extra_rdoc_files: []
|
|
@@ -106,6 +106,7 @@ files:
|
|
|
106
106
|
- lib/simple_form/version.rb
|
|
107
107
|
- lib/simple_form/wrappers.rb
|
|
108
108
|
- lib/simple_form/wrappers/builder.rb
|
|
109
|
+
- lib/simple_form/wrappers/leaf.rb
|
|
109
110
|
- lib/simple_form/wrappers/many.rb
|
|
110
111
|
- lib/simple_form/wrappers/root.rb
|
|
111
112
|
- lib/simple_form/wrappers/single.rb
|
|
@@ -160,12 +161,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
160
161
|
version: '0'
|
|
161
162
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
162
163
|
requirements:
|
|
163
|
-
- - "
|
|
164
|
+
- - ">"
|
|
164
165
|
- !ruby/object:Gem::Version
|
|
165
|
-
version:
|
|
166
|
+
version: 1.3.1
|
|
166
167
|
requirements: []
|
|
167
168
|
rubyforge_project: simple_form
|
|
168
|
-
rubygems_version: 2.
|
|
169
|
+
rubygems_version: 2.2.2
|
|
169
170
|
signing_key:
|
|
170
171
|
specification_version: 4
|
|
171
172
|
summary: Forms made easy!
|
|
@@ -206,4 +207,3 @@ test_files:
|
|
|
206
207
|
- test/support/mock_controller.rb
|
|
207
208
|
- test/support/models.rb
|
|
208
209
|
- test/test_helper.rb
|
|
209
|
-
has_rdoc:
|