awesome_nested_fields 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,4 +1,2 @@
1
1
  source :gemcutter
2
-
3
- # Specify your gem's dependencies in awesome_nested_fields.gemspec
4
2
  gemspec
data/Gemfile.lock CHANGED
@@ -1,74 +1,101 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- awesome_nested_fields (0.0.3)
4
+ awesome_nested_fields (0.6.1)
5
5
  rails (>= 3.0.0)
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
9
9
  specs:
10
- abstract (1.0.0)
11
- actionmailer (3.0.4)
12
- actionpack (= 3.0.4)
13
- mail (~> 2.2.15)
14
- actionpack (3.0.4)
15
- activemodel (= 3.0.4)
16
- activesupport (= 3.0.4)
17
- builder (~> 2.1.2)
18
- erubis (~> 2.6.6)
19
- i18n (~> 0.4)
20
- rack (~> 1.2.1)
21
- rack-mount (~> 0.6.13)
22
- rack-test (~> 0.5.7)
23
- tzinfo (~> 0.3.23)
24
- activemodel (3.0.4)
25
- activesupport (= 3.0.4)
26
- builder (~> 2.1.2)
27
- i18n (~> 0.4)
28
- activerecord (3.0.4)
29
- activemodel (= 3.0.4)
30
- activesupport (= 3.0.4)
31
- arel (~> 2.0.2)
32
- tzinfo (~> 0.3.23)
33
- activeresource (3.0.4)
34
- activemodel (= 3.0.4)
35
- activesupport (= 3.0.4)
36
- activesupport (3.0.4)
37
- arel (2.0.8)
38
- builder (2.1.2)
39
- erubis (2.6.6)
40
- abstract (>= 1.0.0)
41
- i18n (0.5.0)
42
- mail (2.2.15)
43
- activesupport (>= 2.3.6)
10
+ actionmailer (3.2.11)
11
+ actionpack (= 3.2.11)
12
+ mail (~> 2.4.4)
13
+ actionpack (3.2.11)
14
+ activemodel (= 3.2.11)
15
+ activesupport (= 3.2.11)
16
+ builder (~> 3.0.0)
17
+ erubis (~> 2.7.0)
18
+ journey (~> 1.0.4)
19
+ rack (~> 1.4.0)
20
+ rack-cache (~> 1.2)
21
+ rack-test (~> 0.6.1)
22
+ sprockets (~> 2.2.1)
23
+ activemodel (3.2.11)
24
+ activesupport (= 3.2.11)
25
+ builder (~> 3.0.0)
26
+ activerecord (3.2.11)
27
+ activemodel (= 3.2.11)
28
+ activesupport (= 3.2.11)
29
+ arel (~> 3.0.2)
30
+ tzinfo (~> 0.3.29)
31
+ activeresource (3.2.11)
32
+ activemodel (= 3.2.11)
33
+ activesupport (= 3.2.11)
34
+ activesupport (3.2.11)
35
+ i18n (~> 0.6)
36
+ multi_json (~> 1.0)
37
+ ansi (1.4.1)
38
+ arel (3.0.2)
39
+ builder (3.0.4)
40
+ diff-lcs (1.1.3)
41
+ erubis (2.7.0)
42
+ hike (1.2.1)
43
+ i18n (0.6.1)
44
+ journey (1.0.4)
45
+ json (1.7.6)
46
+ mail (2.4.4)
44
47
  i18n (>= 0.4.0)
45
48
  mime-types (~> 1.16)
46
49
  treetop (~> 1.4.8)
47
- mime-types (1.16)
48
- polyglot (0.3.1)
49
- rack (1.2.1)
50
- rack-mount (0.6.13)
51
- rack (>= 1.0.0)
52
- rack-test (0.5.7)
50
+ mime-types (1.19)
51
+ multi_json (1.5.0)
52
+ polyglot (0.3.3)
53
+ rack (1.4.3)
54
+ rack-cache (1.2)
55
+ rack (>= 0.4)
56
+ rack-ssl (1.3.2)
57
+ rack
58
+ rack-test (0.6.2)
53
59
  rack (>= 1.0)
54
- rails (3.0.4)
55
- actionmailer (= 3.0.4)
56
- actionpack (= 3.0.4)
57
- activerecord (= 3.0.4)
58
- activeresource (= 3.0.4)
59
- activesupport (= 3.0.4)
60
+ rails (3.2.11)
61
+ actionmailer (= 3.2.11)
62
+ actionpack (= 3.2.11)
63
+ activerecord (= 3.2.11)
64
+ activeresource (= 3.2.11)
65
+ activesupport (= 3.2.11)
60
66
  bundler (~> 1.0)
61
- railties (= 3.0.4)
62
- railties (3.0.4)
63
- actionpack (= 3.0.4)
64
- activesupport (= 3.0.4)
67
+ railties (= 3.2.11)
68
+ railties (3.2.11)
69
+ actionpack (= 3.2.11)
70
+ activesupport (= 3.2.11)
71
+ rack-ssl (~> 1.3.2)
65
72
  rake (>= 0.8.7)
66
- thor (~> 0.14.4)
67
- rake (0.8.7)
68
- thor (0.14.6)
69
- treetop (1.4.9)
73
+ rdoc (~> 3.4)
74
+ thor (>= 0.14.6, < 2.0)
75
+ rake (10.0.3)
76
+ rdoc (3.12)
77
+ json (~> 1.4)
78
+ rspec (2.7.0)
79
+ rspec-core (~> 2.7.0)
80
+ rspec-expectations (~> 2.7.0)
81
+ rspec-mocks (~> 2.7.0)
82
+ rspec-core (2.7.1)
83
+ rspec-expectations (2.7.0)
84
+ diff-lcs (~> 1.1.2)
85
+ rspec-mocks (2.7.0)
86
+ sprockets (2.2.2)
87
+ hike (~> 1.2)
88
+ multi_json (~> 1.0)
89
+ rack (~> 1.0)
90
+ tilt (~> 1.1, != 1.3.0)
91
+ thor (0.16.0)
92
+ tilt (1.3.3)
93
+ treetop (1.4.12)
94
+ polyglot
70
95
  polyglot (>= 0.3.1)
71
- tzinfo (0.3.24)
96
+ turn (0.8.3)
97
+ ansi
98
+ tzinfo (0.3.35)
72
99
 
73
100
  PLATFORMS
74
101
  ruby
@@ -76,3 +103,5 @@ PLATFORMS
76
103
  DEPENDENCIES
77
104
  awesome_nested_fields!
78
105
  bundler (>= 1.0.0)
106
+ rspec (>= 2)
107
+ turn (~> 0.8.3)
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011 Lailson Bandeira
1
+ Copyright (c) 2011-2012 Lailson Bandeira
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -11,11 +11,15 @@ Installation
11
11
 
12
12
  1. Add the gem to your Gemfile and run `bundle install` to make sure the gem gets installed.
13
13
 
14
- gem 'awesome_nested_fields'
14
+ ```ruby
15
+ gem 'awesome_nested_fields'
16
+ ```
15
17
 
16
18
  2. Add this line to `app/assets/javascripts/application.js` (or where you prefer) so the javascript dependency is added to the asset pipeline. Be sure to include this line after jQuery and jQuery UJS Adapter.
17
19
 
18
- //= require jquery.nested-fields
20
+ ```javascript
21
+ //= require jquery.nested-fields
22
+ ```
19
23
 
20
24
  3. Rock with your _awesome_ nested models.
21
25
 
@@ -24,15 +28,19 @@ Installation
24
28
 
25
29
  1. Add the gem to your Gemfile and run `bundle install` to make sure the gem gets installed. Be sure to include it after `jquery-rails` so the javascript files are added in the correct order at the templates.
26
30
 
27
- gem 'awesome_nested_fields'
31
+ ```ruby
32
+ gem 'awesome_nested_fields'
33
+ ```
28
34
 
29
35
  2. Copy the javascript dependency to `public/javascripts` by using the generator.
30
36
 
31
- rails generate awesome_nested_fields:install
37
+ rails generate awesome_nested_fields:install
32
38
 
33
39
  3. (Optional) The javascript dependency will be added automatically to the defaults javascript files. If you don't use `javascript_include_tag :defaults` in your templates for some reason, require the file manually.
34
40
 
35
- <script src="/javascripts/jquery.nested-fields.js" type="text/javascript"></script>
41
+ ```html
42
+ <script src="/javascripts/jquery.nested-fields.min.js" type="text/javascript"></script>
43
+ ```
36
44
 
37
45
  4. Now you're ready to rock with your _awesome_ nested models. It will be so fun as in Rails 3.1, I promise.
38
46
 
@@ -44,10 +52,12 @@ Basic Usage
44
52
 
45
53
  First, make sure the object that has the `has_many` or `has_and_belongs_to_many` relation accepts nested attributes for the collection you want. For example, if a person _has_many_ phones, we'll have a model like this:
46
54
 
47
- class Person < ActiveRecord::Base
48
- has_many :phones
49
- accepts_nested_attributes_for :phones, allow_destroy: true
50
- end
55
+ ```ruby
56
+ class Person < ActiveRecord::Base
57
+ has_many :phones
58
+ accepts_nested_attributes_for :phones, allow_destroy: true
59
+ end
60
+ ```
51
61
 
52
62
  The `accepts_nested_attributes_for` is a method from Active Record that allows you to pass attributes of nested models directly to its parent, instead of instantiate each child object separately. In this case, `Person` gains a method called `phones_attributes=`, that accepts data for new and existing phones of a given person. The `allow_destroy` option enables us to also delete child objects. To know more about nested attributes, check out the [ActiveRecord::NestedAttribute](https://github.com/rails/rails/blob/master/activerecord/lib/active_record/nested_attributes.rb#L1) class.
53
63
 
@@ -55,27 +65,29 @@ The `accepts_nested_attributes_for` is a method from Active Record that allows y
55
65
 
56
66
  The next step is set up the form view with the `nested_fields_for` method. It receives the association/collection name, an optional hash of options (humm, a pun) and a block with the nested fields. Proceeding with the person/phones example, we can have a form like this:
57
67
 
58
- <%= form_for(@person) do |f| %>
59
- <% # person fields... %>
60
-
61
- <h2>Phones</h2>
62
- <div class="items">
63
- <%= f.nested_fields_for :phones do |f| %>
64
- <fieldset class="item">
65
- <%= f.label :number %>
66
- <%= f.text_field :number %>
67
-
68
- <a href="#" class="remove">remove</a>
69
-
70
- <%= f.hidden_field :id %>
71
- <%= f.hidden_field :_destroy %>
72
- </fieldset>
73
- <% end %>
74
- </div>
75
- <a href="#" class="add">add phone</a>
76
-
77
- <% # more person fields... %>
68
+ ```erb
69
+ <%= form_for(@person) do |f| %>
70
+ <% # person fields... %>
71
+
72
+ <h2>Phones</h2>
73
+ <div class="items">
74
+ <%= f.nested_fields_for :phones do |f| %>
75
+ <fieldset class="item">
76
+ <%= f.label :number %>
77
+ <%= f.text_field :number %>
78
+
79
+ <a href="#" class="remove">remove</a>
80
+
81
+ <%= f.hidden_field :id %>
82
+ <%= f.hidden_field :_destroy %>
83
+ </fieldset>
78
84
  <% end %>
85
+ </div>
86
+ <a href="#" class="add">add phone</a>
87
+
88
+ <% # more person fields... %>
89
+ <% end %>
90
+ ```
79
91
 
80
92
  The `nested_fields_for` method lists the phones this person has and also adds an empty template to the page for creating new phones. (Actually, there is too much code inside the block. If you're not working with a simple example like this you better extract this code into a partial and call just `render :phones` inside the block. Good coding practices, you know.)
81
93
 
@@ -85,9 +97,11 @@ If you're paying attention, you noticed the key elements are marked with special
85
97
 
86
98
  This is the easiest part: just activate the nested fields actions when the page loads. We can put this in the `application.js` file (or in any other place that gets executed in the page):
87
99
 
88
- $(document).ready(function(e) {
89
- $('FORM').nestedFields();
90
- });
100
+ ```javascript
101
+ $(document).ready(function(e) {
102
+ $('FORM').nestedFields();
103
+ });
104
+ ```
91
105
 
92
106
  Now enjoy your new nested model form!
93
107
 
@@ -104,13 +118,15 @@ There are some view options, but most are internal. There is just one you really
104
118
  Sometimes you want to show something when the collection is empty. Just set `show_empty` to `true` and prepare the block to receive `nil` when the collection is empty. Awesome nested fields will take care to show the empty message when there are no elements and remove it when one is added.
105
119
  To implement this on the basic example, do something like:
106
120
 
107
- <%= f.nested_fields_for :phones, show_empty: true do |f| %>
108
- <% if f %>
109
- <% fields code... %>
110
- <% else %>
111
- <p class="empty">There are no phones.</p>
112
- <% end %>
113
- <% end %>
121
+ ```erb
122
+ <%= f.nested_fields_for :phones, show_empty: true do |f| %>
123
+ <% if f %>
124
+ <% fields code... %>
125
+ <% else %>
126
+ <p class="empty">There are no phones.</p>
127
+ <% end %>
128
+ <% end %>
129
+ ```
114
130
 
115
131
  And yeah, you need to mark it with the class `empty` or any other selector configured via javascript.
116
132
 
@@ -119,12 +135,14 @@ And yeah, you need to mark it with the class `empty` or any other selector confi
119
135
  When `nested_fields_for` is called, it also includes a `<script>` tag with the html template of a new item, so the javascript code knows what to insert. But sometimes it is not possible to put the template just after the items. For example, you can be inside a table (tables cannot have script elements inside it) or have multi-level nested items (the templates would be recursively repeated). In these cases you need to render the template manually.
120
136
 
121
137
  To do this, just set the `render_template` option to `false` and use the `nested_fields_template` helper to put the templates anywhere on the page.
122
-
123
- <%= f.nested_fields_for :phones, render_template: false do |f| %>
124
- <% nested field code %>
125
- <% end %>
126
- <!-- some lines after -->
127
- <%= nested_fields_templates %>
138
+
139
+ ```erb
140
+ <%= f.nested_fields_for :phones, render_template: false do |f| %>
141
+ <% nested field code %>
142
+ <% end %>
143
+ <!-- some lines after -->
144
+ <%= nested_fields_templates %>
145
+ ```
128
146
 
129
147
  Keep in mind that you can call the templates only after `nested_fields_for` and inside the DOM element you apply the `nestedFields()` javascript, so it still can find the templates.
130
148
 
@@ -142,45 +160,52 @@ To make nested fields work dynamically, the JS code needs to know what elements
142
160
 
143
161
  For example, if you are using nested fields inside a table, you can do:
144
162
 
145
- element.nestedFields({
146
- containerSelector: 'tbody',
147
- itemSelector: 'tr'
148
- });
149
-
163
+ ```javascript
164
+ element.nestedFields({
165
+ containerSelector: 'tbody',
166
+ itemSelector: 'tr'
167
+ });
168
+ ```
150
169
 
151
170
  #### Callbacks
152
171
 
153
172
  Actions can be executed before or after items get inserted or removed. There are four callbacks available: `beforeInsert`, `afterInsert`, `beforeRemove` and `afterRemove`. All of them receive the item as the first parameter, so you can query or modify it before the operation.
154
173
 
155
- element.nestedFields({
156
- beforeInsert: function(item) {
157
- item.css('color', 'red'); // Make some operation
158
- console.log(item + ' will be inserted.')
159
- },
160
- afterRemove: function(item) {
161
- console.log(item + ' was removed.');
162
- }
163
- });
164
-
174
+ ```javascript
175
+ element.nestedFields({
176
+ beforeInsert: function(item) {
177
+ item.css('color', 'red'); // Make some operation
178
+ console.log(item + ' will be inserted.')
179
+ },
180
+ afterRemove: function(item) {
181
+ console.log(item + ' was removed.');
182
+ }
183
+ });
184
+ ```
185
+
165
186
  The before callbacks also allow you to control when the element will be inserted or removed, so you can perform async operations (ajax, of course!) or choose to not insert or remove the element at all if some condition is not met. Just receive a second parameter as the handler function.
166
-
167
- element.nestedFields({
168
- beforeInsert: function(item, insert) {
169
- $.get('/ajax_function', function() {
170
- insert();
171
- });
172
- }
187
+
188
+ ```javascript
189
+ element.nestedFields({
190
+ beforeInsert: function(item, insert) {
191
+ $.get('/ajax_function', function() {
192
+ insert();
173
193
  });
194
+ }
195
+ });
196
+ ```
174
197
 
175
198
 
176
199
  ### Javascript API
177
200
 
178
201
  It is possible to control nested fields programmatically using a jQuery-style API.
179
202
 
180
- element.nestedFields('insert', function(item) {
181
- // Make some operation with item
182
- }, {skipBefore: true});
183
-
203
+ ```javascript
204
+ element.nestedFields('insert', function(item) {
205
+ // Make some operation with item
206
+ }, {skipBefore: true});
207
+ ```
208
+
184
209
  The code above inserts a new item and does not execute the `beforeInsert` callback function. The complete list of available methods is shown below.
185
210
 
186
211
  * `insert(callback, options)` inserts a new item in the container. The `callback` function is executed just before the item is inserted. There are two available options: `skipBefore` and `skipAfter`. Both arguments are optional.
@@ -192,59 +217,46 @@ The code above inserts a new item and does not execute the `beforeInsert` callba
192
217
  These methods can be called from the element where nested fields are applied (e.g. a form) or from any element inside it (e.g. an input or the container itself).
193
218
 
194
219
 
195
- Multiple Nested Fields
196
- -----------------------
197
-
198
- It is easy to have multiple nested fields on the same page. Instead of applying `nestedFields()` to the form, put the elements (items, container, add, remove) inside a wrapper and apply nested fields to it.
199
-
200
- <!-- ERB Code -->
201
- <h2>Phones</h2>
202
- <div id="phones">
203
- <div class="items">
204
- <%= f.nested_fields_for :phones do |f| %>
205
- <% ... %>
206
- <% end %>
207
- </div>
208
- <a href="#" class="add">add phone</a>
209
- </div>
210
-
211
- <h2>Addresses</h2>
212
- <div id="addresses">
213
- <div class="items">
214
- <%= f.nested_fields_for :addresses do |f| %>
215
- <% ... %>
216
- <% end %>
217
- </div>
218
- <a href="#" class="add">add address</a>
219
- </div>
220
-
221
- // JS Code
222
- $('#phones, #addresses').nestedFields();
220
+ More on the Wiki
221
+ ----------------
222
+
223
+ Check out the wiki to know how to put Multiple Nested Fields on the same page or how to create Multi-level Nested Fields.
223
224
 
224
225
 
225
226
  Demo
226
227
  ----
227
228
 
228
- There is a live demo at http://phonebook.guava.com.br/.
229
+ There is a live demo at http://phonebook.guava.com.br/.
230
+
229
231
  You can find the demo code at https://github.com/lailsonbm/awesome_nested_fields_demo.
230
232
 
231
233
 
232
234
  Compatibility
233
235
  -------------
234
236
 
235
- awesome_nested_fields works only with jQuery and Rails 3.x. Sorry, Rails 2.x users.
237
+ awesome_nested_fields works only with jQuery and Rails 3.x. Sorry, Rails 2.x users. Tested with ActiveRecord and Mongoid (but should work wherever `accepts_nested_fields` method is available).
236
238
 
237
239
 
240
+ Contributors
241
+ ------------
242
+
243
+ * Chris Parker ([mrcsparker](https://github.com/mrcsparker))
244
+ * Juliana Lucena ([julianalucena](https://github.com/julianalucena))
245
+ * Rodrigo Vieira ([rodrigoalvesvieira](https://github.com/rodrigoalvesvieira))
246
+
238
247
  TODO
239
248
  ----
240
249
 
241
- * Write tests
250
+ * Write more tests
242
251
  * Make sure it can degrade gracefully
243
252
  * Implement jQuery autoload
244
253
  * Make `nested_fields_for` works without a block (looking for partials)
245
- * Document how to nest nested fields (yeah, you can do that) ;-)
246
254
 
255
+ Donation
256
+ --------
257
+ [![Pledgie](https://www.pledgie.com/campaigns/18414.png)][pledgie]
258
+ [pledgie]: http://www.pledgie.com/campaigns/18414
247
259
 
248
260
  Copyleft
249
261
  --------
250
- Copyleft (c) 2011 Lailson Bandeira (http://lailsonbandeira.com/). See LICENSE for details.
262
+ Copyleft (c) 2011-2013 Lailson Bandeira (http://lailsonbandeira.com/). See LICENSE for details.
data/Rakefile CHANGED
@@ -1,2 +1,22 @@
1
1
  require 'bundler'
2
2
  Bundler::GemHelper.install_tasks
3
+
4
+ # encoding: UTF-8
5
+
6
+ require 'rake/testtask'
7
+ require 'rdoc/task'
8
+
9
+ task :default => :test
10
+
11
+ desc 'Run AwesomeNestedFields unit tests.'
12
+ Rake::TestTask.new(:test) do |t|
13
+ t.libs << 'lib'
14
+ t.libs << 'test'
15
+ t.pattern = 'test/*_test.rb'
16
+ t.verbose = true
17
+ end
18
+
19
+ require "rspec/core/rake_task"
20
+ RSpec::Core::RakeTask.new(:spec) do |t|
21
+ t.rspec_opts = '--backtrace --color'
22
+ end
@@ -1,4 +1,4 @@
1
- # -*- encoding: utf-8 -*-
1
+ # encoding: utf-8
2
2
  require File.expand_path('../lib/awesome_nested_fields/version', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
@@ -15,6 +15,8 @@ Gem::Specification.new do |s|
15
15
  s.rubyforge_project = "awesome_nested_fields"
16
16
 
17
17
  s.add_development_dependency 'bundler', '>= 1.0.0'
18
+ s.add_development_dependency 'rspec', '>=2'
19
+ s.add_development_dependency 'turn', '~> 0.8.3'
18
20
  s.add_runtime_dependency 'rails', '>= 3.0.0'
19
21
 
20
22
  s.files = `git ls-files`.split("\n")
@@ -1,3 +1,6 @@
1
+ require "rails" unless defined?(Rails)
2
+ require "action_view" unless defined?(ActionView)
3
+
1
4
  module AwesomeNestedFields
2
5
  if ::Rails.version < '3.1'
3
6
  require 'awesome_nested_fields/railtie'
@@ -1,3 +1,3 @@
1
1
  module AwesomeNestedFields
2
- VERSION = "0.6.0"
2
+ VERSION = "0.6.1"
3
3
  end
@@ -0,0 +1,14 @@
1
+ require 'test_helper'
2
+
3
+ class AwesomeNestedFieldsTest < ActiveSupport::TestCase
4
+ test "it has a version" do
5
+ version = AwesomeNestedFields::VERSION
6
+ assert_match version, /^\d+\.\d+\.\d+$/
7
+ assert_not_nil version
8
+ end
9
+
10
+ test "it can escape HTML content" do
11
+ escaped_content = AwesomeNestedFields.escape_html_tags("Home > News & Updates")
12
+ assert_equal escaped_content, "Home &gt; News &amp; Updates"
13
+ end
14
+ end
@@ -0,0 +1,13 @@
1
+ require "test_helper"
2
+
3
+ class InstallGeneratorTest < Rails::Generators::TestCase
4
+ tests InstallGenerator
5
+ destination File.expand_path("../../tmp", __FILE__)
6
+ setup :prepare_destination
7
+
8
+ test "it creates all files properly" do
9
+ run_generator
10
+ assert_file "public/javascripts/jquery.nested-fields.js" if Rails.version < "3.1"
11
+ end
12
+
13
+ end
@@ -0,0 +1,9 @@
1
+ $:.unshift 'lib'
2
+
3
+ require "rubygems" unless defined?(Gem)
4
+ require "rails"
5
+ require "awesome_nested_fields"
6
+ require "turn"
7
+
8
+ require "rails/generators/test_case"
9
+
@@ -211,6 +211,7 @@
211
211
  if(confirmed === undefined || confirmed === true) {
212
212
  removeItemWithCallbacks(item, options);
213
213
  }
214
+ return false;
214
215
  });
215
216
  }
216
217
 
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Awesome Nested Fields
3
+ *
4
+ * Requires jquery-ujs adapter.
5
+ * https://github.com/lailsonbm/awesome_nested_fields
6
+ */
7
+ (function(h){var i={beforeInsert:function(q,r){r()},afterInsert:function(q){},beforeRemove:function(q,r){r()},afterRemove:function(q){},itemTemplateSelector:".item.template",emptyTemplateSelector:".empty.template",containerSelector:".items, .container",itemSelector:".item",emptySelector:".empty",addSelector:".add",removeSelector:".remove",newItemIndex:"new_nested_item",unescapeTemplate:true};var d={init:function(q){return this.each(function(){var r=h(this);if(r.data("nested-fields.options")){g("Nested fields already defined for this element. If you want to redefine options, destroy it and init again.");return r}q=h.extend({},i,q);q.itemTemplate=h(q.itemTemplateSelector,r);q.emptyTemplate=h(q.emptyTemplateSelector,r);q.container=h(q.containerSelector,r);q.add=h(q.addSelector,r);r.data("nested-fields.options",q);l(q);b(q,r)})},insert:function(r,q){q=h.extend({},j(this),q);return f(r,q)},remove:function(r,q){q=h.extend({},j(this),q);return e(r,q)},removeAll:function(q){q=h.extend({},j(this),q);h(d.items.apply(this)).each(function(r,s){d.remove(s,q)})},items:function(){return c(j(this))},destroy:function(){h(this).removeData("nested-fields.options");h("*",this).unbind(".nested-fields")}};h.fn.nestedFields=function(q){if(d[q]){return d[q].apply(this,Array.prototype.slice.call(arguments,1))}else{if(typeof q==="object"||!q){return d.init.apply(this,arguments)}else{h.error("Method "+q+" does not exist on jQuery.nestedFields")}}};function j(r){var q=h(r);while(q.length>0){var s=q.data("nested-fields.options");if(s){return s}else{q=q.parent()}}return null}function l(q){q.add.bind("click.nested-fields",function(r){r.preventDefault();f(null,q)})}function b(q,r){h(q.itemSelector,r).each(function(s,t){k(t,q)})}function m(r){var u=new RegExp(r.newItemIndex,"g");var q=new Date().getTime();var t=r.itemTemplate.html();if(r.unescapeTemplate){t=o(t)}var s=h(t.replace(u,q));s.attr("data-new-record",true);s.attr("data-record-id",q);k(s,r);return s}function f(q,r){var s=m(r);function t(){if(q){q(s)}a(r);r.container.append(s)}if(!r.skipBefore){r.beforeInsert(s,t);if(r.beforeInsert.length<=1){t()}}else{t()}if(!r.skipAfter){r.afterInsert(s)}return s}function a(q){p(q).remove()}function e(t,s){function q(){if(r.attr("data-new-record")){r.remove()}else{r.find("INPUT[name$='[_destroy]']").val("true");r.hide()}n(s)}var r=h(t);if(!s.skipBefore){s.beforeRemove(r,q);if(s.beforeRemove.length<=1){q()}}else{q()}if(!s.skipAfter){s.afterRemove(r)}return r}function n(q){if(c(q).length===0){var r=q.emptyTemplate.html();if(q.unescapeTemplate){r=o(r)}q.container.append(r)}}function k(t,r){var q=h(t).find(r.removeSelector);var u=q.attr("data-confirm");var s=u?"confirm:complete":"click";q.bind(s+".nested-fields",function(v,w){v.preventDefault();if(w===undefined||w===true){e(t,r)}})}function c(q){return q.container.find(q.itemSelector+":visible")}function p(q){return q.container.find(q.emptySelector)}function o(q){var r=document.createElement("div");r.innerHTML=q;return r.childNodes.length===0?"":r.childNodes[0].nodeValue}function g(q){if(console&&console.log){console.log(q)}}})(jQuery);
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awesome_nested_fields
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-25 00:00:00.000000000 Z
12
+ date: 2013-01-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
16
- requirement: &70151785785320 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,47 @@ dependencies:
21
21
  version: 1.0.0
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70151785785320
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.0.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '2'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '2'
46
+ - !ruby/object:Gem::Dependency
47
+ name: turn
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 0.8.3
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.8.3
25
62
  - !ruby/object:Gem::Dependency
26
63
  name: rails
27
- requirement: &70151785784480 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
28
65
  none: false
29
66
  requirements:
30
67
  - - ! '>='
@@ -32,7 +69,12 @@ dependencies:
32
69
  version: 3.0.0
33
70
  type: :runtime
34
71
  prerelease: false
35
- version_requirements: *70151785784480
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: 3.0.0
36
78
  description: Awesome dynamic nested fields for Rails and jQuery
37
79
  email: lailson@guava.com.br
38
80
  executables: []
@@ -52,7 +94,11 @@ files:
52
94
  - lib/awesome_nested_fields/version.rb
53
95
  - lib/generators/awesome_nested_fields/install/install_generator.rb
54
96
  - lib/rails/form_helper.rb
97
+ - test/awesome_nested_fields_test.rb
98
+ - test/generators/install_generator_test.rb
99
+ - test/test_helper.rb
55
100
  - vendor/assets/javascripts/jquery.nested-fields.js
101
+ - vendor/assets/javascripts/jquery.nested-fields.min.js
56
102
  homepage: http://rubygems.org/gems/awesome_nested_fields
57
103
  licenses: []
58
104
  post_install_message:
@@ -65,6 +111,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
65
111
  - - ! '>='
66
112
  - !ruby/object:Gem::Version
67
113
  version: '0'
114
+ segments:
115
+ - 0
116
+ hash: -40724994690773291
68
117
  required_rubygems_version: !ruby/object:Gem::Requirement
69
118
  none: false
70
119
  requirements:
@@ -73,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
122
  version: 1.3.6
74
123
  requirements: []
75
124
  rubyforge_project: awesome_nested_fields
76
- rubygems_version: 1.8.10
125
+ rubygems_version: 1.8.23
77
126
  signing_key:
78
127
  specification_version: 3
79
128
  summary: Awesome nested fields for Rails