cool_nested_forms 0.1.2 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d2f7ad90816a28b45857f43b357d89e45fb89e83
4
- data.tar.gz: 62245f5482d798bafb522b8f366085a598b6839e
3
+ metadata.gz: b48184d7b170609c8a71ea4eb082cfb6edfd795f
4
+ data.tar.gz: 52b40bc7014dfec757f6f34753e5b4afbdfd77e7
5
5
  SHA512:
6
- metadata.gz: 50eccdcb03196c2594f2a24c1d753779eb6133ef55b4531479b8f8ff37171a537b4d8f49cd9104ad60e8163d4d425dd7f38a0af18f90ff2cd2e1d8173332be54
7
- data.tar.gz: f702ec2ed7182732a972d9722ad19e4b293294fd805ae6ad654f414a9aea7e0304bb1bb9f5d00d9f2f8646fb7d902b5bc3da19cdae0e94ebf74ab57578f1b6f0
6
+ metadata.gz: e0527b621ff6b2ca7dc633c996ed48fbf22de4d2afe22e5d12348af1e43f32f82d2e95f69b7533e81455ee39361d1dab1df5d7d8f7bae96a68cd9892d3ad4bd7
7
+ data.tar.gz: 85ff8543fd00f3ac6463c5e2e3899d4570ac0152d619a519cc8c67a7eca0d87aad0872c7a22315aeae51d8b5a6f1e4ec1525ffeb3dace99759b20586dbcd3016
data/README.md CHANGED
@@ -1,8 +1,12 @@
1
1
  # CoolNestedForms
2
+ [![Gem Version](https://badge.fury.io/rb/cool_nested_forms.svg)](https://badge.fury.io/rb/cool_nested_forms)
3
+
2
4
  Add Nested Forms to your Forms. Currently tested with a depth of 2.
3
5
  For example a Form can add an Item and this Item can add a sub Item.
4
6
  It can probably support longer nests but I haven't tested it yet.
5
7
 
8
+ By the way, this is intended to simplify adding the javascript required to add form_field dynamically while following form builder conventions. What that means is that there is some work to be done in the form of configuring models and controllers and adding a couple of views.
9
+
6
10
  ## Installation
7
11
 
8
12
  Add this line to your application's Gemfile:
@@ -13,21 +17,97 @@ gem 'cool_nested_forms'
13
17
 
14
18
  And then execute:
15
19
 
16
- $ bundle
20
+ $ bundle install
17
21
 
18
22
  Or install it yourself as:
19
23
 
20
24
  $ gem install cool_nested_forms
21
25
 
22
- ## Usage
26
+ Then require the javascript in your app/assets/javascripts/application.js
27
+ ```javascript
28
+ //= require cool_nested_forms
29
+ ```
30
+
31
+ ## Usage Example
32
+ For this example I will use Job and Task models
33
+
34
+ ### Preparing your models
35
+
36
+ #### Job Model
37
+ ```ruby
38
+ class Job < ActiveRecord::Base
39
+ has_many :tasks, :dependent => :destroy
40
+ # :name is required - User your own required field here
41
+ accepts_nested_attributes_for :tasks, :reject_if => lambda { |a| a[:name].blank? }, :allow_destroy => true
42
+ end
43
+ ```
44
+ #### Task Model
45
+ ```ruby
46
+ class Task < ActiveRecord::Base
47
+ belongs_to :job
48
+ end
49
+ ```
50
+ ### Preparing the Job Controller
51
+ ```ruby
52
+ class JobsController < ApplicationController
53
+
54
+ # other code #
55
+
56
+ def job_params
57
+ # :id and :_destroy are required. Substitute name with your own fields
58
+ params.require(:job).permit(:name,
59
+ :tasks_attributes => [:id, :name, :_destroy])
60
+ end
61
+ end
62
+ ```
63
+ ### The view used to generate tasks
64
+ Due to laziness remove_child_button needs to be nested right under the containing div. this will be fixed in the next version.
65
+ app/views/jobs/_task.html.rb
66
+ ```html
67
+ <div>
68
+ <%= remove_child_button "Remove" %>
69
+ <%= f.hidden_field :_destroy, :class => 'removable' %>
70
+
71
+ <%= f.label :name %>
72
+ <%= f.text_field :name %>
73
+ </div>
74
+ ```
75
+
76
+ ## Adding functionality to the Job form
77
+ app/views/jobs/_form.html.erb
78
+ ```html
79
+ <%= form_for(@job) do |f| %>
80
+
23
81
 
24
- Will update with usage later
82
+ <!-- your other job fields go here -->
25
83
 
26
- ## Development
27
84
 
28
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
85
+ <!-- this generates a template for javascript -->
86
+ <%= new_fields_template f, :tasks, {object: Tasks.new, :template => "tasks_#{f.object.id}_fields"} %>
87
+ <!-- this generates a button that adds a task into <div id="tasks_<%=f.object.id%>"> -->
88
+ <%= add_child_button "Add Task", :tasks, "tasks_#{f.object.id}", "tasks_#{f.object.id}", "<your-css-classes>" %>
29
89
 
30
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
90
+ <div id="tasks_<%=f.object.id%>">
91
+ <%= f.fields_for :tasks, @job.tasks do |builder| %>
92
+ <%= render "task", :f => builder %>
93
+ <% end %>
94
+ </div>
95
+
96
+ <%end%>
97
+ ```
98
+
99
+ ### After add/remove events
100
+ If you need to perform any other javascript actions after a child is added or removed, you can add a listener to these events
101
+ ```javascript
102
+ coolNestedForms.childAdded
103
+ coolNestedForms.childRemoved
104
+ ```
105
+ Something like this
106
+ ```javascript
107
+ $(document).bind('coolNestedForms.childAdded', function(){
108
+ // do something
109
+ });
110
+ ```
31
111
 
32
112
  ## Contributing
33
113
 
@@ -23,16 +23,16 @@ Gem::Specification.new do |spec|
23
23
  "public gem pushes."
24
24
  end
25
25
 
26
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
27
  f.match(%r{^(test|spec|features)/})
28
28
  end
29
29
  spec.bindir = "exe"
30
30
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
31
  spec.require_paths = ["lib", "app"]
32
32
 
33
- spec.add_runtime_dependency 'rails', '~> 4.1'
33
+ spec.add_runtime_dependency 'rails', '~> 5.1'
34
34
 
35
- spec.add_development_dependency "bundler", "~> 1.13"
36
- spec.add_development_dependency "rake", "~> 10.0"
37
- spec.add_development_dependency "rspec", "~> 3.0"
35
+ spec.add_development_dependency "bundler"
36
+ spec.add_development_dependency "rake"
37
+ spec.add_development_dependency "rspec"
38
38
  end
@@ -1,3 +1,3 @@
1
1
  module CoolNestedForms
2
- VERSION = "0.1.2"
2
+ VERSION = "1.0.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cool_nested_forms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carlos Roque
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-15 00:00:00.000000000 Z
11
+ date: 2017-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -16,56 +16,56 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '4.1'
19
+ version: '5.1'
20
20
  type: :runtime
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.1'
26
+ version: '5.1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '1.13'
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '1.13'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '10.0'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '3.0'
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: '3.0'
68
+ version: '0'
69
69
  description: Easily add nested forms to your forms
70
70
  email:
71
71
  - carlos_roque@hotmail.com
@@ -78,7 +78,6 @@ files:
78
78
  - ".travis.yml"
79
79
  - CODE_OF_CONDUCT.md
80
80
  - Gemfile
81
- - Gemfile.lock
82
81
  - LICENSE
83
82
  - LICENSE.txt
84
83
  - README.md
@@ -87,7 +86,6 @@ files:
87
86
  - app/helpers/cool_nested_forms_helper.rb
88
87
  - bin/console
89
88
  - bin/setup
90
- - cool_nested_forms-0.1.1.gem
91
89
  - cool_nested_forms.gemspec
92
90
  - lib/cool_nested_forms.rb
93
91
  - lib/cool_nested_forms/engine.rb
@@ -113,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
111
  version: '0'
114
112
  requirements: []
115
113
  rubyforge_project:
116
- rubygems_version: 2.2.3
114
+ rubygems_version: 2.5.2
117
115
  signing_key:
118
116
  specification_version: 4
119
117
  summary: Cool Nested Forms
data/Gemfile.lock DELETED
@@ -1,130 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- cool_nested_forms (0.1.0)
5
- rails (~> 4.2.6)
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- actionmailer (4.2.7.1)
11
- actionpack (= 4.2.7.1)
12
- actionview (= 4.2.7.1)
13
- activejob (= 4.2.7.1)
14
- mail (~> 2.5, >= 2.5.4)
15
- rails-dom-testing (~> 1.0, >= 1.0.5)
16
- actionpack (4.2.7.1)
17
- actionview (= 4.2.7.1)
18
- activesupport (= 4.2.7.1)
19
- rack (~> 1.6)
20
- rack-test (~> 0.6.2)
21
- rails-dom-testing (~> 1.0, >= 1.0.5)
22
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
23
- actionview (4.2.7.1)
24
- activesupport (= 4.2.7.1)
25
- builder (~> 3.1)
26
- erubis (~> 2.7.0)
27
- rails-dom-testing (~> 1.0, >= 1.0.5)
28
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
29
- activejob (4.2.7.1)
30
- activesupport (= 4.2.7.1)
31
- globalid (>= 0.3.0)
32
- activemodel (4.2.7.1)
33
- activesupport (= 4.2.7.1)
34
- builder (~> 3.1)
35
- activerecord (4.2.7.1)
36
- activemodel (= 4.2.7.1)
37
- activesupport (= 4.2.7.1)
38
- arel (~> 6.0)
39
- activesupport (4.2.7.1)
40
- i18n (~> 0.7)
41
- json (~> 1.7, >= 1.7.7)
42
- minitest (~> 5.1)
43
- thread_safe (~> 0.3, >= 0.3.4)
44
- tzinfo (~> 1.1)
45
- arel (6.0.3)
46
- builder (3.2.2)
47
- concurrent-ruby (1.0.2)
48
- diff-lcs (1.2.5)
49
- erubis (2.7.0)
50
- globalid (0.3.7)
51
- activesupport (>= 4.1.0)
52
- i18n (0.7.0)
53
- json (1.8.3)
54
- loofah (2.0.3)
55
- nokogiri (>= 1.5.9)
56
- mail (2.6.4)
57
- mime-types (>= 1.16, < 4)
58
- mime-types (3.1)
59
- mime-types-data (~> 3.2015)
60
- mime-types-data (3.2016.0521)
61
- mini_portile2 (2.1.0)
62
- minitest (5.9.0)
63
- nokogiri (1.6.8)
64
- mini_portile2 (~> 2.1.0)
65
- pkg-config (~> 1.1.7)
66
- pkg-config (1.1.7)
67
- rack (1.6.4)
68
- rack-test (0.6.3)
69
- rack (>= 1.0)
70
- rails (4.2.7.1)
71
- actionmailer (= 4.2.7.1)
72
- actionpack (= 4.2.7.1)
73
- actionview (= 4.2.7.1)
74
- activejob (= 4.2.7.1)
75
- activemodel (= 4.2.7.1)
76
- activerecord (= 4.2.7.1)
77
- activesupport (= 4.2.7.1)
78
- bundler (>= 1.3.0, < 2.0)
79
- railties (= 4.2.7.1)
80
- sprockets-rails
81
- rails-deprecated_sanitizer (1.0.3)
82
- activesupport (>= 4.2.0.alpha)
83
- rails-dom-testing (1.0.7)
84
- activesupport (>= 4.2.0.beta, < 5.0)
85
- nokogiri (~> 1.6.0)
86
- rails-deprecated_sanitizer (>= 1.0.1)
87
- rails-html-sanitizer (1.0.3)
88
- loofah (~> 2.0)
89
- railties (4.2.7.1)
90
- actionpack (= 4.2.7.1)
91
- activesupport (= 4.2.7.1)
92
- rake (>= 0.8.7)
93
- thor (>= 0.18.1, < 2.0)
94
- rake (10.5.0)
95
- rspec (3.5.0)
96
- rspec-core (~> 3.5.0)
97
- rspec-expectations (~> 3.5.0)
98
- rspec-mocks (~> 3.5.0)
99
- rspec-core (3.5.2)
100
- rspec-support (~> 3.5.0)
101
- rspec-expectations (3.5.0)
102
- diff-lcs (>= 1.2.0, < 2.0)
103
- rspec-support (~> 3.5.0)
104
- rspec-mocks (3.5.0)
105
- diff-lcs (>= 1.2.0, < 2.0)
106
- rspec-support (~> 3.5.0)
107
- rspec-support (3.5.0)
108
- sprockets (3.7.0)
109
- concurrent-ruby (~> 1.0)
110
- rack (> 1, < 3)
111
- sprockets-rails (3.1.1)
112
- actionpack (>= 4.0)
113
- activesupport (>= 4.0)
114
- sprockets (>= 3.0.0)
115
- thor (0.19.1)
116
- thread_safe (0.3.5)
117
- tzinfo (1.2.2)
118
- thread_safe (~> 0.1)
119
-
120
- PLATFORMS
121
- ruby
122
-
123
- DEPENDENCIES
124
- bundler (~> 1.13.a)
125
- cool_nested_forms!
126
- rake (~> 10.0)
127
- rspec (~> 3.0)
128
-
129
- BUNDLED WITH
130
- 1.13.0.rc.1
Binary file