cocoon 1.0.19 → 1.0.20
Sign up to get free protection for your applications and to get access to all the features.
- data/History.md +31 -0
- data/VERSION +1 -1
- data/cocoon.gemspec +2 -2
- data/lib/cocoon/view_helpers.rb +6 -11
- data/spec/cocoon_spec.rb +21 -7
- metadata +4 -4
data/History.md
CHANGED
@@ -1,5 +1,36 @@
|
|
1
1
|
# Change History / Release Notes
|
2
2
|
|
3
|
+
|
4
|
+
## Version 1.0.20
|
5
|
+
|
6
|
+
* improved handing of the `:partial`: remove the extra options-hash, and just make it use the single hash, so now we can just write
|
7
|
+
|
8
|
+
= link_to_add_association 'add something', f, :tasks, :partial => 'shared/task_fields'
|
9
|
+
= link_to_add_association 'add something', f, :tasks, :class => 'your-special-class', :partial => 'shared/task_fields'
|
10
|
+
|
11
|
+
|
12
|
+
## Version 1.0.19
|
13
|
+
|
14
|
+
* pull #53 (@CuriousCurmudgeon): fixed some bugs introduced in previous version (ooooops! Thanks!!!)
|
15
|
+
|
16
|
+
## Version 1.0.18
|
17
|
+
|
18
|
+
* pull in #51 (@erwin): adding an `after-removal-callback` in javascript, very useful if you want to recalculate e.g. total-items or indexes
|
19
|
+
* pull in #42 (@zacstewart): allow to hand extra `:locals` to the partial
|
20
|
+
* updated documentation
|
21
|
+
|
22
|
+
## Version 1.0.17
|
23
|
+
|
24
|
+
* fix: make sure that cocoon still works for rails 3.0, where the `conditions` is not available yet
|
25
|
+
|
26
|
+
## Version 1.0.16
|
27
|
+
|
28
|
+
* merged pull request #33 (@fl00r): added the a custom partial option! genius :)
|
29
|
+
Also the creation of the nested objects takes any available conditions into account.
|
30
|
+
Now you can write
|
31
|
+
|
32
|
+
= link_to_add_association 'add something', f, :tasks, {}, :partial => 'shared/task_fields'
|
33
|
+
|
3
34
|
## Version 1.0.15
|
4
35
|
|
5
36
|
* added `data-association-insertion-method` that gives more control over where to insert the new nested fields.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.20
|
data/cocoon.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "cocoon"
|
8
|
-
s.version = "1.0.
|
8
|
+
s.version = "1.0.20"
|
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 = "2012-04-
|
12
|
+
s.date = "2012-04-09"
|
13
13
|
s.description = "Unobtrusive nested forms handling, using jQuery. Use this and discover cocoon-heaven."
|
14
14
|
s.email = "nathan@dixis.com"
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/cocoon/view_helpers.rb
CHANGED
@@ -32,7 +32,7 @@ module Cocoon
|
|
32
32
|
|
33
33
|
# :nodoc:
|
34
34
|
def render_association(association, f, new_object, render_options={}, custom_partial=nil)
|
35
|
-
partial =
|
35
|
+
partial = get_partial_path(custom_partial, association)
|
36
36
|
locals = render_options.delete(:locals) || {}
|
37
37
|
method_name = f.respond_to?(:semantic_fields_for) ? :semantic_fields_for : (f.respond_to?(:simple_fields_for) ? :simple_fields_for : :fields_for)
|
38
38
|
f.send(method_name, association, new_object, {:child_index => "new_#{association}"}.merge(render_options)) do |builder|
|
@@ -57,24 +57,23 @@ module Cocoon
|
|
57
57
|
f = args[0]
|
58
58
|
association = args[1]
|
59
59
|
html_options = args[2] || {}
|
60
|
-
|
61
|
-
link_to_add_association(capture(&block), f, association, html_options, options)
|
60
|
+
link_to_add_association(capture(&block), f, association, html_options)
|
62
61
|
else
|
63
62
|
name = args[0]
|
64
63
|
f = args[1]
|
65
64
|
association = args[2]
|
66
65
|
html_options = args[3] || {}
|
67
|
-
options = args[4] || {}
|
68
66
|
|
69
67
|
render_options = html_options.delete(:render_options)
|
70
68
|
render_options ||= {}
|
69
|
+
override_partial = html_options.delete(:partial)
|
71
70
|
|
72
71
|
html_options[:class] = [html_options[:class], "add_fields"].compact.join(' ')
|
73
72
|
html_options[:'data-association'] = association.to_s.singularize
|
74
73
|
html_options[:'data-associations'] = association.to_s.pluralize
|
75
74
|
|
76
75
|
new_object = create_object(f, association)
|
77
|
-
html_options[:'data-template'] = CGI.escapeHTML(render_association(association, f, new_object, render_options,
|
76
|
+
html_options[:'data-template'] = CGI.escapeHTML(render_association(association, f, new_object, render_options, override_partial)).html_safe
|
78
77
|
|
79
78
|
link_to(name, '#', html_options )
|
80
79
|
end
|
@@ -90,12 +89,8 @@ module Cocoon
|
|
90
89
|
new_object = assoc.klass.new(*conditions)
|
91
90
|
end
|
92
91
|
|
93
|
-
def
|
94
|
-
|
95
|
-
partial
|
96
|
-
else
|
97
|
-
association.to_s.singularize + "_fields"
|
98
|
-
end
|
92
|
+
def get_partial_path(partial, association)
|
93
|
+
partial ? partial : association.to_s.singularize + "_fields"
|
99
94
|
end
|
100
95
|
|
101
96
|
end
|
data/spec/cocoon_spec.rb
CHANGED
@@ -28,6 +28,13 @@ describe Cocoon do
|
|
28
28
|
result = @tester.link_to_add_association('add something', @form_obj, :comments, {:class => 'something silly'})
|
29
29
|
result.to_s.should == '<a href="#" class="something silly add_fields" data-association="comment" data-associations="comments" data-template="form<tag>">add something</a>'
|
30
30
|
end
|
31
|
+
|
32
|
+
it "allows to explicitly hand the wanted partial" do
|
33
|
+
@tester.unstub(:render_association)
|
34
|
+
@tester.should_receive(:render_association).with(anything(), anything(), anything(), anything(), "shared/partial").and_return('partiallll')
|
35
|
+
result = @tester.link_to_add_association('add something', @form_obj, :comments, :partial => "shared/partial")
|
36
|
+
result.to_s.should == '<a href="#" class="add_fields" data-association="comment" data-associations="comments" data-template="partiallll">add something</a>'
|
37
|
+
end
|
31
38
|
end
|
32
39
|
|
33
40
|
context "with a block" do
|
@@ -45,10 +52,10 @@ describe Cocoon do
|
|
45
52
|
result.to_s.should == '<a href="#" class="floppy disk add_fields" data-association="comment" data-associations="comments" data-template="form<tag>">some long name</a>'
|
46
53
|
end
|
47
54
|
|
48
|
-
it "
|
55
|
+
it "allows to explicitly hand the wanted partial" do
|
49
56
|
@tester.unstub(:render_association)
|
50
57
|
@tester.should_receive(:render_association).with(anything(), anything(), anything(), anything(), "shared/partial").and_return('partiallll')
|
51
|
-
result = @tester.link_to_add_association( @form_obj, :comments,
|
58
|
+
result = @tester.link_to_add_association( @form_obj, :comments, :class => 'floppy disk', :partial => "shared/partial") do
|
52
59
|
"some long name"
|
53
60
|
end
|
54
61
|
result.to_s.should == '<a href="#" class="floppy disk add_fields" data-association="comment" data-associations="comments" data-template="partiallll">some long name</a>'
|
@@ -81,14 +88,21 @@ describe Cocoon do
|
|
81
88
|
end
|
82
89
|
end
|
83
90
|
|
84
|
-
context "
|
85
|
-
it "
|
91
|
+
context "passing locals to the partial" do
|
92
|
+
it "when given: passes the locals to the partials" do
|
86
93
|
@tester.unstub(:render_association)
|
87
94
|
@form_obj.should_receive(:fields_for) { | association, new_object, options_hash, &block| block.call }
|
88
95
|
@tester.should_receive(:render).with("person_fields", {:f=>nil, :dynamic=>true, :alfred=>"Judoka"}).and_return ("partiallll")
|
89
96
|
result = @tester.link_to_add_association('add something', @form_obj, :people, :render_options => {:wrapper => 'inline', :locals => {:alfred => 'Judoka'}})
|
90
97
|
result.to_s.should == '<a href="#" class="add_fields" data-association="person" data-associations="people" data-template="partiallll">add something</a>'
|
91
98
|
end
|
99
|
+
it "if no locals are given it still works" do
|
100
|
+
@tester.unstub(:render_association)
|
101
|
+
@form_obj.should_receive(:fields_for) { | association, new_object, options_hash, &block| block.call }
|
102
|
+
@tester.should_receive(:render).with("person_fields", {:f=>nil, :dynamic=>true}).and_return ("partiallll")
|
103
|
+
result = @tester.link_to_add_association('add something', @form_obj, :people, :render_options => {:wrapper => 'inline'})
|
104
|
+
result.to_s.should == '<a href="#" class="add_fields" data-association="person" data-associations="people" data-template="partiallll">add something</a>'
|
105
|
+
end
|
92
106
|
end
|
93
107
|
|
94
108
|
|
@@ -168,13 +182,13 @@ describe Cocoon do
|
|
168
182
|
end
|
169
183
|
end
|
170
184
|
|
171
|
-
context "
|
185
|
+
context "get_partial_path" do
|
172
186
|
it "generates the default partial name if no partial given" do
|
173
|
-
result = @tester.
|
187
|
+
result = @tester.get_partial_path(nil, :admin_comments)
|
174
188
|
result.should == "admin_comment_fields"
|
175
189
|
end
|
176
190
|
it "uses the given partial name" do
|
177
|
-
result = @tester.
|
191
|
+
result = @tester.get_partial_path("comment_fields", :admin_comments)
|
178
192
|
result.should == "comment_fields"
|
179
193
|
end
|
180
194
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cocoon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 63
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 20
|
10
|
+
version: 1.0.20
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Nathan Van der Auwera
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-04-
|
18
|
+
date: 2012-04-09 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
requirement: &id001 !ruby/object:Gem::Requirement
|