cocoon 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NzE3MjkzZDE4NTVjN2ZiNDU3MzMxYjg4ZGEyNmU5NDBkMzMwNWFlMw==
5
+ data.tar.gz: !binary |-
6
+ ZDViZDlhNjdkMDUwMTBkZmZmMDQ4OTgyMjc3NzJjYmQ2OGIwYjkzNA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ M2JjZGMyOGQzZDliYTM2NmM5Y2ZmMGZiZWRhMTQ3NDE1YjkzYWQ3MDRjOTI0
10
+ MWYwYjAzM2Q4OWIyYzBmYTlhNTQ4ZmM0YjJmYjYxZTlkZDM3MTQ2MGQyNmM1
11
+ YTJmZmNiZTYwM2VmNTY5OGFhZjU1ZjhhZGJmMTEzYmJlYjEwZWY=
12
+ data.tar.gz: !binary |-
13
+ ZTg4ZmVhZmE1MmEzMmQwNzVkOGMyMTViMTBkYTQ4ZmY5OTkzMWUxZmJmZGZi
14
+ ZDc2MjkxZTFkMzFhNmI5NGZjODE5YzQxMWNlOWJjNWI4NGZiMTFmNjBiNjQy
15
+ OTBkN2E4ZmVlNmJhMmRkMTQwOTAzZGE3ODA3OWZhMTdlOTMwZjY=
data/README.markdown CHANGED
@@ -96,10 +96,11 @@ E.g. in your `ProjectsController`:
96
96
  end
97
97
  ```
98
98
 
99
-
100
-
101
99
  ## Examples
102
100
 
101
+ Cocoon's default configuration requires `link_to_add_association` and associated partials to
102
+ be properly wrapped with elements. The examples below illustrate simple layouts.
103
+
103
104
  ### Formtastic
104
105
 
105
106
  In our `projects/_form` partial we'd write:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.1
1
+ 1.2.2
@@ -2,9 +2,16 @@
2
2
 
3
3
  var cocoon_element_counter = 0;
4
4
 
5
- function replace_in_content(content, regexp_str, with_str) {
6
- reg_exp = new RegExp(regexp_str);
7
- content.replace(reg_exp, with_str);
5
+ var create_new_id = function() {
6
+ return (new Date().getTime() + cocoon_element_counter++);
7
+ }
8
+
9
+ var newcontent_braced = function(id) {
10
+ return '[' + id + ']$1';
11
+ }
12
+
13
+ var newcontent_underscord = function(id) {
14
+ return '_' + id + '_$1';
8
15
  }
9
16
 
10
17
  $(document).on('click', '.add_fields', function(e) {
@@ -16,21 +23,35 @@
16
23
  insertionMethod = $this.data('association-insertion-method') || $this.data('association-insertion-position') || 'before',
17
24
  insertionNode = $this.data('association-insertion-node'),
18
25
  insertionTraversal = $this.data('association-insertion-traversal'),
26
+ count = parseInt($this.data('count'), 10),
19
27
  regexp_braced = new RegExp('\\[new_' + assoc + '\\](.*?\\s)', 'g'),
20
28
  regexp_underscord = new RegExp('_new_' + assoc + '_(\\w*)', 'g'),
21
- new_id = new Date().getTime() + cocoon_element_counter++,
22
- newcontent_braced = '[' + new_id + ']',
23
- newcontent_underscord = '_' + new_id + '_',
24
- new_content = content.replace(regexp_braced, '[' + new_id + ']$1');
29
+ new_id = create_new_id(),
30
+ new_content = content.replace(regexp_braced, newcontent_braced(new_id)),
31
+ new_contents = [];
25
32
 
33
+
26
34
  if (new_content == content) {
27
- regexp_braced = new RegExp('\\[new_' + assocs + '\\](.*?\\s)', 'g');
28
- regexp_underscord = new RegExp('_new_' + assocs + '_(\\w*)', 'g');
29
- new_content = content.replace(regexp_braced, '[' + new_id + ']$1');
35
+ regexp_braced = new RegExp('\\[new_' + assocs + '\\](.*?\\s)', 'g');
36
+ regexp_underscord = new RegExp('_new_' + assocs + '_(\\w*)', 'g');
37
+ new_content = content.replace(regexp_braced, newcontent_braced(new_id));
30
38
  }
31
39
 
32
- new_content = new_content.replace(regexp_underscord, newcontent_underscord + "$1");
33
-
40
+ new_content = new_content.replace(regexp_underscord, newcontent_underscord(new_id));
41
+ new_contents = [new_content];
42
+
43
+ count = (isNaN(count) ? 1 : Math.max(count, 1));
44
+ count -= 1;
45
+
46
+ while (count) {
47
+ new_id = create_new_id();
48
+ new_content = content.replace(regexp_braced, newcontent_braced(new_id));
49
+ new_content = new_content.replace(regexp_underscord, newcontent_underscord(new_id));
50
+ new_contents.push(new_content);
51
+
52
+ count -= 1;
53
+ }
54
+
34
55
  if (insertionNode){
35
56
  if (insertionTraversal){
36
57
  insertionNode = $this[insertionTraversal](insertionNode);
@@ -41,16 +62,18 @@
41
62
  insertionNode = $this.parent();
42
63
  }
43
64
 
44
- var contentNode = $(new_content);
65
+ for (var i in new_contents) {
66
+ var contentNode = $(new_contents[i]);
45
67
 
46
- insertionNode.trigger('cocoon:before-insert', [contentNode]);
68
+ insertionNode.trigger('cocoon:before-insert', [contentNode]);
47
69
 
48
- // allow any of the jquery dom manipulation methods (after, before, append, prepend, etc)
49
- // to be called on the node. allows the insertion node to be the parent of the inserted
50
- // code and doesn't force it to be a sibling like after/before does. default: 'before'
51
- var addedContent = insertionNode[insertionMethod](contentNode);
70
+ // allow any of the jquery dom manipulation methods (after, before, append, prepend, etc)
71
+ // to be called on the node. allows the insertion node to be the parent of the inserted
72
+ // code and doesn't force it to be a sibling like after/before does. default: 'before'
73
+ var addedContent = insertionNode[insertionMethod](contentNode);
52
74
 
53
- insertionNode.trigger('cocoon:after-insert', [contentNode]);
75
+ insertionNode.trigger('cocoon:after-insert', [contentNode]);
76
+ }
54
77
  });
55
78
 
56
79
  $(document).on('click', '.remove_fields.dynamic, .remove_fields.existing', function(e) {
@@ -66,10 +89,10 @@
66
89
 
67
90
  setTimeout(function() {
68
91
  if ($this.hasClass('dynamic')) {
69
- $this.closest(".nested-fields").remove();
92
+ node_to_delete.remove();
70
93
  } else {
71
94
  $this.prev("input[type=hidden]").val("1");
72
- $this.closest(".nested-fields").hide();
95
+ node_to_delete.hide();
73
96
  }
74
97
  trigger_node.trigger('cocoon:after-remove', [node_to_delete]);
75
98
  }, timeout);
data/cocoon.gemspec CHANGED
@@ -2,14 +2,15 @@
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.2 ruby lib
5
6
 
6
7
  Gem::Specification.new do |s|
7
8
  s.name = "cocoon"
8
- s.version = "1.2.1"
9
+ s.version = "1.2.2"
9
10
 
10
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
12
  s.authors = ["Nathan Van der Auwera"]
12
- s.date = "2013-09-25"
13
+ s.date = "2013-11-14"
13
14
  s.description = "Unobtrusive nested forms handling, using jQuery. Use this and discover cocoon-heaven."
14
15
  s.email = "nathan@dixis.com"
15
16
  s.extra_rdoc_files = [
@@ -80,11 +81,11 @@ Gem::Specification.new do |s|
80
81
  ]
81
82
  s.homepage = "http://github.com/nathanvda/cocoon"
82
83
  s.require_paths = ["lib"]
83
- s.rubygems_version = "1.8.25"
84
+ s.rubygems_version = "2.1.11"
84
85
  s.summary = "gem that enables easier nested forms with standard forms, formtastic and simple-form"
85
86
 
86
87
  if s.respond_to? :specification_version then
87
- s.specification_version = 3
88
+ s.specification_version = 4
88
89
 
89
90
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
90
91
  s.add_development_dependency(%q<rails>, [">= 4.0.0"])
@@ -58,6 +58,7 @@ module Cocoon
58
58
  # - *:wrap_object* : a proc that will allow to wrap your object, especially suited when using
59
59
  # decorators, or if you want special initialisation
60
60
  # - *:form_name* : the parameter for the form in the nested form partial. Default `f`.
61
+ # - *:count* : Count of how many objects will be added on a single click. Default `1`.
61
62
  # - *&block*: see <tt>link_to</tt>
62
63
 
63
64
  def link_to_add_association(*args, &block)
@@ -78,6 +79,7 @@ module Cocoon
78
79
  wrap_object = html_options.delete(:wrap_object)
79
80
  force_non_association_create = html_options.delete(:force_non_association_create) || false
80
81
  form_parameter_name = html_options.delete(:form_name) || 'f'
82
+ count = html_options.delete(:count).to_i
81
83
 
82
84
  html_options[:class] = [html_options[:class], "add_fields"].compact.join(' ')
83
85
  html_options[:'data-association'] = association.to_s.singularize
@@ -87,8 +89,10 @@ module Cocoon
87
89
  new_object = wrap_object.call(new_object) if wrap_object.respond_to?(:call)
88
90
 
89
91
  html_options[:'data-association-insertion-template'] = CGI.escapeHTML(render_association(association, f, new_object, form_parameter_name, render_options, override_partial)).html_safe
92
+
93
+ html_options[:'data-count'] = count if count > 0
90
94
 
91
- link_to(name, '#', html_options )
95
+ link_to(name, '#', html_options)
92
96
  end
93
97
  end
94
98
 
data/spec/cocoon_spec.rb CHANGED
@@ -238,6 +238,13 @@ describe Cocoon do
238
238
  end
239
239
  end
240
240
 
241
+ context 'when adding a count' do
242
+ before do
243
+ @html = @tester.link_to_add_association('add something', @form_obj, :comments, { :count => 3 })
244
+ end
245
+ it_behaves_like "a correctly rendered add link", { :extra_attributes => { 'data-count' => '3' } }
246
+ end
247
+
241
248
  end
242
249
 
243
250
  context "link_to_remove_association" do
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocoon
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
5
- prerelease:
4
+ version: 1.2.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Nathan Van der Auwera
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-09-25 00:00:00.000000000 Z
11
+ date: 2013-11-14 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rails
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ! '>='
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ! '>='
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: sqlite3
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ! '>='
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ! '>='
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: json_pure
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ! '>='
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ! '>='
60
53
  - !ruby/object:Gem::Version
@@ -62,7 +55,6 @@ dependencies:
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: jeweler
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ! '>='
68
60
  - !ruby/object:Gem::Version
@@ -70,7 +62,6 @@ dependencies:
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - ! '>='
76
67
  - !ruby/object:Gem::Version
@@ -78,7 +69,6 @@ dependencies:
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: rspec-rails
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
73
  - - ! '>='
84
74
  - !ruby/object:Gem::Version
@@ -86,7 +76,6 @@ dependencies:
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
80
  - - ! '>='
92
81
  - !ruby/object:Gem::Version
@@ -94,7 +83,6 @@ dependencies:
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: rspec
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
87
  - - ! '>='
100
88
  - !ruby/object:Gem::Version
@@ -102,7 +90,6 @@ dependencies:
102
90
  type: :development
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
94
  - - ! '>='
108
95
  - !ruby/object:Gem::Version
@@ -110,7 +97,6 @@ dependencies:
110
97
  - !ruby/object:Gem::Dependency
111
98
  name: actionpack
112
99
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
100
  requirements:
115
101
  - - ! '>='
116
102
  - !ruby/object:Gem::Version
@@ -118,7 +104,6 @@ dependencies:
118
104
  type: :development
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
107
  requirements:
123
108
  - - ! '>='
124
109
  - !ruby/object:Gem::Version
@@ -126,7 +111,6 @@ dependencies:
126
111
  - !ruby/object:Gem::Dependency
127
112
  name: simplecov
128
113
  requirement: !ruby/object:Gem::Requirement
129
- none: false
130
114
  requirements:
131
115
  - - ! '>='
132
116
  - !ruby/object:Gem::Version
@@ -134,7 +118,6 @@ dependencies:
134
118
  type: :development
135
119
  prerelease: false
136
120
  version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
121
  requirements:
139
122
  - - ! '>='
140
123
  - !ruby/object:Gem::Version
@@ -142,7 +125,6 @@ dependencies:
142
125
  - !ruby/object:Gem::Dependency
143
126
  name: nokogiri
144
127
  requirement: !ruby/object:Gem::Requirement
145
- none: false
146
128
  requirements:
147
129
  - - ! '>='
148
130
  - !ruby/object:Gem::Version
@@ -150,7 +132,6 @@ dependencies:
150
132
  type: :development
151
133
  prerelease: false
152
134
  version_requirements: !ruby/object:Gem::Requirement
153
- none: false
154
135
  requirements:
155
136
  - - ! '>='
156
137
  - !ruby/object:Gem::Version
@@ -158,7 +139,6 @@ dependencies:
158
139
  - !ruby/object:Gem::Dependency
159
140
  name: generator_spec
160
141
  requirement: !ruby/object:Gem::Requirement
161
- none: false
162
142
  requirements:
163
143
  - - ! '>='
164
144
  - !ruby/object:Gem::Version
@@ -166,7 +146,6 @@ dependencies:
166
146
  type: :development
167
147
  prerelease: false
168
148
  version_requirements: !ruby/object:Gem::Requirement
169
- none: false
170
149
  requirements:
171
150
  - - ! '>='
172
151
  - !ruby/object:Gem::Version
@@ -174,7 +153,6 @@ dependencies:
174
153
  - !ruby/object:Gem::Dependency
175
154
  name: rspec
176
155
  requirement: !ruby/object:Gem::Requirement
177
- none: false
178
156
  requirements:
179
157
  - - ! '>='
180
158
  - !ruby/object:Gem::Version
@@ -182,7 +160,6 @@ dependencies:
182
160
  type: :development
183
161
  prerelease: false
184
162
  version_requirements: !ruby/object:Gem::Requirement
185
- none: false
186
163
  requirements:
187
164
  - - ! '>='
188
165
  - !ruby/object:Gem::Version
@@ -258,30 +235,26 @@ files:
258
235
  - spec/support/shared_examples.rb
259
236
  homepage: http://github.com/nathanvda/cocoon
260
237
  licenses: []
238
+ metadata: {}
261
239
  post_install_message:
262
240
  rdoc_options: []
263
241
  require_paths:
264
242
  - lib
265
243
  required_ruby_version: !ruby/object:Gem::Requirement
266
- none: false
267
244
  requirements:
268
245
  - - ! '>='
269
246
  - !ruby/object:Gem::Version
270
247
  version: '0'
271
- segments:
272
- - 0
273
- hash: -3336163965730752832
274
248
  required_rubygems_version: !ruby/object:Gem::Requirement
275
- none: false
276
249
  requirements:
277
250
  - - ! '>='
278
251
  - !ruby/object:Gem::Version
279
252
  version: '0'
280
253
  requirements: []
281
254
  rubyforge_project:
282
- rubygems_version: 1.8.25
255
+ rubygems_version: 2.1.11
283
256
  signing_key:
284
- specification_version: 3
257
+ specification_version: 4
285
258
  summary: gem that enables easier nested forms with standard forms, formtastic and
286
259
  simple-form
287
260
  test_files: []