cocooned 2.0.4 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +19 -0
- data/README.md +10 -6
- data/app/assets/javascripts/cocooned.js +11 -4
- data/cocooned.gemspec +0 -3
- data/lib/cocooned/association/builder.rb +1 -1
- data/lib/cocooned/helpers/containers.rb +4 -2
- data/lib/cocooned/version.rb +1 -1
- metadata +3 -45
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 109827f9ebd10c0449258165b0a5d02e6bbd6ae4626f7ad02e6433f7bdf885bb
|
4
|
+
data.tar.gz: c79261d7aebc07c5d8516bbdddd0bdf7334af260c1b253eb2b6c52d56184416b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 904197ab102c253ceee532f9ff777b063d560228a11b0ead34af44510148a7fd5f23ba02947f314a787161e02da83d6ecf76b77ce3df9abc2e32bc5a18322161
|
7
|
+
data.tar.gz: 87fab14e1918bb4315819327d2b4460e5a7046e6f6d3364504c82b544c3a792bf73273afb97a1dc82a6c877f29e5e341eff44e57f537927b4983f1b53b68a4f7
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,25 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## Version 2.1.0 (2024-01-28)
|
10
|
+
|
11
|
+
### Added
|
12
|
+
|
13
|
+
* Add support for custom tag name to container helpers (#55, #56)
|
14
|
+
`cocooned_container` and `cocooned_item` now support an optional tag name as their first argument (as `content_tag` do) when the default `<div/>` is not appropriate.
|
15
|
+
**Warning:** This change is not supposed to break anything as helpers prototypes stays the same and no other positional argument where really expected before. However, depending on how you used these helpers with previous releases, you may encounter unexpected side effects.
|
16
|
+
* Documentation about nested use cases and event initialization (#59)
|
17
|
+
|
18
|
+
### Fixed
|
19
|
+
|
20
|
+
* Replacements operated on a newly built item in some nested use cases (#52, #57)
|
21
|
+
Replacements are now done recursively in nested templates if any exists. This should fix field naming in newly built items when multiple Cocooned instance are nested and correct naming of sub-items depends on generated names for their parent.
|
22
|
+
|
23
|
+
### Changed
|
24
|
+
|
25
|
+
* Update test matrix (#54)
|
26
|
+
Add Ruby 3.3. Drop Ruby 2.6 and Ruby 2.7
|
27
|
+
|
9
28
|
## Version 2.0.4 (2023-11-23)
|
10
29
|
|
11
30
|
### Fixed
|
data/README.md
CHANGED
@@ -193,7 +193,7 @@ And your sub form as follow:
|
|
193
193
|
+ <% end %>
|
194
194
|
```
|
195
195
|
|
196
|
-
The `cocooned_container` and `cocooned_item` helpers will set for you the HTML attributes the JavaScript part of Cocooned expect to find to hook on. They will forward any option supported by ActionView's `content_tag
|
196
|
+
The `cocooned_container` and `cocooned_item` helpers will set for you the HTML attributes the JavaScript part of Cocooned expect to find to hook on. They will forward any option supported by ActionView's `content_tag` and accept a tag name as first argument if you don't want to use the default `<div>`.
|
197
197
|
|
198
198
|
### 3. Add a way to add a new item to the list
|
199
199
|
|
@@ -257,6 +257,10 @@ If you have a `has_one` association, then you (probably) need to set `force_non_
|
|
257
257
|
|
258
258
|
See the [original merge request](https://github.com/nathanvda/cocoon/pull/247) for more details.
|
259
259
|
|
260
|
+
#### Complex nested forms
|
261
|
+
|
262
|
+
If you want to build complex forms with multiple levels of nesting, make sure you [initialize Cocooned event handlers correctly for dynamically added child items](https://github.com/notus-sh/cocooned/blob/main/npm/README.md#complex-nested-forms) or your form won't behave as you might expect.
|
263
|
+
|
260
264
|
## Plugins
|
261
265
|
|
262
266
|
Cocooned comes with two built-in plugins:
|
@@ -306,10 +310,10 @@ Remember to add `:position` as a permitted parameter in your controller.
|
|
306
310
|
|
307
311
|
Each helper provided by Cocooned with a name ending with `_link` has its `_button` equivalent, to generate a `<button type="button" />` instead of a `<a href="#" />`:
|
308
312
|
|
309
|
-
- `cocooned_add_item_link` <=> `cocooned_add_item_button` ([Documentation](https://github.com/notus-sh/cocooned/blob/
|
310
|
-
- `cocooned_remove_item_link` <=> `cocooned_remove_item_button` ([Documentation](https://github.com/notus-sh/cocooned/blob/
|
311
|
-
- `cocooned_move_item_up_link` <=> `cocooned_move_item_up_button` ([Documentation](https://github.com/notus-sh/cocooned/blob/
|
312
|
-
- `cocooned_move_item_down_link` <=> `cocooned_move_item_down_button` ([Documentation](https://github.com/notus-sh/cocooned/blob/
|
313
|
+
- `cocooned_add_item_link` <=> `cocooned_add_item_button` ([Documentation](https://github.com/notus-sh/cocooned/blob/main/lib/cocooned/helpers/tags/add.rb))
|
314
|
+
- `cocooned_remove_item_link` <=> `cocooned_remove_item_button` ([Documentation](https://github.com/notus-sh/cocooned/blob/main/lib/cocooned/helpers/tags/remove.rb))
|
315
|
+
- `cocooned_move_item_up_link` <=> `cocooned_move_item_up_button` ([Documentation](https://github.com/notus-sh/cocooned/blob/main/lib/cocooned/helpers/tags/up.rb))
|
316
|
+
- `cocooned_move_item_down_link` <=> `cocooned_move_item_down_button` ([Documentation](https://github.com/notus-sh/cocooned/blob/main/lib/cocooned/helpers/tags/down.rb))
|
313
317
|
|
314
318
|
While all `_link` helpers accept and will politely forward any option supported by ActionView's `link_to`, `_button` helpers will do the same with options supported by ActionView's `button_tag`.
|
315
319
|
|
@@ -328,7 +332,7 @@ If no translation is found, the default label will be the humanized action name.
|
|
328
332
|
|
329
333
|
## Javascript
|
330
334
|
|
331
|
-
For more documentation about the JavaScript bundled in the companion package, please refer to [its own documentation](https://github.com/notus-sh/cocooned/blob/
|
335
|
+
For more documentation about the JavaScript bundled in the companion package, please refer to [its own documentation](https://github.com/notus-sh/cocooned/blob/main/npm/README.md).
|
332
336
|
|
333
337
|
## Styling forms
|
334
338
|
|
@@ -309,10 +309,7 @@
|
|
309
309
|
|
310
310
|
build (id) {
|
311
311
|
const node = this.#documentFragment.cloneNode(true);
|
312
|
-
this.#
|
313
|
-
node.querySelectorAll(`*[${replacement.attribute}]`).forEach(node => replacement.apply(node, id));
|
314
|
-
});
|
315
|
-
|
312
|
+
this.#applyReplacements(node, id);
|
316
313
|
return node
|
317
314
|
}
|
318
315
|
|
@@ -320,6 +317,16 @@
|
|
320
317
|
#association
|
321
318
|
#documentFragment
|
322
319
|
#replacements
|
320
|
+
|
321
|
+
#applyReplacements(node, id) {
|
322
|
+
this.#replacements.forEach(replacement => {
|
323
|
+
node.querySelectorAll(`*[${replacement.attribute}]`).forEach(node => replacement.apply(node, id));
|
324
|
+
});
|
325
|
+
|
326
|
+
node.querySelectorAll('template').forEach(template => {
|
327
|
+
this.#applyReplacements(template.content, id);
|
328
|
+
});
|
329
|
+
}
|
323
330
|
}
|
324
331
|
|
325
332
|
class Traverser {
|
data/cocooned.gemspec
CHANGED
@@ -43,9 +43,6 @@ Gem::Specification.new do |spec|
|
|
43
43
|
spec.add_dependency 'rails', '>= 6.0', '<= 7.2'
|
44
44
|
|
45
45
|
spec.add_development_dependency 'bundler', '~> 2.1'
|
46
|
-
spec.add_development_dependency 'formtastic', '~> 4.0'
|
47
46
|
spec.add_development_dependency 'rake', '~> 13.0'
|
48
47
|
spec.add_development_dependency 'rspec', '~> 3.11'
|
49
|
-
spec.add_development_dependency 'rspec-rails', '>= 5.0'
|
50
|
-
spec.add_development_dependency 'simple_form', '~> 5.1'
|
51
48
|
end
|
@@ -31,10 +31,11 @@ module Cocooned
|
|
31
31
|
# will be forwarded.
|
32
32
|
def cocooned_container(*args, &block)
|
33
33
|
options = args.extract_options!.dup
|
34
|
+
name = args.shift || :div
|
34
35
|
defaults = cocooned_wrapper_defaults(options, %w[cocooned-container], :'cocooned-container')
|
35
36
|
defaults[:data][:cocooned_options] = options.extract!(:limit, :reorderable).to_json
|
36
37
|
|
37
|
-
content_tag(
|
38
|
+
content_tag(name, *args, **options.deep_merge(defaults), &block)
|
38
39
|
end
|
39
40
|
|
40
41
|
# Wrap content with the expected markup for a Cocooned item.
|
@@ -54,9 +55,10 @@ module Cocooned
|
|
54
55
|
# be forwarded.
|
55
56
|
def cocooned_item(*args, &block)
|
56
57
|
options = args.extract_options!.dup
|
58
|
+
name = args.shift || :div
|
57
59
|
defaults = cocooned_wrapper_defaults(options, %w[cocooned-item nested-fields], :'cocooned-item')
|
58
60
|
|
59
|
-
content_tag(
|
61
|
+
content_tag(name, *args, **options.deep_merge(defaults), &block)
|
60
62
|
end
|
61
63
|
|
62
64
|
protected
|
data/lib/cocooned/version.rb
CHANGED
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: 2.0
|
4
|
+
version: 2.1.0
|
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:
|
12
|
+
date: 2024-01-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -45,20 +45,6 @@ dependencies:
|
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '2.1'
|
48
|
-
- !ruby/object:Gem::Dependency
|
49
|
-
name: formtastic
|
50
|
-
requirement: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '4.0'
|
55
|
-
type: :development
|
56
|
-
prerelease: false
|
57
|
-
version_requirements: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '4.0'
|
62
48
|
- !ruby/object:Gem::Dependency
|
63
49
|
name: rake
|
64
50
|
requirement: !ruby/object:Gem::Requirement
|
@@ -87,34 +73,6 @@ dependencies:
|
|
87
73
|
- - "~>"
|
88
74
|
- !ruby/object:Gem::Version
|
89
75
|
version: '3.11'
|
90
|
-
- !ruby/object:Gem::Dependency
|
91
|
-
name: rspec-rails
|
92
|
-
requirement: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '5.0'
|
97
|
-
type: :development
|
98
|
-
prerelease: false
|
99
|
-
version_requirements: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - ">="
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '5.0'
|
104
|
-
- !ruby/object:Gem::Dependency
|
105
|
-
name: simple_form
|
106
|
-
requirement: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - "~>"
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '5.1'
|
111
|
-
type: :development
|
112
|
-
prerelease: false
|
113
|
-
version_requirements: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - "~>"
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '5.1'
|
118
76
|
description: " Easier nested form in Rails with capabilities to add, remove, reorder
|
119
77
|
or limit nested items. Works with standard Rails form builder, Formtastic or SimpleForm,
|
120
78
|
and with or without jQuery. "
|
@@ -180,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
180
138
|
- !ruby/object:Gem::Version
|
181
139
|
version: '0'
|
182
140
|
requirements: []
|
183
|
-
rubygems_version: 3.
|
141
|
+
rubygems_version: 3.5.3
|
184
142
|
signing_key:
|
185
143
|
specification_version: 4
|
186
144
|
summary: Form builder agnostic handling of Rails nested forms
|