cocooned 1.3.1 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0ff5fc052a1bf37f18e1f22b550f35bf876e0cc09c4c7d4ebef3667c7afde67a
4
- data.tar.gz: 55202ea14bda345f2ed5f20fc95ebb0de1bfa7831e9f70ba92b2a092c7ca210b
3
+ metadata.gz: 4494f16e78b35fe2847ef24c3b8ec95183ce63cf05fc41a81ed9aa6b316ca1a1
4
+ data.tar.gz: 4f554493b8c3aa8fe6e9e89a1eb762d186336783ad24f948e31d4d97922f405b
5
5
  SHA512:
6
- metadata.gz: ed672de23fce13326d63cb1e943689ea8f4df8be8873111daecb9a25df954ee06a47592a6b28399c95120e6079337c26125838b42a868395e0d5639d08461569
7
- data.tar.gz: 23b8d0ab6bdfda55e974f322bec4a0a39a9fd089f9bfbfa343144ccdc76639560286a4212ac3018e0ee10a567d70b8f363be5c3c3578e5000440de41a2464e04
6
+ metadata.gz: 8c09909ed1c2e7b9db436be0918b19bc28815568c804aeb76e9caba91809baabea55a3a732bcfedeac5226d550820e79b85f12d69ffced86aa2844bfaca16e91
7
+ data.tar.gz: 0c41cef34455f05fb7bc278f563d063f40ca3e5c74f31dbc2ec642f60b694041657d9f35ca35cdf8579ba685ca0923d8a16994dacbdc34a56c65520e4d44cad3
data/History.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Change History / Release Notes
2
2
 
3
+ ## Version 1.3.2
4
+
5
+ * Compatibility with Mongoid 7+
6
+
7
+ ## Version 1.3.1
8
+
9
+ * Use UMD pattern to load the Cocooned module
10
+ * Now publish packages on both rubygems.org and npmjs.com
11
+
3
12
  ## Version 1.3.0
4
13
 
5
14
  ### Breaking changes
data/README.md CHANGED
@@ -33,7 +33,11 @@ Inside your `Gemfile` add the following:
33
33
  gem "cocooned"
34
34
  ```
35
35
 
36
- You must also require `cocooned` in your `application.js` and `application.css`, so it compiles with the asset pipeline.
36
+ ### Load Cocooned styles and scripts
37
+
38
+ If you use Sprockets, you have to require `cocooned` in your `application.js` and `application.css`, so it compiles with the asset pipeline.
39
+
40
+ If you use Yarn to manage your non-Ruby dependencies and/or Webpack to build your assets, you can install the [`@notus.sh/cocooned` companion package](https://www.npmjs.com/package/@notus.sh/cocooned).
37
41
 
38
42
  ## Usage
39
43
 
@@ -70,23 +74,23 @@ E.g. in your `ListsController`:
70
74
 
71
75
  ### Basic form
72
76
 
73
- _Please note examples in this section are written with the [`haml` templating language](http://haml.info/)._
74
-
75
77
  [Rails natively supports nested forms](https://guides.rubyonrails.org/form_helpers.html#nested-forms) but does not support adding or removing nested items.
76
78
 
77
- ```haml
78
- / `app/views/lists/_form.html.haml`
79
- = form_for @list do |f|
80
- = f.input :name
79
+ ```erb
80
+ <% # `app/views/lists/_form.html.erb` %>
81
+ <%= form_for @list do |f| %>
82
+ <%= f.input :name %>
81
83
 
82
- %h3 Items
83
- = f.fields_for :tasks do |item_form|
84
- / This block is repeated for every task in @list.items
85
- = item_form.label :description
86
- = item_form.text_field :description
87
- = item_form.check_box :done
88
-
89
- = f.submit "Save"
84
+ <h3>Items</h3>
85
+ <%= f.fields_for :tasks do |item_form| %>
86
+ <% # This block is repeated for every task in @list.items %>
87
+ <%= item_form.label :description %>
88
+ <%= item_form.text_field :description %>
89
+ <%= item_form.check_box :done %>
90
+ <% end %>
91
+
92
+ <%= f.submit "Save" %>
93
+ <% end %>
90
94
  ```
91
95
 
92
96
  To enable Cocooned on this first, we need to:
@@ -102,75 +106,88 @@ Let's do it.
102
106
 
103
107
  We now have two files:
104
108
 
105
- ```haml
106
- / `app/views/lists/_form.html.haml`
107
- = form_for @list do |form|
108
- = form.input :name
109
+ ```erb
110
+ <% # `app/views/lists/_form.html.erb` %>
111
+ <%= form_for @list do |form| %>
112
+ <%= form.input :name %>
109
113
 
110
- %h3 Items
111
- = form.fields_for :items do |item_form|
112
- = render 'item_fields', f: item_form
114
+ <h3>Items</h3>
115
+ <%= form.fields_for :items do |item_form|
116
+ <%= render 'item_fields', f: item_form %>
117
+ <% end %>
113
118
 
114
- = form.submit "Save"
119
+ <%= form.submit "Save" %>
120
+ <% end %>
115
121
  ```
116
122
 
117
- ```haml
118
- / `app/views/lists/_item_fields.html.haml`
119
- = f.label :description
120
- = f.text_field :description
121
- = f.check_box :done
123
+ ```erb
124
+ <% # `app/views/lists/_item_fields.html.erb` %>
125
+ <%= f.label :description %>
126
+ <%= f.text_field :description %>
127
+ <%= f.check_box :done %>
122
128
  ```
123
129
 
124
130
  #### 2. Add a way to add a new item to the collection
125
131
 
126
- ```haml
127
- / `app/views/lists/_form.html.haml`
128
- = form_for @list do |form|
129
- = form.input :name
132
+ ```erb
133
+ <% # `app/views/lists/_form.html.erb` %>
134
+ <%= form_for @list do |form| %>
135
+ <%= form.input :name %>
130
136
 
131
- %h3 Items
132
- #items
133
- = form.fields_for :tasks do |item_form|
134
- = render 'item_fields', f: item_form
135
- .links
136
- = cocooned_add_item_link 'Add an item', form, :items
137
+ <h3>Items</h3>
138
+ <div id="items">
139
+ <%= form.fields_for :tasks do |item_form| %>
140
+ <%= render 'item_fields', f: item_form %>
141
+ <% end %>
142
+
143
+ <div class="links">
144
+ <%= cocooned_add_item_link 'Add an item', form, :items %>
145
+ </div>
146
+ </div>
137
147
 
138
- = form.submit "Save"
148
+ <%= form.submit "Save" %>
149
+ <% end %>
139
150
  ```
140
151
 
141
152
  By default, a new item will be inserted just before the immediate parent of the 'Add an item' link. You can have a look at the documentation of `cocooned_add_item_link` for more information about how to change that but we'll keep it simple for now.
142
153
 
143
154
  #### 3. Add a way to remove an item from the collection
144
155
 
145
- ```haml
146
- / `app/views/lists/_item_fields.html.haml`
147
- .cocooned-item
148
- = f.label :description
149
- = f.text_field :description
150
- = f.check_box :done
151
- = cocooned_remove_item_link 'Remove', f
156
+ ```erb
157
+ <% # `app/views/lists/_item_fields.html.erb` %>
158
+ <div class="cocooned-item">
159
+ <%= f.label :description %>
160
+ <%= f.text_field :description %>
161
+ <%= f.check_box :done %>
162
+ <%= cocooned_remove_item_link 'Remove', f %>
163
+ </div>
152
164
  ```
153
165
 
154
- The `.cocooned-item` class is required for the `cocooned_remove_item_link` to work correctly.
166
+ The `cocooned-item` class is required for the `cocooned_remove_item_link` to work correctly.
155
167
 
156
168
  #### 4. Initialize Cocooned to handle this form
157
169
 
158
170
  Cocooned will detect on page load forms it should handle and initialize itself.
159
171
  This detection is based on the presence of a `data-cocooned-options` attribute on the nested forms container.
160
172
 
161
- ```haml
162
- / `app/views/lists/_form.html.haml`
163
- = form_for @list do |form|
164
- = form.input :name
173
+ ```erb
174
+ <% # `app/views/lists/_form.html.erb` %>
175
+ <%= form_for @list do |form| %>
176
+ <%= form.input :name %>
165
177
 
166
- %h3 Items
167
- #items{ :data => { cocooned_options: {}.to_json } }
168
- = form.fields_for :tasks do |item_form|
169
- = render 'item_fields', f: item_form
170
- .links
171
- = cocooned_add_item_link 'Add an item', form, :items
178
+ <h3>Items</h3>
179
+ <div id="items" data-cocooned-options="<%= {}.to_json %>">
180
+ <%= form.fields_for :tasks do |item_form| %>
181
+ <%= render 'item_fields', f: item_form %>
182
+ <% end %>
183
+
184
+ <div class="links">
185
+ <%= cocooned_add_item_link 'Add an item', form, :items %>
186
+ </div>
187
+ </div>
172
188
 
173
- = form.submit "Save"
189
+ <%= form.submit "Save" %>
190
+ </div>
174
191
  ```
175
192
 
176
193
  And we're done!
@@ -188,52 +205,63 @@ For now, Cocooned supports two plugins:
188
205
 
189
206
  The limit plugin is autoloaded when needed and does not require anything more than you specifiying the maximum number of items allowed in the association.
190
207
 
191
- ```haml
192
- / `app/views/lists/_form.html.haml`
193
- = form_for @list do |form|
194
- = form.input :name
208
+ ```erb
209
+ <% # `app/views/lists/_form.html.erb` %>
210
+ <%= form_for @list do |form| %>
211
+ <%= form.input :name %>
195
212
 
196
- %h3 Items
197
- #items{ :data => { cocooned_options: { limit: 12 }.to_json } }
198
- = form.fields_for :tasks do |item_form|
199
- = render 'item_fields', f: item_form
200
- .links
201
- = cocooned_add_item_link 'Add an item', form, :items
213
+ <h3>Items</h3>
214
+ <div id="items" data-cocooned-options="<%= { limit: 12 }.to_json %>">
215
+ <%= form.fields_for :tasks do |item_form| %>
216
+ <%= render 'item_fields', f: item_form %>
217
+ <% end %>
218
+
219
+ <div class="links">
220
+ <%= cocooned_add_item_link 'Add an item', form, :items %>
221
+ </div>
222
+ </div>
202
223
 
203
- = form.submit "Save"
224
+ <%= form.submit "Save" %>
225
+ <% end %>
204
226
  ```
205
227
 
206
228
  #### The reorderable plugin
207
229
 
208
230
  The reorderable plugin is autoloaded when activated and does not support any particular options.
209
231
 
210
- ```haml
211
- / `app/views/lists/_form.html.haml`
212
- = form_for @list do |form|
213
- = form.input :name
214
-
215
- %h3 Items
216
- #items{ :data => { cocooned_options: { reorderable: true }.to_json } }
217
- = form.fields_for :tasks do |item_form|
218
- = render 'item_fields', f: item_form
219
- .links
220
- = cocooned_add_item_link 'Add an item', form, :items
232
+ ```erb
233
+ <% # `app/views/lists/_form.html.haml` %>
234
+ <%= form_for @list do |form| %>
235
+ <%= form.input :name %>
221
236
 
222
- = form.submit "Save"
237
+ <h3>Items</h3>
238
+ <div id="items" data-cocooned-options="<%= { reorderable: true }.to_json %>">
239
+ <%= form.fields_for :tasks do |item_form| %>
240
+ <%= render 'item_fields', f: item_form %>
241
+ <% end %>
242
+
243
+ <div class="links">
244
+ <%= cocooned_add_item_link 'Add an item', form, :items %>
245
+ </div>
246
+ </div>
247
+
248
+ <%= form.submit "Save" %>
249
+ <% end %>
223
250
  ```
224
251
 
225
252
  However, you need to edit your nested partial to add the links that allow your users to move an item up or down in the collection and to add a `position` field.
226
253
 
227
- ```haml
228
- / `app/views/lists/_item_fields.html.haml`
229
- .cocooned-item
230
- = f.label :description
231
- = f.text_field :description
232
- = f.check_box :done
233
- = f.hidden_field :position
234
- = cocooned_move_item_up_link 'Up', f
235
- = cocooned_move_item_down_link 'Down', f
236
- = cocooned_remove_item_link 'Remove', f
254
+ ```erb
255
+ <% # `app/views/lists/_item_fields.html.erb` %>
256
+ <div class="cocooned-item">
257
+ <%= f.label :description %>
258
+ <%= f.text_field :description %>
259
+ <%= f.check_box :done %>
260
+ <%= f.hidden_field :position %>
261
+ <%= cocooned_move_item_up_link 'Up', f %>
262
+ <%= cocooned_move_item_down_link 'Down', f %>
263
+ <%= cocooned_remove_item_link 'Remove', f %>
264
+ </div>
237
265
  ```
238
266
 
239
267
  Also, remember the strong parameters gotcha we mentioned earlier.
data/Rakefile CHANGED
@@ -79,6 +79,7 @@ namespace :npm do
79
79
  contributors = []
80
80
  spec.authors.each_with_index do |name, i|
81
81
  next if spec.email[i].nil?
82
+
82
83
  contributors << {
83
84
  name: name.dup.force_encoding('UTF-8'),
84
85
  email: spec.email[i].dup.force_encoding('UTF-8')
@@ -1,5 +1,7 @@
1
1
  /* globals define */
2
2
 
3
+ // Use Universal Module Definition pattern to load Cocooned
4
+ // See https://github.com/umdjs/umd/blob/master/templates/returnExportsGlobal.js
3
5
  (function (root, factory) {
4
6
  if (typeof define === 'function' && define.amd) {
5
7
  // AMD. Register as an anonymous module.
@@ -36,4 +36,5 @@ Gem::Specification.new do |spec|
36
36
  spec.add_development_dependency 'rspec', '~> 3.8.0'
37
37
  spec.add_development_dependency 'rspec-rails', '~> 3.8.0'
38
38
  spec.add_development_dependency 'rubocop'
39
+ spec.add_development_dependency 'rubocop-performance'
39
40
  end
@@ -54,11 +54,12 @@ module Cocooned
54
54
  def build_without_reflection
55
55
  methods = %W[build_#{plural_name} build_#{singular_name}].select { |m| form.object.respond_to?(m) }
56
56
  raise "Association #{association} doesn't exist on #{form.object.class}" unless methods.any?
57
+
57
58
  form.object.send(methods.first)
58
59
  end
59
60
 
60
61
  def should_use_conditions?
61
- reflection.class.name == 'Mongoid::Relations::Metadata' || @options[:force_non_association_create]
62
+ reflection.class.name.starts_with?('Mongoid::') || @options[:force_non_association_create]
62
63
  end
63
64
 
64
65
  def build_with_conditions
@@ -14,7 +14,7 @@ module Cocooned
14
14
  [
15
15
  "NOTE: #{target_and_name} is deprecated",
16
16
  replacement == :none ? ' with no replacement' : "; use #{replacement} instead",
17
- format('. It will dissapear in %s.', release),
17
+ format('. It will dissapear in %<release>s.', release: release),
18
18
  location.nil? ? '' : "\n#{target_and_name} called from #{location}"
19
19
  ].join.strip
20
20
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cocooned
4
- VERSION = '1.3.1'
4
+ VERSION = '1.3.2'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocooned
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gaël-Ian Havard
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-08-24 00:00:00.000000000 Z
12
+ date: 2019-04-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -115,6 +115,20 @@ dependencies:
115
115
  - - ">="
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
+ - !ruby/object:Gem::Dependency
119
+ name: rubocop-performance
120
+ requirement: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ type: :development
126
+ prerelease: false
127
+ version_requirements: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
118
132
  description: Easier nested form. Supports standard Rails forms, Formtastic and SimpleForm.
119
133
  email:
120
134
  - gael-ian@notus.sh