cocoon 1.2.11 → 1.2.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +36 -5
- data/Gemfile +3 -2
- data/{MIT-LICENSE → LICENSE} +0 -0
- data/README.markdown +28 -9
- data/Rakefile +48 -1
- data/VERSION +1 -1
- data/app/assets/javascripts/cocoon.js +14 -7
- data/cocoon.gemspec +15 -11
- data/gemfiles/Gemfile.default +31 -0
- data/lib/cocoon/view_helpers.rb +4 -3
- data/npm/README.md +8 -0
- data/npm/package.json.erb +21 -0
- data/spec/cocoon_spec.rb +15 -7
- data/spec/dummy/db/migrate/20110306212208_create_posts.rb +1 -1
- data/spec/dummy/db/migrate/20110306212250_create_comments.rb +1 -1
- data/spec/dummy/db/migrate/20110420222224_create_people.rb +1 -1
- data/spec/dummy/db/schema.rb +17 -8
- metadata +16 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5ece48b77f3c2ade4038d9a745ecda7d23ec24d2e1b391a7900c1b040e9800a0
|
4
|
+
data.tar.gz: dfd2781be46692cc32726a785d379503c1f1aadd37a015f3d18e1955f2bc893b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 278cc47c1d3cf4bc126f8609cbb4efa945fb59b864f495097e3a1f0d536b6353cc43da3d4e49d2cddbb65c660adfc057a50d3b8639d7acb5bcf1eed761937fd8
|
7
|
+
data.tar.gz: 8c9b316114c977cdf62aac3c172cb50bb74444714099751bd4915d8b970a105d6cca61ffe7c41f8369d7bdf2cb6f935ce92b852dba58b1c7e234f32d06daa9fe
|
data/.travis.yml
CHANGED
@@ -3,19 +3,30 @@ rvm:
|
|
3
3
|
- 2.1.5
|
4
4
|
- 2.2.6
|
5
5
|
- 2.3.2
|
6
|
+
- 2.4.1
|
7
|
+
- 2.4.5
|
8
|
+
- 2.4.6
|
9
|
+
- 2.5.4
|
10
|
+
- 2.5.5
|
11
|
+
- 2.6.3
|
6
12
|
- rbx-2
|
13
|
+
|
14
|
+
before_install:
|
15
|
+
- gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true
|
16
|
+
- gem install bundler -v '< 2'
|
17
|
+
|
7
18
|
gemfile:
|
8
19
|
- gemfiles/Gemfile.rails-3.2.13
|
9
20
|
- gemfiles/Gemfile.rails-4-r2
|
10
|
-
- Gemfile
|
21
|
+
- gemfiles/Gemfile.default
|
11
22
|
|
12
23
|
matrix:
|
13
24
|
fast_finish: true
|
14
25
|
exclude:
|
15
26
|
- rvm: 2.0.0
|
16
|
-
gemfile: Gemfile
|
27
|
+
gemfile: gemfiles/Gemfile.default
|
17
28
|
- rvm: 2.1.5
|
18
|
-
gemfile: Gemfile
|
29
|
+
gemfile: gemfiles/Gemfile.default
|
19
30
|
- rvm: 2.2.6
|
20
31
|
gemfile: gemfiles/Gemfile.rails-3.2.13
|
21
32
|
- rvm: 2.2.6
|
@@ -24,9 +35,29 @@ matrix:
|
|
24
35
|
gemfile: gemfiles/Gemfile.rails-3.2.13
|
25
36
|
- rvm: 2.3.2
|
26
37
|
gemfile: gemfiles/Gemfile.rails-4-r2
|
27
|
-
- rvm: 2.4.
|
38
|
+
- rvm: 2.4.1
|
39
|
+
gemfile: gemfiles/Gemfile.rails-3.2.13
|
40
|
+
- rvm: 2.4.1
|
41
|
+
gemfile: gemfiles/Gemfile.rails-4-r2
|
42
|
+
- rvm: 2.4.6
|
43
|
+
gemfile: gemfiles/Gemfile.rails-3.2.13
|
44
|
+
- rvm: 2.4.6
|
45
|
+
gemfile: gemfiles/Gemfile.rails-4-r2
|
46
|
+
- rvm: 2.4.5
|
47
|
+
gemfile: gemfiles/Gemfile.rails-3.2.13
|
48
|
+
- rvm: 2.4.5
|
49
|
+
gemfile: gemfiles/Gemfile.rails-4-r2
|
50
|
+
- rvm: 2.5.4
|
51
|
+
gemfile: gemfiles/Gemfile.rails-3.2.13
|
52
|
+
- rvm: 2.5.4
|
53
|
+
gemfile: gemfiles/Gemfile.rails-4-r2
|
54
|
+
- rvm: 2.5.5
|
55
|
+
gemfile: gemfiles/Gemfile.rails-3.2.13
|
56
|
+
- rvm: 2.5.5
|
57
|
+
gemfile: gemfiles/Gemfile.rails-4-r2
|
58
|
+
- rvm: 2.6.3
|
28
59
|
gemfile: gemfiles/Gemfile.rails-3.2.13
|
29
|
-
- rvm: 2.
|
60
|
+
- rvm: 2.6.3
|
30
61
|
gemfile: gemfiles/Gemfile.rails-4-r2
|
31
62
|
allow_failures:
|
32
63
|
- rvm: rbx-2
|
data/Gemfile
CHANGED
@@ -2,10 +2,11 @@ source "http://rubygems.org"
|
|
2
2
|
|
3
3
|
|
4
4
|
group :development, :test do
|
5
|
-
gem "rails", "
|
5
|
+
gem "rails", "~> 4.2"
|
6
6
|
gem "sqlite3", '1.3.13'
|
7
7
|
gem "json_pure"
|
8
|
-
gem "jeweler",
|
8
|
+
gem "jeweler", git: 'git@github.com:technicalpickles/jeweler'
|
9
|
+
# gem "jeweler", "~> 2.3"
|
9
10
|
gem "rspec-rails", "~> 3.0.0"
|
10
11
|
gem "rspec", "~> 3.0.0"
|
11
12
|
gem "actionpack", ">=4.0.0"
|
data/{MIT-LICENSE → LICENSE}
RENAMED
File without changes
|
data/README.markdown
CHANGED
@@ -27,6 +27,23 @@ gem "cocoon"
|
|
27
27
|
|
28
28
|
> Please note that for rails 4 you will need at least v1.2.0 or later.
|
29
29
|
|
30
|
+
### Rails 6/Webpacker
|
31
|
+
|
32
|
+
Add the componanion package
|
33
|
+
|
34
|
+
yarn add @nathanvda/cocoon
|
35
|
+
|
36
|
+
and then in your `app/javascripts/packs/application.js` you should add
|
37
|
+
|
38
|
+
require("jquery")
|
39
|
+
require("@nathanvda/cocoon")
|
40
|
+
|
41
|
+
|
42
|
+
> Note: there are alternative npm packages, which might better suit your needs.
|
43
|
+
E.g. some offer the cocoon functionality without using jquery (search for `cocoon + vanilla` --I found three packages on npm already).
|
44
|
+
Obviously you are free to use those, however the code samples in this README will (still) rely on jquery.
|
45
|
+
|
46
|
+
|
30
47
|
### Rails 3.1+/Rails 4/Rails 5
|
31
48
|
|
32
49
|
Add the following to `application.js` so it compiles to the asset pipeline:
|
@@ -109,7 +126,7 @@ E.g. in your `ProjectsController`:
|
|
109
126
|
Cocoon's default configuration requires `link_to_add_association` and associated partials to
|
110
127
|
be properly wrapped with elements. The examples below illustrate simple layouts.
|
111
128
|
|
112
|
-
Please note these examples rely on the `haml` gem (
|
129
|
+
Please note these examples rely on the `haml` gem ([click here](https://github.com/nathanvda/cocoon/wiki/ERB-examples) for the default `erb` views).
|
113
130
|
|
114
131
|
### Formtastic
|
115
132
|
|
@@ -218,10 +235,10 @@ This should be called within the form builder.
|
|
218
235
|
|
219
236
|
`link_to_add_association` takes four parameters:
|
220
237
|
|
221
|
-
- name
|
222
|
-
- f
|
223
|
-
- association
|
224
|
-
- html_options
|
238
|
+
- **name**: the text to show in the link
|
239
|
+
- **f**: the form builder
|
240
|
+
- **association**: the name of the association (plural) of which a new instance needs to be added (symbol or string).
|
241
|
+
- **html_options**: extra html-options (see [`link_to`](http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to)
|
225
242
|
There are some special options, the first three allow to control the placement of the new link-data:
|
226
243
|
- `data-association-insertion-traversal` : the jquery traversal method to allow node selection relative to the link. `closest`, `next`, `children`, etc. Default: absolute selection
|
227
244
|
- `data-association-insertion-node` : the jquery selector of the node as string, or a function that takes the `link_to_add_association` node as the parameter and returns a node. Default: parent node
|
@@ -234,6 +251,7 @@ This should be called within the form builder.
|
|
234
251
|
- `wrap_object` : a proc that will allow to wrap your object, especially useful if you are using decorators (e.g. draper). See example lower.
|
235
252
|
- `force_non_association_create`: if true, it will _not_ create the new object using the association (see lower)
|
236
253
|
- `form_name` : the name of the form parameter in your nested partial. By default this is `f`.
|
254
|
+
- `count` : the number of nested items to insert at once. Default `1`.
|
237
255
|
|
238
256
|
Optionally, you can omit the name and supply a block that is captured to render the link body (if you want to do something more complicated).
|
239
257
|
|
@@ -338,9 +356,9 @@ This should be placed inside the partial `_<association-object-singular>_fields`
|
|
338
356
|
|
339
357
|
It takes three parameters:
|
340
358
|
|
341
|
-
- name
|
342
|
-
- f
|
343
|
-
- html_options
|
359
|
+
- **name**: the text to show in the link
|
360
|
+
- **f**: referring to the containing form-object
|
361
|
+
- **html_options**: extra html-options (see `link_to`)
|
344
362
|
|
345
363
|
Optionally you could also leave out the name and supply a block that is captured to give the name (if you want to do something more complicated).
|
346
364
|
|
@@ -367,13 +385,14 @@ On insertion or removal the following events are triggered:
|
|
367
385
|
To listen to the events in your JavaScript:
|
368
386
|
|
369
387
|
```javascript
|
370
|
-
$('#container').on('cocoon:before-insert', function(e, insertedItem) {
|
388
|
+
$('#container').on('cocoon:before-insert', function(e, insertedItem, originalEvent) {
|
371
389
|
// ... do something
|
372
390
|
});
|
373
391
|
```
|
374
392
|
|
375
393
|
...where `e` is the event and the second parameter is the inserted or removed item. This allows you to change markup, or
|
376
394
|
add effects/animations (see example below).
|
395
|
+
`originalEvent` is also passed and references the event that triggered an insertion or removal (e.g. the `click` event on the link to add an association)
|
377
396
|
|
378
397
|
|
379
398
|
If in your view you have the following snippet to select an `owner`:
|
data/Rakefile
CHANGED
@@ -11,6 +11,9 @@ require 'rdoc/task'
|
|
11
11
|
|
12
12
|
require 'rspec/core'
|
13
13
|
require 'rspec/core/rake_task'
|
14
|
+
require 'erb'
|
15
|
+
require 'JSON'
|
16
|
+
|
14
17
|
|
15
18
|
RSpec::Core::RakeTask.new(:spec)
|
16
19
|
|
@@ -39,4 +42,48 @@ begin
|
|
39
42
|
Jeweler::GemcutterTasks.new
|
40
43
|
rescue LoadError
|
41
44
|
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
42
|
-
end
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
require 'bundler/gem_tasks'
|
49
|
+
|
50
|
+
spec = Bundler.load_gemspec('./cocoon.gemspec')
|
51
|
+
|
52
|
+
|
53
|
+
npm_src_dir = './npm'
|
54
|
+
npm_dest_dir = './dist'
|
55
|
+
CLOBBER.include 'dist'
|
56
|
+
|
57
|
+
assets_dir = './app/assets/'
|
58
|
+
|
59
|
+
npm_files = {
|
60
|
+
File.join(npm_dest_dir, 'cocoon.js') => File.join(assets_dir, 'javascripts', 'cocoon.js'),
|
61
|
+
File.join(npm_dest_dir, 'README.md') => File.join(npm_src_dir, 'README.md'),
|
62
|
+
File.join(npm_dest_dir, 'LICENSE') => './LICENSE'
|
63
|
+
}
|
64
|
+
|
65
|
+
namespace :npm do
|
66
|
+
npm_files.each do |dest, src|
|
67
|
+
file dest => src do
|
68
|
+
cp src, dest
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
task :'package-json' do
|
73
|
+
template = ERB.new(File.read(File.join(npm_src_dir, 'package.json.erb')))
|
74
|
+
content = template.result_with_hash(spec: spec)
|
75
|
+
File.write(File.join(npm_dest_dir, 'package.json'),
|
76
|
+
JSON.pretty_generate(JSON.parse(content)))
|
77
|
+
end
|
78
|
+
|
79
|
+
desc "Build nathanvda-cocoon-#{spec.version}.tgz into the pkg directory"
|
80
|
+
task build: (%i[package-json] + npm_files.keys) do
|
81
|
+
system("cd #{npm_dest_dir} && npm pack && mv ./nathanvda-cocoon-#{spec.version}.tgz ../pkg/")
|
82
|
+
end
|
83
|
+
|
84
|
+
desc "Build and push nathanvda-cocoon-#{spec.version}.tgz to https://npmjs.org"
|
85
|
+
task release: %i[build] do
|
86
|
+
system("npm publish ./pkg/nathanvda-cocoon-#{spec.version}.tgz --access public")
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.2.
|
1
|
+
1.2.15
|
@@ -39,6 +39,8 @@
|
|
39
39
|
|
40
40
|
$(document).on('click', '.add_fields', function(e) {
|
41
41
|
e.preventDefault();
|
42
|
+
e.stopPropagation();
|
43
|
+
|
42
44
|
var $this = $(this),
|
43
45
|
assoc = $this.data('association'),
|
44
46
|
assocs = $this.data('associations'),
|
@@ -51,7 +53,8 @@
|
|
51
53
|
regexp_underscord = new RegExp('_new_' + assoc + '_(\\w*)', 'g'),
|
52
54
|
new_id = create_new_id(),
|
53
55
|
new_content = content.replace(regexp_braced, newcontent_braced(new_id)),
|
54
|
-
new_contents = []
|
56
|
+
new_contents = [],
|
57
|
+
originalEvent = e;
|
55
58
|
|
56
59
|
|
57
60
|
if (new_content == content) {
|
@@ -85,7 +88,7 @@
|
|
85
88
|
var contentNode = $(node);
|
86
89
|
|
87
90
|
var before_insert = jQuery.Event('cocoon:before-insert');
|
88
|
-
insertionNodeElem.trigger(before_insert, [contentNode]);
|
91
|
+
insertionNodeElem.trigger(before_insert, [contentNode, originalEvent]);
|
89
92
|
|
90
93
|
if (!before_insert.isDefaultPrevented()) {
|
91
94
|
// allow any of the jquery dom manipulation methods (after, before, append, prepend, etc)
|
@@ -93,7 +96,8 @@
|
|
93
96
|
// code and doesn't force it to be a sibling like after/before does. default: 'before'
|
94
97
|
var addedContent = insertionNodeElem[insertionMethod](contentNode);
|
95
98
|
|
96
|
-
insertionNodeElem.trigger('cocoon:after-insert', [contentNode
|
99
|
+
insertionNodeElem.trigger('cocoon:after-insert', [contentNode,
|
100
|
+
originalEvent]);
|
97
101
|
}
|
98
102
|
});
|
99
103
|
});
|
@@ -102,24 +106,27 @@
|
|
102
106
|
var $this = $(this),
|
103
107
|
wrapper_class = $this.data('wrapper-class') || 'nested-fields',
|
104
108
|
node_to_delete = $this.closest('.' + wrapper_class),
|
105
|
-
trigger_node = node_to_delete.parent()
|
109
|
+
trigger_node = node_to_delete.parent(),
|
110
|
+
originalEvent = e;
|
106
111
|
|
107
112
|
e.preventDefault();
|
113
|
+
e.stopPropagation();
|
108
114
|
|
109
115
|
var before_remove = jQuery.Event('cocoon:before-remove');
|
110
|
-
trigger_node.trigger(before_remove, [node_to_delete]);
|
116
|
+
trigger_node.trigger(before_remove, [node_to_delete, originalEvent]);
|
111
117
|
|
112
118
|
if (!before_remove.isDefaultPrevented()) {
|
113
119
|
var timeout = trigger_node.data('remove-timeout') || 0;
|
114
120
|
|
115
121
|
setTimeout(function() {
|
116
122
|
if ($this.hasClass('dynamic')) {
|
117
|
-
node_to_delete.
|
123
|
+
node_to_delete.detach();
|
118
124
|
} else {
|
119
125
|
$this.prev("input[type=hidden]").val("1");
|
120
126
|
node_to_delete.hide();
|
121
127
|
}
|
122
|
-
trigger_node.trigger('cocoon:after-remove', [node_to_delete
|
128
|
+
trigger_node.trigger('cocoon:after-remove', [node_to_delete,
|
129
|
+
originalEvent]);
|
123
130
|
}, timeout);
|
124
131
|
}
|
125
132
|
});
|
data/cocoon.gemspec
CHANGED
@@ -2,36 +2,40 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: cocoon 1.2.
|
5
|
+
# stub: cocoon 1.2.15 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "cocoon".freeze
|
9
|
-
s.version = "1.2.
|
9
|
+
s.version = "1.2.15"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib".freeze]
|
13
13
|
s.authors = ["Nathan Van der Auwera".freeze]
|
14
|
-
s.date = "
|
14
|
+
s.date = "2020-09-08"
|
15
15
|
s.description = "Unobtrusive nested forms handling, using jQuery. Use this and discover cocoon-heaven.".freeze
|
16
16
|
s.email = "nathan@dixis.com".freeze
|
17
17
|
s.extra_rdoc_files = [
|
18
|
+
"LICENSE",
|
18
19
|
"README.markdown"
|
19
20
|
]
|
20
21
|
s.files = [
|
21
22
|
".travis.yml",
|
22
23
|
"Gemfile",
|
23
24
|
"History.md",
|
24
|
-
"
|
25
|
+
"LICENSE",
|
25
26
|
"README.markdown",
|
26
27
|
"Rakefile",
|
27
28
|
"VERSION",
|
28
29
|
"app/assets/javascripts/cocoon.js",
|
29
30
|
"cocoon.gemspec",
|
31
|
+
"gemfiles/Gemfile.default",
|
30
32
|
"gemfiles/Gemfile.rails-3.2.13",
|
31
33
|
"gemfiles/Gemfile.rails-4-r2",
|
32
34
|
"lib/cocoon.rb",
|
33
35
|
"lib/cocoon/view_helpers.rb",
|
34
36
|
"lib/generators/cocoon/install/install_generator.rb",
|
37
|
+
"npm/README.md",
|
38
|
+
"npm/package.json.erb",
|
35
39
|
"spec/cocoon_spec.rb",
|
36
40
|
"spec/dummy/Rakefile",
|
37
41
|
"spec/dummy/app/controllers/application_controller.rb",
|
@@ -82,17 +86,17 @@ Gem::Specification.new do |s|
|
|
82
86
|
]
|
83
87
|
s.homepage = "http://github.com/nathanvda/cocoon".freeze
|
84
88
|
s.licenses = ["MIT".freeze]
|
85
|
-
s.rubygems_version = "
|
89
|
+
s.rubygems_version = "3.0.8".freeze
|
86
90
|
s.summary = "gem that enables easier nested forms with standard forms, formtastic and simple-form".freeze
|
87
91
|
|
88
92
|
if s.respond_to? :specification_version then
|
89
93
|
s.specification_version = 4
|
90
94
|
|
91
95
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
92
|
-
s.add_development_dependency(%q<rails>.freeze, ["
|
96
|
+
s.add_development_dependency(%q<rails>.freeze, ["~> 4.2"])
|
93
97
|
s.add_development_dependency(%q<sqlite3>.freeze, ["= 1.3.13"])
|
94
98
|
s.add_development_dependency(%q<json_pure>.freeze, [">= 0"])
|
95
|
-
s.add_development_dependency(%q<jeweler>.freeze, ["
|
99
|
+
s.add_development_dependency(%q<jeweler>.freeze, [">= 0"])
|
96
100
|
s.add_development_dependency(%q<rspec-rails>.freeze, ["~> 3.0.0"])
|
97
101
|
s.add_development_dependency(%q<rspec>.freeze, ["~> 3.0.0"])
|
98
102
|
s.add_development_dependency(%q<actionpack>.freeze, [">= 4.0.0"])
|
@@ -106,10 +110,10 @@ Gem::Specification.new do |s|
|
|
106
110
|
s.add_development_dependency(%q<racc>.freeze, [">= 0"])
|
107
111
|
s.add_development_dependency(%q<rubinius-developer_tools>.freeze, [">= 0"])
|
108
112
|
else
|
109
|
-
s.add_dependency(%q<rails>.freeze, ["
|
113
|
+
s.add_dependency(%q<rails>.freeze, ["~> 4.2"])
|
110
114
|
s.add_dependency(%q<sqlite3>.freeze, ["= 1.3.13"])
|
111
115
|
s.add_dependency(%q<json_pure>.freeze, [">= 0"])
|
112
|
-
s.add_dependency(%q<jeweler>.freeze, ["
|
116
|
+
s.add_dependency(%q<jeweler>.freeze, [">= 0"])
|
113
117
|
s.add_dependency(%q<rspec-rails>.freeze, ["~> 3.0.0"])
|
114
118
|
s.add_dependency(%q<rspec>.freeze, ["~> 3.0.0"])
|
115
119
|
s.add_dependency(%q<actionpack>.freeze, [">= 4.0.0"])
|
@@ -124,10 +128,10 @@ Gem::Specification.new do |s|
|
|
124
128
|
s.add_dependency(%q<rubinius-developer_tools>.freeze, [">= 0"])
|
125
129
|
end
|
126
130
|
else
|
127
|
-
s.add_dependency(%q<rails>.freeze, ["
|
131
|
+
s.add_dependency(%q<rails>.freeze, ["~> 4.2"])
|
128
132
|
s.add_dependency(%q<sqlite3>.freeze, ["= 1.3.13"])
|
129
133
|
s.add_dependency(%q<json_pure>.freeze, [">= 0"])
|
130
|
-
s.add_dependency(%q<jeweler>.freeze, ["
|
134
|
+
s.add_dependency(%q<jeweler>.freeze, [">= 0"])
|
131
135
|
s.add_dependency(%q<rspec-rails>.freeze, ["~> 3.0.0"])
|
132
136
|
s.add_dependency(%q<rspec>.freeze, ["~> 3.0.0"])
|
133
137
|
s.add_dependency(%q<actionpack>.freeze, [">= 4.0.0"])
|
@@ -0,0 +1,31 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
|
4
|
+
group :development, :test do
|
5
|
+
gem "rails", "~> 4.2"
|
6
|
+
gem "sqlite3", '~> 1.3.13'
|
7
|
+
gem "json_pure"
|
8
|
+
gem "jeweler"
|
9
|
+
gem "rspec-rails", "~> 3.0.0"
|
10
|
+
gem "rspec", "~> 3.0.0"
|
11
|
+
gem "simplecov", :require => false
|
12
|
+
gem "rake", "~> 10.1"
|
13
|
+
|
14
|
+
gem 'nokogiri'
|
15
|
+
|
16
|
+
gem "generator_spec"
|
17
|
+
|
18
|
+
platforms :rbx do
|
19
|
+
gem 'rubysl'
|
20
|
+
gem 'rubysl-test-unit'
|
21
|
+
gem 'psych'
|
22
|
+
gem 'racc'
|
23
|
+
gem 'rubinius-developer_tools'
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
|
30
|
+
# gem 'ruby-debug'
|
31
|
+
# gem 'ruby-debug19'
|
data/lib/cocoon/view_helpers.rb
CHANGED
@@ -37,13 +37,14 @@ module Cocoon
|
|
37
37
|
wrapper_class = html_options.delete(:wrapper_class)
|
38
38
|
html_options[:'data-wrapper-class'] = wrapper_class if wrapper_class.present?
|
39
39
|
|
40
|
-
|
40
|
+
f.hidden_field(:_destroy, value: f.object._destroy) + link_to(name, '#', html_options)
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
44
|
# :nodoc:
|
45
|
-
def render_association(association, f, new_object, form_name,
|
45
|
+
def render_association(association, f, new_object, form_name, received_render_options={}, custom_partial=nil)
|
46
46
|
partial = get_partial_path(custom_partial, association)
|
47
|
+
render_options = received_render_options.dup
|
47
48
|
locals = render_options.delete(:locals) || {}
|
48
49
|
ancestors = f.class.ancestors.map{|c| c.to_s}
|
49
50
|
method_name = ancestors.include?('SimpleForm::FormBuilder') ? :simple_fields_for : (ancestors.include?('Formtastic::FormBuilder') ? :semantic_fields_for : :fields_for)
|
@@ -126,7 +127,7 @@ module Cocoon
|
|
126
127
|
end
|
127
128
|
|
128
129
|
def create_object_on_association(f, association, instance, force_non_association_create)
|
129
|
-
if instance.class.name
|
130
|
+
if instance.class.name.starts_with?('Mongoid::') || force_non_association_create
|
130
131
|
create_object_with_conditions(instance)
|
131
132
|
else
|
132
133
|
assoc_obj = nil
|
data/npm/README.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
{
|
2
|
+
"name": "@nathanvda/cocoon",
|
3
|
+
"version": "<%= spec.version %>",
|
4
|
+
"license": "MIT",
|
5
|
+
|
6
|
+
"description": "Companion package for the cocoon Ruby gem.",
|
7
|
+
"homepage": "https://github.com/nathanvda/cocoon",
|
8
|
+
"repository": "https://github.com/nathanvda/cocoon",
|
9
|
+
"bugs": {
|
10
|
+
"url": "https://github.com/nathanvda/cocoon/issues"
|
11
|
+
},
|
12
|
+
|
13
|
+
"author": "nathan@dixis.com",
|
14
|
+
|
15
|
+
"main": "cocoon.js",
|
16
|
+
"files": ["cocoon.js", "README", "LICENSE", "package.json"],
|
17
|
+
|
18
|
+
"dependencies": {
|
19
|
+
"jquery": "^3.3.1"
|
20
|
+
}
|
21
|
+
}
|
data/spec/cocoon_spec.rb
CHANGED
@@ -14,12 +14,12 @@ describe Cocoon do
|
|
14
14
|
before(:each) do
|
15
15
|
@tester = TestClass.new
|
16
16
|
@post = Post.new
|
17
|
-
@form_obj = double(:object => @post, :object_name => @post.class.name)
|
18
17
|
end
|
19
18
|
|
20
19
|
|
21
20
|
context "link_to_add_association" do
|
22
21
|
before(:each) do
|
22
|
+
@form_obj = double(:object => @post, :object_name => @post.class.name)
|
23
23
|
allow(@tester).to receive(:render_association).and_return('form<tag>')
|
24
24
|
end
|
25
25
|
|
@@ -198,9 +198,13 @@ describe Cocoon do
|
|
198
198
|
allow(@tester).to receive(:render_association).and_call_original
|
199
199
|
expect(@form_obj).to receive(:fields_for) { | association, new_object, options_hash, &block| block.call }
|
200
200
|
expect(@tester).to receive(:render).with("person_fields", {:f=>nil, :dynamic=>true, :alfred=>"Judoka"}).and_return ("partiallll")
|
201
|
-
@
|
201
|
+
@render_options = {:wrapper => 'inline', :locals => {:alfred => 'Judoka'}}
|
202
|
+
@html = @tester.link_to_add_association('add something', @form_obj, :people, :render_options => @render_options)
|
202
203
|
end
|
203
204
|
it_behaves_like "a correctly rendered add link", {template: 'partiallll', association: 'person', associations: 'people' }
|
205
|
+
it "does not afffect render-options" do
|
206
|
+
expect(@render_options[:locals]).to eq({alfred: 'Judoka'})
|
207
|
+
end
|
204
208
|
end
|
205
209
|
context "if no locals are given it still works" do
|
206
210
|
before do
|
@@ -272,6 +276,9 @@ describe Cocoon do
|
|
272
276
|
end
|
273
277
|
|
274
278
|
context "link_to_remove_association" do
|
279
|
+
before do
|
280
|
+
@form_obj = @tester.send(:instantiate_builder, @post.class.name, @post, {})
|
281
|
+
end
|
275
282
|
context "without a block" do
|
276
283
|
context "accepts a name" do
|
277
284
|
before do
|
@@ -326,7 +333,7 @@ describe Cocoon do
|
|
326
333
|
before do
|
327
334
|
@post_marked_for_destruction = Post.new
|
328
335
|
@post_marked_for_destruction.mark_for_destruction
|
329
|
-
@form_obj_destroyed =
|
336
|
+
@form_obj_destroyed = @tester.send(:instantiate_builder, @post_marked_for_destruction.class.name, @post_marked_for_destruction, {})
|
330
337
|
@html = @tester.link_to_remove_association('remove something', @form_obj_destroyed)
|
331
338
|
end
|
332
339
|
|
@@ -387,11 +394,11 @@ describe Cocoon do
|
|
387
394
|
# I submitted a bug for this: https://github.com/rails/rails/issues/11376
|
388
395
|
if Rails.rails4?
|
389
396
|
@post = Post.create(title: 'Testing')
|
390
|
-
@form_obj = double(:object => @post, :object_name => @post.class.name)
|
391
397
|
end
|
392
|
-
|
398
|
+
form_obj = double(:object => @post, :object_name => @post.class.name)
|
399
|
+
result = @tester.create_object(form_obj, :admin_comments)
|
393
400
|
expect(result.author).to eq("Admin")
|
394
|
-
expect(
|
401
|
+
expect(form_obj.object.admin_comments).to be_empty
|
395
402
|
end
|
396
403
|
|
397
404
|
it "creates correct association for belongs_to associations" do
|
@@ -420,7 +427,8 @@ describe Cocoon do
|
|
420
427
|
|
421
428
|
it "can create using only conditions not the association" do
|
422
429
|
expect(@tester).to receive(:create_object_with_conditions).and_return('flappie')
|
423
|
-
|
430
|
+
form_obj = @tester.send(:instantiate_builder, @post.class.name, @post, {})
|
431
|
+
expect(@tester.create_object(form_obj, :comments, true)).to eq('flappie')
|
424
432
|
end
|
425
433
|
end
|
426
434
|
|
data/spec/dummy/db/schema.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: UTF-8
|
1
2
|
# This file is auto-generated from the current state of the database. Instead
|
2
3
|
# of editing this file, please use the migrations feature of Active Record to
|
3
4
|
# incrementally modify your database, and then regenerate this schema definition.
|
@@ -8,23 +9,31 @@
|
|
8
9
|
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
9
10
|
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
10
11
|
#
|
11
|
-
# It's strongly recommended
|
12
|
+
# It's strongly recommended that you check this file into your version control system.
|
12
13
|
|
13
|
-
ActiveRecord::Schema.define(:
|
14
|
+
ActiveRecord::Schema.define(version: 20110420222224) do
|
14
15
|
|
15
|
-
create_table "comments", :
|
16
|
+
create_table "comments", force: :cascade do |t|
|
16
17
|
t.text "body"
|
17
18
|
t.string "author"
|
18
19
|
t.integer "post_id"
|
19
|
-
t.datetime "created_at"
|
20
|
-
t.datetime "updated_at"
|
20
|
+
t.datetime "created_at", null: false
|
21
|
+
t.datetime "updated_at", null: false
|
21
22
|
end
|
22
23
|
|
23
|
-
create_table "
|
24
|
+
create_table "people", force: :cascade do |t|
|
25
|
+
t.string "name"
|
26
|
+
t.string "description"
|
27
|
+
t.integer "post_id"
|
28
|
+
t.datetime "created_at", null: false
|
29
|
+
t.datetime "updated_at", null: false
|
30
|
+
end
|
31
|
+
|
32
|
+
create_table "posts", force: :cascade do |t|
|
24
33
|
t.string "title"
|
25
34
|
t.text "body"
|
26
|
-
t.datetime "created_at"
|
27
|
-
t.datetime "updated_at"
|
35
|
+
t.datetime "created_at", null: false
|
36
|
+
t.datetime "updated_at", null: false
|
28
37
|
end
|
29
38
|
|
30
39
|
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cocoon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Van der Auwera
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-09-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 4.
|
19
|
+
version: '4.2'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 4.
|
26
|
+
version: '4.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: sqlite3
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -56,16 +56,16 @@ dependencies:
|
|
56
56
|
name: jeweler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec-rails
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -240,22 +240,26 @@ email: nathan@dixis.com
|
|
240
240
|
executables: []
|
241
241
|
extensions: []
|
242
242
|
extra_rdoc_files:
|
243
|
+
- LICENSE
|
243
244
|
- README.markdown
|
244
245
|
files:
|
245
246
|
- ".travis.yml"
|
246
247
|
- Gemfile
|
247
248
|
- History.md
|
248
|
-
-
|
249
|
+
- LICENSE
|
249
250
|
- README.markdown
|
250
251
|
- Rakefile
|
251
252
|
- VERSION
|
252
253
|
- app/assets/javascripts/cocoon.js
|
253
254
|
- cocoon.gemspec
|
255
|
+
- gemfiles/Gemfile.default
|
254
256
|
- gemfiles/Gemfile.rails-3.2.13
|
255
257
|
- gemfiles/Gemfile.rails-4-r2
|
256
258
|
- lib/cocoon.rb
|
257
259
|
- lib/cocoon/view_helpers.rb
|
258
260
|
- lib/generators/cocoon/install/install_generator.rb
|
261
|
+
- npm/README.md
|
262
|
+
- npm/package.json.erb
|
259
263
|
- spec/cocoon_spec.rb
|
260
264
|
- spec/dummy/Rakefile
|
261
265
|
- spec/dummy/app/controllers/application_controller.rb
|
@@ -322,8 +326,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
322
326
|
- !ruby/object:Gem::Version
|
323
327
|
version: '0'
|
324
328
|
requirements: []
|
325
|
-
|
326
|
-
rubygems_version: 2.6.14
|
329
|
+
rubygems_version: 3.0.8
|
327
330
|
signing_key:
|
328
331
|
specification_version: 4
|
329
332
|
summary: gem that enables easier nested forms with standard forms, formtastic and
|