cocoon 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +9 -0
- data/VERSION +1 -1
- data/cocoon.gemspec +6 -2
- data/lib/cocoon/view_helpers.rb +1 -0
- data/lib/generators/cocoon/install/templates/cocoon.js +23 -3
- data/spec/cocoon_spec.rb +12 -4
- data/spec/dummy/app/models/person.rb +2 -0
- data/spec/dummy/app/models/post.rb +1 -0
- data/spec/dummy/db/migrate/20110420222224_create_people.rb +15 -0
- metadata +8 -4
data/README.markdown
CHANGED
@@ -124,6 +124,15 @@ It takes four parameters:
|
|
124
124
|
|
125
125
|
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).
|
126
126
|
|
127
|
+
There is an option to add a callback on insertion. The callback can be added as follows:
|
128
|
+
|
129
|
+
$("#todo_tasks a.add_fields").
|
130
|
+
data("insertion-callback",
|
131
|
+
function() {
|
132
|
+
$(this).find("textarea").autoResize({extraSpace:0}).change();
|
133
|
+
});
|
134
|
+
|
135
|
+
|
127
136
|
### link_to_remove_association
|
128
137
|
|
129
138
|
This function will add a link to your markup that will, when clicked, dynamically remove the surrounding partial form.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.4
|
data/cocoon.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{cocoon}
|
8
|
-
s.version = "1.0.
|
8
|
+
s.version = "1.0.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Nathan Van der Auwera"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-04-25}
|
13
13
|
s.description = %q{Unobtrusive nested forms handling, using jQuery. Use this and discover cocoon-heaven.}
|
14
14
|
s.email = %q{nathan@dixis.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -33,6 +33,7 @@ Gem::Specification.new do |s|
|
|
33
33
|
"spec/dummy/app/controllers/application_controller.rb",
|
34
34
|
"spec/dummy/app/helpers/application_helper.rb",
|
35
35
|
"spec/dummy/app/models/comment.rb",
|
36
|
+
"spec/dummy/app/models/person.rb",
|
36
37
|
"spec/dummy/app/models/post.rb",
|
37
38
|
"spec/dummy/app/views/layouts/application.html.erb",
|
38
39
|
"spec/dummy/config.ru",
|
@@ -52,6 +53,7 @@ Gem::Specification.new do |s|
|
|
52
53
|
"spec/dummy/config/routes.rb",
|
53
54
|
"spec/dummy/db/migrate/20110306212208_create_posts.rb",
|
54
55
|
"spec/dummy/db/migrate/20110306212250_create_comments.rb",
|
56
|
+
"spec/dummy/db/migrate/20110420222224_create_people.rb",
|
55
57
|
"spec/dummy/db/schema.rb",
|
56
58
|
"spec/dummy/public/404.html",
|
57
59
|
"spec/dummy/public/422.html",
|
@@ -76,6 +78,7 @@ Gem::Specification.new do |s|
|
|
76
78
|
s.test_files = [
|
77
79
|
"spec/spec_helper.rb",
|
78
80
|
"spec/dummy/app/controllers/application_controller.rb",
|
81
|
+
"spec/dummy/app/models/person.rb",
|
79
82
|
"spec/dummy/app/models/comment.rb",
|
80
83
|
"spec/dummy/app/models/post.rb",
|
81
84
|
"spec/dummy/app/helpers/application_helper.rb",
|
@@ -93,6 +96,7 @@ Gem::Specification.new do |s|
|
|
93
96
|
"spec/dummy/config/boot.rb",
|
94
97
|
"spec/dummy/db/schema.rb",
|
95
98
|
"spec/dummy/db/migrate/20110306212208_create_posts.rb",
|
99
|
+
"spec/dummy/db/migrate/20110420222224_create_people.rb",
|
96
100
|
"spec/dummy/db/migrate/20110306212250_create_comments.rb",
|
97
101
|
"spec/cocoon_spec.rb",
|
98
102
|
"spec/integration/navigation_spec.rb"
|
data/lib/cocoon/view_helpers.rb
CHANGED
@@ -59,6 +59,7 @@ module Cocoon
|
|
59
59
|
|
60
60
|
html_options[:class] = [html_options[:class], "add_fields"].compact.join(' ')
|
61
61
|
html_options[:'data-association'] = association.to_s.singularize
|
62
|
+
html_options[:'data-associations'] = association.to_s.pluralize
|
62
63
|
|
63
64
|
new_object = f.object.class.reflect_on_association(association).klass.new
|
64
65
|
html_options[:'data-template'] = CGI.escapeHTML(render_association(association, f, new_object))
|
@@ -1,28 +1,48 @@
|
|
1
1
|
$(document).ready(function() {
|
2
2
|
|
3
|
+
function replace_in_content(content, regexp_str, with_str) {
|
4
|
+
reg_exp = new RegExp(regexp_str);
|
5
|
+
content.replace(reg_exp, with_str)
|
6
|
+
}
|
7
|
+
|
8
|
+
|
3
9
|
$('.add_fields').live('click', function() {
|
4
10
|
var assoc = $(this).attr('data-association');
|
11
|
+
var assocs = $(this).attr('data-associations');
|
5
12
|
var content = $(this).attr('data-template');
|
6
13
|
var insertionPosition = $(this).attr('data-association-insertion-position');
|
7
14
|
var insertionNode = $(this).attr('data-association-insertion-node');
|
15
|
+
var insertionCallback = $(this).data('insertion-callback');
|
8
16
|
var regexp_braced = new RegExp('\\[new_' + assoc + '\\]', 'g');
|
17
|
+
var regexp_underscord = new RegExp('_new_' + assoc + '_', 'g');
|
9
18
|
var new_id = new Date().getTime();
|
19
|
+
var newcontent_braced = '[' + new_id + ']';
|
20
|
+
var newcontent_underscord = '_' + new_id + '_';
|
10
21
|
var new_content = content.replace(regexp_braced, '[' + new_id + ']');
|
11
22
|
if (new_content == content) {
|
12
|
-
regexp_braced = new RegExp('\\[new_' +
|
23
|
+
regexp_braced = new RegExp('\\[new_' + assocs + '\\]', 'g');
|
24
|
+
regexp_underscord = new RegExp('_new_' + assocs + '_', 'g');
|
13
25
|
new_content = content.replace(regexp_braced, '[' + new_id + ']');
|
14
26
|
}
|
27
|
+
new_content = new_content.replace(regexp_underscord, newcontent_underscord);
|
28
|
+
|
15
29
|
if (insertionNode) {
|
16
30
|
insertionNode = $(insertionNode);
|
17
31
|
}
|
18
32
|
else {
|
19
33
|
insertionNode = $(this).parent();
|
20
34
|
}
|
35
|
+
|
36
|
+
var contentNode = $(new_content);
|
21
37
|
|
22
38
|
if (insertionPosition == 'after'){
|
23
|
-
insertionNode.after(
|
39
|
+
insertionNode.after(contentNode);
|
24
40
|
} else {
|
25
|
-
insertionNode.before(
|
41
|
+
insertionNode.before(contentNode);
|
42
|
+
}
|
43
|
+
|
44
|
+
if(insertionCallback){
|
45
|
+
insertionCallback.call(contentNode);
|
26
46
|
}
|
27
47
|
|
28
48
|
return false;
|
data/spec/cocoon_spec.rb
CHANGED
@@ -21,12 +21,12 @@ describe Cocoon do
|
|
21
21
|
context "without a block" do
|
22
22
|
it "should accept a name" do
|
23
23
|
result = @tester.link_to_add_association('add something', @form_obj, :comments)
|
24
|
-
result.to_s.should == '<a href="#" class="add_fields" data-association="comment" data-template="form&lt;tag&gt;">add something</a>'
|
24
|
+
result.to_s.should == '<a href="#" class="add_fields" data-association="comment" data-associations="comments" data-template="form&lt;tag&gt;">add something</a>'
|
25
25
|
end
|
26
26
|
|
27
27
|
it "should accept html options and pass them to link_to" do
|
28
28
|
result = @tester.link_to_add_association('add something', @form_obj, :comments, {:class => 'something silly'})
|
29
|
-
result.to_s.should == '<a href="#" class="something silly add_fields" data-association="comment" data-template="form&lt;tag&gt;">add something</a>'
|
29
|
+
result.to_s.should == '<a href="#" class="something silly add_fields" data-association="comment" data-associations="comments" data-template="form&lt;tag&gt;">add something</a>'
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
@@ -35,14 +35,22 @@ describe Cocoon do
|
|
35
35
|
result = @tester.link_to_add_association(@form_obj, :comments) do
|
36
36
|
"some long name"
|
37
37
|
end
|
38
|
-
result.to_s.should == '<a href="#" class="add_fields" data-association="comment" data-template="form&lt;tag&gt;">some long name</a>'
|
38
|
+
result.to_s.should == '<a href="#" class="add_fields" data-association="comment" data-associations="comments" data-template="form&lt;tag&gt;">some long name</a>'
|
39
39
|
end
|
40
40
|
|
41
41
|
it "should accept html options and pass them to link_to" do
|
42
42
|
result = @tester.link_to_add_association(@form_obj, :comments, {:class => 'floppy disk'}) do
|
43
43
|
"some long name"
|
44
44
|
end
|
45
|
-
result.to_s.should == '<a href="#" class="floppy disk add_fields" data-association="comment" data-template="form&lt;tag&gt;">some long name</a>'
|
45
|
+
result.to_s.should == '<a href="#" class="floppy disk add_fields" data-association="comment" data-associations="comments" data-template="form&lt;tag&gt;">some long name</a>'
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
context "with an irregular plural" do
|
51
|
+
it "should use the correct plural" do
|
52
|
+
result = @tester.link_to_add_association('add something', @form_obj, :people)
|
53
|
+
result.to_s.should == '<a href="#" class="add_fields" data-association="person" data-associations="people" data-template="form&lt;tag&gt;">add something</a>'
|
46
54
|
end
|
47
55
|
|
48
56
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 1.0.
|
8
|
+
- 4
|
9
|
+
version: 1.0.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Nathan Van der Auwera
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-
|
17
|
+
date: 2011-04-25 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -58,6 +58,7 @@ files:
|
|
58
58
|
- spec/dummy/app/controllers/application_controller.rb
|
59
59
|
- spec/dummy/app/helpers/application_helper.rb
|
60
60
|
- spec/dummy/app/models/comment.rb
|
61
|
+
- spec/dummy/app/models/person.rb
|
61
62
|
- spec/dummy/app/models/post.rb
|
62
63
|
- spec/dummy/app/views/layouts/application.html.erb
|
63
64
|
- spec/dummy/config.ru
|
@@ -77,6 +78,7 @@ files:
|
|
77
78
|
- spec/dummy/config/routes.rb
|
78
79
|
- spec/dummy/db/migrate/20110306212208_create_posts.rb
|
79
80
|
- spec/dummy/db/migrate/20110306212250_create_comments.rb
|
81
|
+
- spec/dummy/db/migrate/20110420222224_create_people.rb
|
80
82
|
- spec/dummy/db/schema.rb
|
81
83
|
- spec/dummy/public/404.html
|
82
84
|
- spec/dummy/public/422.html
|
@@ -106,7 +108,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
106
108
|
requirements:
|
107
109
|
- - ">="
|
108
110
|
- !ruby/object:Gem::Version
|
109
|
-
hash:
|
111
|
+
hash: 180877711
|
110
112
|
segments:
|
111
113
|
- 0
|
112
114
|
version: "0"
|
@@ -128,6 +130,7 @@ summary: gem that enables easier nested forms with standard forms, formtastic an
|
|
128
130
|
test_files:
|
129
131
|
- spec/spec_helper.rb
|
130
132
|
- spec/dummy/app/controllers/application_controller.rb
|
133
|
+
- spec/dummy/app/models/person.rb
|
131
134
|
- spec/dummy/app/models/comment.rb
|
132
135
|
- spec/dummy/app/models/post.rb
|
133
136
|
- spec/dummy/app/helpers/application_helper.rb
|
@@ -145,6 +148,7 @@ test_files:
|
|
145
148
|
- spec/dummy/config/boot.rb
|
146
149
|
- spec/dummy/db/schema.rb
|
147
150
|
- spec/dummy/db/migrate/20110306212208_create_posts.rb
|
151
|
+
- spec/dummy/db/migrate/20110420222224_create_people.rb
|
148
152
|
- spec/dummy/db/migrate/20110306212250_create_comments.rb
|
149
153
|
- spec/cocoon_spec.rb
|
150
154
|
- spec/integration/navigation_spec.rb
|