rondo_form 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6ee9d8f4d7737a47f8e756a02d3dab153a2f8e162b8b5141755976c381470114
4
- data.tar.gz: 2d1b339d1a473c7336ecf5fe3182b23591ab409f5cffe580fabd62b1f0c3ed1b
3
+ metadata.gz: c3d9a9ef19130de5f6aa92adf1139711bd5faaae4ef20155579e6865f291b7d9
4
+ data.tar.gz: 791d1fff3244853568a449b8b3c7a151dec19b45d2c3e2e79dd77cdec47ad891
5
5
  SHA512:
6
- metadata.gz: 10b686a87cb7e4de4cd13616d9b85d875d36db630209989c5bb40ae19d23fa66ee0b6153b4220a42c6e4479289b0515f427917d0385ccea5a7f5c44741504d71
7
- data.tar.gz: 76fcdce9be21925c0f1aba373fd19f996e7c9fbac7d4e3e952df969ebf4b3a6ed3eb232d47a8326161ad0f627f61267afbcc146c465f1e1dbbc2df6906e72e96
6
+ metadata.gz: e511697842f4cebf817bf61108e0556281e0702b7acd9cb6b75c0ba62d18ae7ef33b3e2665ec240a595955d0d80c77d6297bd882a7de5148552997b1020e77d5
7
+ data.tar.gz: b9d9ef124e278eef3de87275295783874535207bd4785cac54a84059f28cd350e96f6b301399a1080e3ac63ab855370983c8b3793a86daf7fdd75a1c083929c2
data/README.md CHANGED
@@ -8,24 +8,62 @@ Install the gem and add to the application's Gemfile by executing:
8
8
 
9
9
  $ bundle add rondo_form
10
10
 
11
- If bundler is not being used to manage dependencies, install the gem by executing:
11
+ Or inside the Gemfile add the following
12
12
 
13
- $ gem install rondo_form
13
+ $ gem 'rondo_form', '~> 0.2.0'
14
14
 
15
15
  Run the installation task:
16
16
 
17
- $ rails g rondo_form:install
17
+ $ rails g rondo_form:install
18
18
 
19
19
  ## Usage
20
20
 
21
+ For example, we have `Project` model, which has `has_many` relationship with `Task` model:
22
+ ```
23
+ rails g scaffold Project name:string description:string
24
+ rails g model Task description:string done:boolean project:belongs_to
25
+ ```
26
+
27
+ ### Sample with SimpleForm
28
+ In your `projects/_form` partial:
29
+ ``` erb
30
+ <%= simple_form_for(@project) do |f| %>
31
+
32
+ <div class="form-inputs">
33
+ <%= f.input :name %>
34
+ <%= f.input :description %>
35
+ </div>
36
+
37
+ <h3 class="text-xl mt-4">Tasks</h3>
38
+ <div class="my-2" data-controller="cocoon">
39
+ <%= f.simple_fields_for :tasks do |task| %>
40
+ <%= render "task_fields", f: task %>
41
+ <% end %>
42
+ <div class="links">
43
+ <%= link_to_add_association "Add Task", f, :tasks %>
44
+ </div>
45
+ </div>
46
+
47
+ <div class="form-actions mt-4">
48
+ <%= f.button :submit %>
49
+ </div>
50
+ <% end %>
51
+
52
+ ```
53
+
54
+ In your `_task_fields` partial:
55
+ ``` erb
56
+ <div class="nested-fields">
57
+ <%= f.input :description %>
58
+ <%= f.input :done, as: :boolean %>
59
+ <%= link_to_remove_association "Remove Task", f %>
60
+ </div>
61
+
62
+ ```
63
+
64
+ _Note_: You must add `data-controller="cocoon"` to an element, that wraps `fields_for` and `link_to_add_association` helper.
21
65
 
22
66
 
23
- ## Development
24
-
25
- 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.
26
-
27
- 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
-
29
67
  ## Contributing
30
68
 
31
69
  Bug reports and pull requests are welcome on GitHub at https://github.com/hungle00/rondo_form.
@@ -5,10 +5,10 @@ module RondoForm
5
5
  desc "This generator installs the javascript needed for rondo_form"
6
6
 
7
7
  def copy_the_javascript
8
- copy_file "cocoon_controller.js", "app/javascript/controllers/cocoon_controller.js", force: true
8
+ copy_file "nested_rondo_controller.js", "app/javascript/controllers/nested_rondo_controller.js", force: true
9
9
  if (Rails.root.join("app/javascript/controllers/index.js")).exist?
10
10
  append_to_file "app/javascript/controllers/index.js",
11
- %(import CocoonController from "./cocoon_controller"\napplication.register("cocoon", CocoonController)\n)
11
+ %(import NestedRondoController from "./nested_rondo_controller"\napplication.register("nested-rondo", NestedRondoController)\n)
12
12
  else
13
13
  say %(Couldn't find "app/javascript/controllers/index.js".), :red
14
14
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RondoForm
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.1"
5
5
  end
@@ -24,7 +24,7 @@ module RondoForm
24
24
 
25
25
  is_dynamic = f.object.new_record?
26
26
  html_options[:class] = [html_options[:class], "remove_fields #{is_dynamic ? 'dynamic' : 'existing'}"].compact.join(' ')
27
- html_options[:'data-action'] = "click->cocoon#removeField"
27
+ html_options[:'data-action'] = "click->nested-rondo#removeField"
28
28
  f.hidden_field(:_destroy) + link_to(name, '', html_options)
29
29
  end
30
30
  end
@@ -48,11 +48,11 @@ module RondoForm
48
48
 
49
49
  html_options[:class] = [html_options[:class], "add_fields"].compact.join(' ')
50
50
  html_options[:'data-association'] = association.to_s.singularize
51
- html_options[:'data-action'] = "click->cocoon#addField"
51
+ html_options[:'data-action'] = "click->nested-rondo#addField"
52
52
 
53
53
  new_object = f.object.class.reflect_on_association(association).klass.new
54
54
  model_name = new_object.class.name.underscore
55
- hidden_div = content_tag("template", id: "#{model_name}_fields_template", data: {cocoon_target: 'template'}) do
55
+ hidden_div = content_tag("template", id: "#{model_name}_fields_template", data: {'nested-rondo_target': 'template'}) do
56
56
  render_association(association, f, new_object)
57
57
  end
58
58
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rondo_form
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - hungle00
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-06-14 00:00:00.000000000 Z
11
+ date: 2023-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -78,7 +78,7 @@ files:
78
78
  - README.md
79
79
  - Rakefile
80
80
  - lib/generators/rondo_form/install_generator.rb
81
- - lib/generators/rondo_form/templates/cocoon_controller.js
81
+ - lib/generators/rondo_form/templates/nested_rondo_controller.js
82
82
  - lib/rondo_form.rb
83
83
  - lib/rondo_form/version.rb
84
84
  - lib/rondo_form/view_helpers.rb