abyme 0.4.0 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.DS_Store +0 -0
- data/.babelrc +6 -0
- data/CHANGELOG.md +22 -1
- data/Gemfile.lock +106 -81
- data/README.md +123 -173
- data/abyme.gemspec +7 -1
- data/dist/abyme.js +2 -0
- data/dist/abyme.js.map +1 -0
- data/dist/abyme.modern.js +2 -0
- data/dist/abyme.modern.js.map +1 -0
- data/dist/abyme.module.js +2 -0
- data/dist/abyme.module.js.map +1 -0
- data/dist/abyme.umd.js +2 -0
- data/dist/abyme.umd.js.map +1 -0
- data/jest/jest-setup.js +2 -0
- data/lib/abyme.rb +1 -0
- data/lib/abyme/abyme_builder.rb +11 -18
- data/lib/abyme/action_view_extensions/builder.rb +2 -0
- data/lib/abyme/controller.rb +15 -0
- data/lib/abyme/engine.rb +3 -0
- data/lib/abyme/model.rb +82 -6
- data/lib/abyme/version.rb +2 -2
- data/lib/abyme/view_helpers.rb +69 -51
- data/lib/generators/abyme/controller/USAGE +16 -0
- data/lib/generators/abyme/controller/controller_generator.rb +25 -0
- data/lib/generators/abyme/model/USAGE +21 -0
- data/lib/generators/abyme/model/model_generator.rb +70 -0
- data/lib/generators/abyme/resource/USAGE +10 -0
- data/lib/generators/abyme/resource/resource_generator.rb +18 -0
- data/lib/generators/abyme/stimulus/USAGE +5 -0
- data/lib/generators/abyme/stimulus/stimulus_generator.rb +21 -0
- data/lib/generators/abyme/view/USAGE +11 -0
- data/lib/generators/abyme/view/view_generator.rb +65 -0
- data/package-lock.json +31992 -0
- data/package.json +35 -5
- data/specs/index.test.js +26 -0
- data/{javascript → src}/abyme_controller.js +1 -3
- data/{javascript → src}/index.js +0 -0
- data/yarn.lock +7678 -22
- metadata +97 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e3260e42f323e10f878f73c7c1f7f04940338ad94d8ed850328b6761a107c972
|
4
|
+
data.tar.gz: 6b88d29df010626b918a23d7731ed30262493ef2e1e665a5a9097d357abcbd6f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f051dca1fee545d6be1a7b37e9622fceaef7dfc80cf07eaefe7c8da7f2963f944a827a6d11872e2fdace2f43f3fd78b5e03dbd9eafd1ffb702294f73877792d2
|
7
|
+
data.tar.gz: 28e65c72a9a4ba52787f243a16cb78cd3973e53b3de6e7e4bd07e04809d7e1f0564556570633e2a560e8d85ad6f6ed97e076d2db14422e44989fa81f20bd7e71
|
data/.DS_Store
CHANGED
Binary file
|
data/.babelrc
ADDED
data/CHANGELOG.md
CHANGED
@@ -2,11 +2,32 @@
|
|
2
2
|
|
3
3
|
## [Unreleased](https://github.com/bear-in-mind/abyme/tree/HEAD)
|
4
4
|
|
5
|
-
[Full Changelog](https://github.com/bear-in-mind/abyme/compare/v0.
|
5
|
+
[Full Changelog](https://github.com/bear-in-mind/abyme/compare/v0.5.0...HEAD)
|
6
|
+
|
7
|
+
**Merged pull requests:**
|
8
|
+
|
9
|
+
- retro compatibility with former public method names [\#26](https://github.com/bear-in-mind/abyme/pull/26) ([bear-in-mind](https://github.com/bear-in-mind))
|
10
|
+
|
11
|
+
## [v0.5.0](https://github.com/bear-in-mind/abyme/tree/v0.5.0) (2021-02-26)
|
12
|
+
|
13
|
+
[Full Changelog](https://github.com/bear-in-mind/abyme/compare/v0.2.5...v0.5.0)
|
14
|
+
|
15
|
+
**Merged pull requests:**
|
16
|
+
|
17
|
+
- Dynamic strong params for nested attributes [\#23](https://github.com/bear-in-mind/abyme/pull/23) ([bear-in-mind](https://github.com/bear-in-mind))
|
18
|
+
|
19
|
+
## [v0.2.5](https://github.com/bear-in-mind/abyme/tree/v0.2.5) (2021-02-12)
|
20
|
+
|
21
|
+
[Full Changelog](https://github.com/bear-in-mind/abyme/compare/v0.4.0...v0.2.5)
|
22
|
+
|
23
|
+
## [v0.4.0](https://github.com/bear-in-mind/abyme/tree/v0.4.0) (2021-02-12)
|
24
|
+
|
25
|
+
[Full Changelog](https://github.com/bear-in-mind/abyme/compare/v0.2.4...v0.4.0)
|
6
26
|
|
7
27
|
**Merged pull requests:**
|
8
28
|
|
9
29
|
- Bump nokogiri from 1.10.10 to 1.11.1 [\#22](https://github.com/bear-in-mind/abyme/pull/22) ([dependabot[bot]](https://github.com/apps/dependabot))
|
30
|
+
- Methods naming change & FormBuilder extension [\#21](https://github.com/bear-in-mind/abyme/pull/21) ([bear-in-mind](https://github.com/bear-in-mind))
|
10
31
|
- Solved JS compile bug [\#19](https://github.com/bear-in-mind/abyme/pull/19) ([bear-in-mind](https://github.com/bear-in-mind))
|
11
32
|
|
12
33
|
## [v0.2.4](https://github.com/bear-in-mind/abyme/tree/v0.2.4) (2020-10-18)
|
data/Gemfile.lock
CHANGED
@@ -1,61 +1,61 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
abyme (0.
|
4
|
+
abyme (0.6.2)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
actioncable (6.0.3.
|
10
|
-
actionpack (= 6.0.3.
|
9
|
+
actioncable (6.0.3.7)
|
10
|
+
actionpack (= 6.0.3.7)
|
11
11
|
nio4r (~> 2.0)
|
12
12
|
websocket-driver (>= 0.6.1)
|
13
|
-
actionmailbox (6.0.3.
|
14
|
-
actionpack (= 6.0.3.
|
15
|
-
activejob (= 6.0.3.
|
16
|
-
activerecord (= 6.0.3.
|
17
|
-
activestorage (= 6.0.3.
|
18
|
-
activesupport (= 6.0.3.
|
13
|
+
actionmailbox (6.0.3.7)
|
14
|
+
actionpack (= 6.0.3.7)
|
15
|
+
activejob (= 6.0.3.7)
|
16
|
+
activerecord (= 6.0.3.7)
|
17
|
+
activestorage (= 6.0.3.7)
|
18
|
+
activesupport (= 6.0.3.7)
|
19
19
|
mail (>= 2.7.1)
|
20
|
-
actionmailer (6.0.3.
|
21
|
-
actionpack (= 6.0.3.
|
22
|
-
actionview (= 6.0.3.
|
23
|
-
activejob (= 6.0.3.
|
20
|
+
actionmailer (6.0.3.7)
|
21
|
+
actionpack (= 6.0.3.7)
|
22
|
+
actionview (= 6.0.3.7)
|
23
|
+
activejob (= 6.0.3.7)
|
24
24
|
mail (~> 2.5, >= 2.5.4)
|
25
25
|
rails-dom-testing (~> 2.0)
|
26
|
-
actionpack (6.0.3.
|
27
|
-
actionview (= 6.0.3.
|
28
|
-
activesupport (= 6.0.3.
|
26
|
+
actionpack (6.0.3.7)
|
27
|
+
actionview (= 6.0.3.7)
|
28
|
+
activesupport (= 6.0.3.7)
|
29
29
|
rack (~> 2.0, >= 2.0.8)
|
30
30
|
rack-test (>= 0.6.3)
|
31
31
|
rails-dom-testing (~> 2.0)
|
32
32
|
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
33
|
-
actiontext (6.0.3.
|
34
|
-
actionpack (= 6.0.3.
|
35
|
-
activerecord (= 6.0.3.
|
36
|
-
activestorage (= 6.0.3.
|
37
|
-
activesupport (= 6.0.3.
|
33
|
+
actiontext (6.0.3.7)
|
34
|
+
actionpack (= 6.0.3.7)
|
35
|
+
activerecord (= 6.0.3.7)
|
36
|
+
activestorage (= 6.0.3.7)
|
37
|
+
activesupport (= 6.0.3.7)
|
38
38
|
nokogiri (>= 1.8.5)
|
39
|
-
actionview (6.0.3.
|
40
|
-
activesupport (= 6.0.3.
|
39
|
+
actionview (6.0.3.7)
|
40
|
+
activesupport (= 6.0.3.7)
|
41
41
|
builder (~> 3.1)
|
42
42
|
erubi (~> 1.4)
|
43
43
|
rails-dom-testing (~> 2.0)
|
44
44
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
45
|
-
activejob (6.0.3.
|
46
|
-
activesupport (= 6.0.3.
|
45
|
+
activejob (6.0.3.7)
|
46
|
+
activesupport (= 6.0.3.7)
|
47
47
|
globalid (>= 0.3.6)
|
48
|
-
activemodel (6.0.3.
|
49
|
-
activesupport (= 6.0.3.
|
50
|
-
activerecord (6.0.3.
|
51
|
-
activemodel (= 6.0.3.
|
52
|
-
activesupport (= 6.0.3.
|
53
|
-
activestorage (6.0.3.
|
54
|
-
actionpack (= 6.0.3.
|
55
|
-
activejob (= 6.0.3.
|
56
|
-
activerecord (= 6.0.3.
|
57
|
-
marcel (~> 0.
|
58
|
-
activesupport (6.0.3.
|
48
|
+
activemodel (6.0.3.7)
|
49
|
+
activesupport (= 6.0.3.7)
|
50
|
+
activerecord (6.0.3.7)
|
51
|
+
activemodel (= 6.0.3.7)
|
52
|
+
activesupport (= 6.0.3.7)
|
53
|
+
activestorage (6.0.3.7)
|
54
|
+
actionpack (= 6.0.3.7)
|
55
|
+
activejob (= 6.0.3.7)
|
56
|
+
activerecord (= 6.0.3.7)
|
57
|
+
marcel (~> 1.0.0)
|
58
|
+
activesupport (6.0.3.7)
|
59
59
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
60
60
|
i18n (>= 0.7, < 2)
|
61
61
|
minitest (~> 5.1)
|
@@ -63,66 +63,76 @@ GEM
|
|
63
63
|
zeitwerk (~> 2.2, >= 2.2.2)
|
64
64
|
addressable (2.7.0)
|
65
65
|
public_suffix (>= 2.0.2, < 5.0)
|
66
|
+
bindex (0.8.1)
|
66
67
|
builder (3.2.4)
|
67
|
-
|
68
|
+
byebug (11.1.3)
|
69
|
+
capybara (3.35.3)
|
68
70
|
addressable
|
69
71
|
mini_mime (>= 0.1.3)
|
70
72
|
nokogiri (~> 1.8)
|
71
73
|
rack (>= 1.6.0)
|
72
74
|
rack-test (>= 0.6.3)
|
73
|
-
regexp_parser (
|
75
|
+
regexp_parser (>= 1.5, < 3.0)
|
74
76
|
xpath (~> 3.2)
|
75
77
|
childprocess (3.0.0)
|
76
|
-
|
78
|
+
coderay (1.1.3)
|
79
|
+
concurrent-ruby (1.1.9)
|
77
80
|
crass (1.0.6)
|
78
|
-
database_cleaner (
|
79
|
-
|
80
|
-
|
81
|
-
|
81
|
+
database_cleaner-active_record (2.0.1)
|
82
|
+
activerecord (>= 5.a)
|
83
|
+
database_cleaner-core (~> 2.0.0)
|
84
|
+
database_cleaner-core (2.0.1)
|
82
85
|
diff-lcs (1.4.4)
|
83
|
-
docile (1.
|
86
|
+
docile (1.4.0)
|
84
87
|
erubi (1.10.0)
|
88
|
+
generator_spec (0.9.4)
|
89
|
+
activesupport (>= 3.0.0)
|
90
|
+
railties (>= 3.0.0)
|
85
91
|
globalid (0.4.2)
|
86
92
|
activesupport (>= 4.2.0)
|
87
|
-
i18n (1.8.
|
93
|
+
i18n (1.8.10)
|
88
94
|
concurrent-ruby (~> 1.0)
|
89
|
-
loofah (2.
|
95
|
+
loofah (2.10.0)
|
90
96
|
crass (~> 1.0.2)
|
91
97
|
nokogiri (>= 1.5.9)
|
92
98
|
mail (2.7.1)
|
93
99
|
mini_mime (>= 0.1.1)
|
94
|
-
marcel (0.
|
95
|
-
mimemagic (~> 0.3.2)
|
100
|
+
marcel (1.0.1)
|
96
101
|
method_source (1.0.0)
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
nokogiri (1.11.1)
|
102
|
+
mini_mime (1.1.0)
|
103
|
+
mini_portile2 (2.5.3)
|
104
|
+
minitest (5.14.4)
|
105
|
+
nio4r (2.5.7)
|
106
|
+
nokogiri (1.11.7)
|
103
107
|
mini_portile2 (~> 2.5.0)
|
104
108
|
racc (~> 1.4)
|
109
|
+
pry (0.13.1)
|
110
|
+
coderay (~> 1.1)
|
111
|
+
method_source (~> 1.0)
|
112
|
+
pry-byebug (3.9.0)
|
113
|
+
byebug (~> 11.0)
|
114
|
+
pry (~> 0.13.0)
|
105
115
|
public_suffix (4.0.6)
|
106
|
-
puma (5.
|
116
|
+
puma (5.3.2)
|
107
117
|
nio4r (~> 2.0)
|
108
118
|
racc (1.5.2)
|
109
119
|
rack (2.2.3)
|
110
120
|
rack-test (1.1.0)
|
111
121
|
rack (>= 1.0, < 3)
|
112
|
-
rails (6.0.3.
|
113
|
-
actioncable (= 6.0.3.
|
114
|
-
actionmailbox (= 6.0.3.
|
115
|
-
actionmailer (= 6.0.3.
|
116
|
-
actionpack (= 6.0.3.
|
117
|
-
actiontext (= 6.0.3.
|
118
|
-
actionview (= 6.0.3.
|
119
|
-
activejob (= 6.0.3.
|
120
|
-
activemodel (= 6.0.3.
|
121
|
-
activerecord (= 6.0.3.
|
122
|
-
activestorage (= 6.0.3.
|
123
|
-
activesupport (= 6.0.3.
|
122
|
+
rails (6.0.3.7)
|
123
|
+
actioncable (= 6.0.3.7)
|
124
|
+
actionmailbox (= 6.0.3.7)
|
125
|
+
actionmailer (= 6.0.3.7)
|
126
|
+
actionpack (= 6.0.3.7)
|
127
|
+
actiontext (= 6.0.3.7)
|
128
|
+
actionview (= 6.0.3.7)
|
129
|
+
activejob (= 6.0.3.7)
|
130
|
+
activemodel (= 6.0.3.7)
|
131
|
+
activerecord (= 6.0.3.7)
|
132
|
+
activestorage (= 6.0.3.7)
|
133
|
+
activesupport (= 6.0.3.7)
|
124
134
|
bundler (>= 1.3.0)
|
125
|
-
railties (= 6.0.3.
|
135
|
+
railties (= 6.0.3.7)
|
126
136
|
sprockets-rails (>= 2.0.0)
|
127
137
|
rails-controller-testing (1.0.5)
|
128
138
|
actionpack (>= 5.0.1.rc1)
|
@@ -133,14 +143,14 @@ GEM
|
|
133
143
|
nokogiri (>= 1.6)
|
134
144
|
rails-html-sanitizer (1.3.0)
|
135
145
|
loofah (~> 2.3)
|
136
|
-
railties (6.0.3.
|
137
|
-
actionpack (= 6.0.3.
|
138
|
-
activesupport (= 6.0.3.
|
146
|
+
railties (6.0.3.7)
|
147
|
+
actionpack (= 6.0.3.7)
|
148
|
+
activesupport (= 6.0.3.7)
|
139
149
|
method_source
|
140
150
|
rake (>= 0.8.7)
|
141
151
|
thor (>= 0.20.3, < 2.0)
|
142
152
|
rake (13.0.3)
|
143
|
-
regexp_parser (1.
|
153
|
+
regexp_parser (2.1.1)
|
144
154
|
rspec-core (3.10.1)
|
145
155
|
rspec-support (~> 3.10.0)
|
146
156
|
rspec-expectations (3.10.1)
|
@@ -149,10 +159,10 @@ GEM
|
|
149
159
|
rspec-mocks (3.10.2)
|
150
160
|
diff-lcs (>= 1.2.0, < 2.0)
|
151
161
|
rspec-support (~> 3.10.0)
|
152
|
-
rspec-rails (
|
153
|
-
actionpack (>=
|
154
|
-
activesupport (>=
|
155
|
-
railties (>=
|
162
|
+
rspec-rails (5.0.1)
|
163
|
+
actionpack (>= 5.2)
|
164
|
+
activesupport (>= 5.2)
|
165
|
+
railties (>= 5.2)
|
156
166
|
rspec-core (~> 3.10)
|
157
167
|
rspec-expectations (~> 3.10)
|
158
168
|
rspec-mocks (~> 3.10)
|
@@ -162,11 +172,16 @@ GEM
|
|
162
172
|
selenium-webdriver (3.142.7)
|
163
173
|
childprocess (>= 0.5, < 4.0)
|
164
174
|
rubyzip (>= 1.2.2)
|
165
|
-
|
175
|
+
simple_form (5.1.0)
|
176
|
+
actionpack (>= 5.2)
|
177
|
+
activemodel (>= 5.2)
|
178
|
+
simplecov (0.21.2)
|
166
179
|
docile (~> 1.1)
|
167
180
|
simplecov-html (~> 0.11)
|
181
|
+
simplecov_json_formatter (~> 0.1)
|
168
182
|
simplecov-html (0.12.3)
|
169
183
|
simplecov-lcov (0.8.0)
|
184
|
+
simplecov_json_formatter (0.1.3)
|
170
185
|
sprockets (4.0.2)
|
171
186
|
concurrent-ruby (~> 1.0)
|
172
187
|
rack (> 1, < 3)
|
@@ -179,11 +194,16 @@ GEM
|
|
179
194
|
thread_safe (0.3.6)
|
180
195
|
tzinfo (1.2.9)
|
181
196
|
thread_safe (~> 0.1)
|
182
|
-
|
197
|
+
web-console (4.1.0)
|
198
|
+
actionview (>= 6.0.0)
|
199
|
+
activemodel (>= 6.0.0)
|
200
|
+
bindex (>= 0.4.0)
|
201
|
+
railties (>= 6.0.0)
|
202
|
+
webdrivers (4.6.0)
|
183
203
|
nokogiri (~> 1.6)
|
184
204
|
rubyzip (>= 1.3.0)
|
185
205
|
selenium-webdriver (>= 3.0, < 4.0)
|
186
|
-
websocket-driver (0.7.
|
206
|
+
websocket-driver (0.7.5)
|
187
207
|
websocket-extensions (>= 0.1.0)
|
188
208
|
websocket-extensions (0.1.5)
|
189
209
|
xpath (3.2.0)
|
@@ -196,17 +216,22 @@ PLATFORMS
|
|
196
216
|
DEPENDENCIES
|
197
217
|
abyme!
|
198
218
|
bundler (~> 2.0)
|
219
|
+
byebug
|
199
220
|
capybara
|
200
221
|
database_cleaner-active_record
|
222
|
+
generator_spec
|
223
|
+
pry-byebug
|
201
224
|
puma
|
202
|
-
rails
|
225
|
+
rails (~> 6.0.3.6)
|
203
226
|
rails-controller-testing
|
204
227
|
rake (~> 13.0)
|
205
228
|
rspec-rails
|
229
|
+
simple_form
|
206
230
|
simplecov
|
207
231
|
simplecov-lcov
|
208
232
|
sqlite3
|
233
|
+
web-console
|
209
234
|
webdrivers
|
210
235
|
|
211
236
|
BUNDLED WITH
|
212
|
-
2.
|
237
|
+
2.2.13
|
data/README.md
CHANGED
@@ -1,33 +1,28 @@
|
|
1
|
-
#
|
1
|
+
# abyme 🕳
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/abyme.svg)](https://badge.fury.io/rb/abyme)
|
4
4
|
![build](https://github.com/bear-in-mind/abyme/workflows/build/badge.svg)
|
5
5
|
[![Maintainability](https://api.codeclimate.com/v1/badges/f591a9e00f7cf5188ad5/maintainability)](https://codeclimate.com/github/bear-in-mind/abyme/maintainability)
|
6
|
-
[![Coverage Status](https://coveralls.io/repos/github/bear-in-mind/abyme/badge.svg)](https://coveralls.io/github/bear-in-mind/abyme?branch=master)
|
6
|
+
[![Coverage Status](https://coveralls.io/repos/github/bear-in-mind/abyme/badge.svg?branch=master)](https://coveralls.io/github/bear-in-mind/abyme?branch=master)
|
7
7
|
|
8
|
-
abyme
|
8
|
+
abyme is an easy and form-agnostic way to handle nested attributes in Rails, using [stimulus](https://stimulusjs.org/handbook/introduction) under the hood. Here's an example :
|
9
9
|
```ruby
|
10
10
|
# views/projects/_form.html.erb
|
11
|
-
<%=
|
12
|
-
<%= f.
|
13
|
-
<%= f.
|
14
|
-
|
15
|
-
|
11
|
+
<%= form_for @project do |f| %>
|
12
|
+
<%= f.text_field :title %>
|
13
|
+
<%= f.text_area :description %>
|
14
|
+
|
16
15
|
<%= f.abyme_for(:tasks) %>
|
16
|
+
|
17
|
+
<%= f.submit 'Save' %>
|
17
18
|
<% end %>
|
18
19
|
```
|
19
|
-
Supposing you have a partial located in `views/abyme/_task_fields` containing your fields for `tasks`, the `abyme_for` command will generate and display 3 elements in this order :
|
20
|
-
- A div containing all task fields for `@project.tasks` (either persisted or already built instances of `tasks`)
|
21
|
-
- A div which will contain all additional tasks about to be created (added through the `Add task` button below)
|
22
|
-
- A button to generate fields for new instances of tasks
|
23
|
-
|
24
|
-
Have a look below to learn more about the different options and needed configuration.
|
25
|
-
|
26
|
-
|
27
|
-
## Disclaimer
|
28
|
-
This project is still a work in progress and subject to change. We would advise not to use it in production code just yet.
|
20
|
+
Supposing you have a `Project` that `has_many :tasks` and a partial located in `views/abyme/_task_fields` containing your form fields for `tasks`, the `abyme_for` command will generate and display 3 elements in this order :
|
21
|
+
- A `div` containing all task fields for `@project.tasks` (either persisted or already built instances of `tasks`)
|
22
|
+
- A `div` which will contain all additional tasks about to be created (added through the `Add task` button below)
|
23
|
+
- A `button` to generate fields for new instances of tasks
|
29
24
|
|
30
|
-
|
25
|
+
Have a look below to learn more about configuration and all its different options.
|
31
26
|
|
32
27
|
## Demo app
|
33
28
|
|
@@ -51,7 +46,12 @@ And then execute:
|
|
51
46
|
$ yarn add abyme
|
52
47
|
|
53
48
|
|
54
|
-
Assuming you [already installed Stimulus](https://stimulusjs.org/handbook/introduction),
|
49
|
+
Assuming you [already installed Stimulus](https://stimulusjs.org/handbook/introduction), you need to register the `stimulus` controller that takes care of the JavaScript behaviour. You can launch this generator :
|
50
|
+
```bash
|
51
|
+
rails generate abyme:stimulus
|
52
|
+
```
|
53
|
+
Or you can register it yourself :
|
54
|
+
|
55
55
|
```javascript
|
56
56
|
// app/javascript/controllers/index.js
|
57
57
|
import { Application } from "stimulus"
|
@@ -66,154 +66,137 @@ application.load(definitionsFromContext(context))
|
|
66
66
|
application.register('abyme', AbymeController)
|
67
67
|
```
|
68
68
|
|
69
|
-
##
|
70
|
-
|
71
|
-
|
69
|
+
## Getting started
|
70
|
+
|
71
|
+
To learn more about the *why* of this gem, check out our [wiki](https://github.com/bear-in-mind/abyme/wiki/What-are-nested-forms-and-why-a-new-gem-%3F)
|
72
|
+
|
73
|
+
You may also check out our [step by step tutorial](https://github.com/bear-in-mind/abyme/wiki/Step-by-step-Tutorial) and our [advanced configuration guide](https://github.com/bear-in-mind/abyme/wiki/Step-by-step-:-Advanced-configuration) (currently in construction).
|
74
|
+
## Documentation
|
75
|
+
As in our [our tutorial](https://github.com/bear-in-mind/abyme/wiki/Step-by-step-Tutorial), we'll assume we have a `Project` model, that `has_many :tasks` for the rest of the documentation.
|
76
|
+
### Generators
|
77
|
+
To be up and running in no time, we built a few generators. Feel free to skip these if you prefer a manual implementation.
|
78
|
+
#### Resource
|
79
|
+
To generate everything you need with one command, use this generator :
|
80
|
+
```bash
|
81
|
+
rails generate abyme:resource project tasks
|
82
|
+
# Includes configuration in Project model
|
83
|
+
# Adds abyme_attributes in ProjectsController permitted params
|
84
|
+
# Creates a partial and minimum boilerplate in app/views/abyme/_task_fields.html.erb
|
85
|
+
```
|
86
|
+
Now, head to your parent form and [keep reading](https://github.com/eki-177/abyme#abyme_forassociation-options---block) !
|
87
|
+
|
88
|
+
You can also specify [attributes to be permitted](https://github.com/eki-177/abyme#model), or permit all of them (see below). This will populate the partial with input fields for the specified attributes
|
89
|
+
```bash
|
90
|
+
rails generate abyme:resource project tasks description title
|
91
|
+
# Includes configuration in Project model, including permitted attributes
|
92
|
+
# Adds abyme_attributes in ProjectsController permitted params
|
93
|
+
# Creates a partial with input fields for the specified attributes in app/views/abyme/_task_fields.html.erb
|
94
|
+
```
|
72
95
|
|
73
|
-
|
96
|
+
#### Individual generators
|
97
|
+
All the generators launched by the main `resource` generator are available individually :
|
98
|
+
```bash
|
99
|
+
# Controller
|
100
|
+
rails generate abyme:controller Projects
|
101
|
+
|
102
|
+
# Model
|
103
|
+
# Permit only a few attributes
|
104
|
+
rails generate abyme:model project tasks description title
|
105
|
+
# Permit all attributes
|
106
|
+
rails generate abyme:model project participants all_attributes
|
107
|
+
|
108
|
+
# Views
|
109
|
+
# Without attributes (use this if you're not using SimpleForm or don't care about generating input fields)
|
110
|
+
rails generate abyme:view tasks
|
111
|
+
# With a few attributes
|
112
|
+
rails generate abyme:view tasks name description
|
113
|
+
# With all attributes
|
114
|
+
rails generate abyme:view tasks all_attributes
|
115
|
+
```
|
74
116
|
|
75
|
-
|
117
|
+
### Model
|
76
118
|
|
77
|
-
|
119
|
+
💡 Don't forget to `include Abyme::Model` in your parent model
|
78
120
|
|
79
|
-
|
80
|
-
|
121
|
+
#### #abymize(:association, permit: nil, reject: nil, options = {})
|
122
|
+
In models, the `abyme_for :association` acts as an alias for this command :
|
81
123
|
```ruby
|
82
|
-
|
83
|
-
class Project < ApplicationRecord
|
84
|
-
has_many :tasks
|
85
|
-
validates :title, :description, presence: true
|
86
|
-
end
|
87
|
-
|
88
|
-
# models/task.rb
|
89
|
-
class Task < ApplicationRecord
|
90
|
-
belongs_to :project
|
91
|
-
has_many :comments
|
92
|
-
validates :title, :description, presence: true
|
93
|
-
end
|
94
|
-
|
95
|
-
# models/comment.rb
|
96
|
-
class Comment < ApplicationRecord
|
97
|
-
belongs_to :task
|
98
|
-
validates :content, presence: true
|
99
|
-
end
|
124
|
+
accepts_nested_attributes_for :association, reject_if: :all_blank, :allow_destroy: true
|
100
125
|
```
|
101
|
-
|
102
|
-
|
126
|
+
|
127
|
+
* `permit: []` : allows you to generate a hash of attributes that can be easily called on the controller side through the `::abyme_attributes` class method (see details below).
|
103
128
|
```ruby
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
# ...
|
109
|
-
abymize :tasks
|
110
|
-
end
|
111
|
-
|
112
|
-
# models/task.rb
|
113
|
-
class Task < ApplicationRecord
|
114
|
-
include Abyme::Model
|
115
|
-
has_many :comments, inverse_of: :task
|
116
|
-
# ...
|
117
|
-
abymize :comments
|
118
|
-
end
|
129
|
+
abymize :association, permit: [:name, :description]
|
130
|
+
|
131
|
+
# You may also permit all attributes like so :
|
132
|
+
abymize :association, permit: :all_attributes
|
119
133
|
```
|
120
|
-
Note the use of the `inverse_of` option. It is needed for Rails to effectively associate children to their yet unsaved parent. Have a peek to the bottom of [this page](https://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html#method-i-accepts_nested_attributes_for) for more info.
|
121
|
-
|
122
|
-
### Controller
|
123
|
-
Since we're dealing with one form, we're only concerned with one controller : the one the form routes to. In our example, this would be the `ProjectsController`.
|
124
|
-
The only configuration needed here will concern our strong params. Nested attributes require a very specific syntax to white-list the permitted attributes. It looks like this :
|
125
134
|
|
135
|
+
* `reject: []` : allows you to add all attributes to `::abyme_attributes`, excepted the ones specified.
|
126
136
|
```ruby
|
127
|
-
|
128
|
-
params.require(:project).permit(
|
129
|
-
:title, :description, tasks_attributes: [
|
130
|
-
:id, :title, :description, :_destroy, comments_attributes: [
|
131
|
-
:id, :content, :_destroy
|
132
|
-
]
|
133
|
-
]
|
134
|
-
)
|
135
|
-
end
|
137
|
+
abymize :association, reject: [:password]
|
136
138
|
```
|
137
|
-
A few explanations here.
|
138
139
|
|
139
|
-
*
|
140
|
+
* `options: {}` : [the same options] you may pass to the `accepts_nested_attributes` method (see [this link](https://api.rubyonrails.org/v6.1.0/classes/ActiveRecord/NestedAttributes/ClassMethods.html) for details)
|
141
|
+
```ruby
|
142
|
+
abyme_for :association, limit: 3, allow_destroy: false
|
143
|
+
```
|
140
144
|
|
141
|
-
|
145
|
+
#### ::abyme_attributes
|
146
|
+
Returns a hash to the right format to be included in the `strong params` on the controller side. For a `Project` model with nested `:tasks` :
|
147
|
+
```ruby
|
148
|
+
Project.abyme_attributes
|
149
|
+
# => {tasks_attributes: [:title, :description, :id, :_destroy]}
|
150
|
+
```
|
142
151
|
|
143
|
-
|
152
|
+
### Controller
|
153
|
+
#### #abyme_attributes
|
154
|
+
Infers the name of the resource from the controller name, and calls the `::abyme_attributes` method on it. Hence, in your `ProjectsController` :
|
155
|
+
```ruby
|
156
|
+
def project_params
|
157
|
+
params.require(:project).permit(:title, :description, abyme_attributes)
|
158
|
+
end
|
159
|
+
```
|
144
160
|
|
145
|
-
|
161
|
+
### Views
|
146
162
|
|
147
|
-
|
148
|
-
|
149
|
-
* Display fields for the **new records** (future `:tasks` not yet persisted)
|
150
|
-
* A button to **trigger the addition** of fields for a new resource (an `Add a new task` button)
|
151
|
-
* A button to **remove fields** for a given resource (`Remove task`)
|
163
|
+
#### #abyme_for(:association, options = {}, &block)
|
164
|
+
This is the container for all your nested fields. It takes the symbolized association as a parameter, along with options, and an optional block to specify any layout you may wish for the different parts of the `abyme` builder.
|
152
165
|
|
153
|
-
|
166
|
+
💡 Please note an id is automatically added to this element, which value is : `abyme--association_name`.
|
154
167
|
|
168
|
+
💡 If you don't pass a block, `records`, `new_records` and `add_association` will be called and will appear in this order in your layout.
|
169
|
+
* `partial: ` : allows you to indicate a custom partial path for both `records` and `new_records`
|
155
170
|
```ruby
|
156
|
-
|
157
|
-
<%= simple_form_for @project do |f| %>
|
158
|
-
<%= f.input :title %>
|
159
|
-
<%= f.input :description %>
|
160
|
-
<%= f.submit 'Save' %>
|
161
|
-
|
162
|
-
<%= f.abyme_for(:tasks) do |abyme| %>
|
171
|
+
<%= f.abyme_for(:tasks, partial: 'projects/task_fields') do |abyme| %>
|
163
172
|
<%= abyme.records %>
|
164
173
|
<%= abyme.new_records %>
|
165
174
|
<%= add_associated_record %>
|
166
175
|
<% end %>
|
167
|
-
<% end %>
|
168
|
-
```
|
169
|
-
|
170
|
-
`abyme.records` will contain the persisted associations fields, while `abyme.new_records` will contain fields for the new associations. `add_associated_record` will by default generate a button with a text of type "Add `resource_name`". To work properly, this method **has** to be called **inside the block** passed to the `abyme_for` method.
|
171
|
-
|
172
|
-
Now where's the code for these fields ? abyme will assume a **partial** to be present in the directory `/views/abyme` with a *name respecting this naming convention* (just like with [cocoon](https://github.com/nathanvda/cocoon#basic-usage)): `_singular_association_name_fields.html.erb`.
|
173
|
-
|
174
|
-
This partial might look like this:
|
175
|
-
```ruby
|
176
|
-
# views/abyme/_task_fields.html.erb
|
177
|
-
<%= f.input :title %>
|
178
|
-
<%= f.input :description %>
|
179
|
-
<%= f.hidden_field :_destroy %>
|
180
|
-
|
181
|
-
<%= remove_associated_record(tag: :div) do %>
|
182
|
-
<i class="fas fa-trash"></i>
|
183
|
-
<% end %>
|
184
176
|
```
|
185
|
-
|
186
|
-
Note the presence of the `remove_associated_record` button. Here, we pass it an option to make it a `<div>`, as well as a block to customize its content. Don't forget the `_destroy` attribute, needed to mark items for destruction.
|
187
|
-
|
188
|
-
### What about the controller ?
|
189
|
-
|
190
|
-
What about it ? Well, not much. That's the actual magical thing about `nested_attributes`: once your model is aware of its acceptance of those for a given association, and your strong params are correctly configured, there's nothing else to do.
|
191
|
-
`@project.create(project_params)` is all you'll need to save a project along with its descendants 👨👧👧
|
192
|
-
|
193
|
-
### Auto mode
|
194
|
-
|
195
|
-
Let's now take care of our comments fields. We'll add these using our neat *automatic mode*: just stick this line at the end of the partial :
|
177
|
+
* `limit: ` : allows you to limit the number of new fields that can be created through JS. If you need to limit the number of associations in database, you will need to add validations. You can also pass an option [in your model as well](https://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html#method-i-accepts_nested_attributes_for).
|
196
178
|
```ruby
|
197
|
-
|
198
|
-
#
|
199
|
-
<%=
|
179
|
+
<%= f.abyme_for(:tasks, limit: 5) do |abyme| %>
|
180
|
+
# Beyond 5 tasks, the add button won't add any more fields. See events section below to see how to handle the 'abyme:limit-reached' event
|
181
|
+
<%= abyme.records %>
|
182
|
+
<%= abyme.new_records %>
|
183
|
+
<%= add_associated_record %>
|
184
|
+
<% end %>
|
200
185
|
```
|
201
|
-
|
202
|
-
|
203
|
-
## Advanced usage
|
204
|
-
### Models
|
205
|
-
In models, the `abyme_for :association` acts as an alias for this command :
|
206
|
-
|
186
|
+
* `min_count: ` by default, there won't be any blank fields added on page load. By passing a `min_count` option, you can set how many empty fields should appear in the form.
|
207
187
|
```ruby
|
208
|
-
|
188
|
+
<%= f.abyme_for(:tasks, min_count: 1) do |abyme| %>
|
189
|
+
# 1 blank task will automatically be added to the form.
|
190
|
+
<%= abyme.records %>
|
191
|
+
<%= abyme.new_records %>
|
192
|
+
<%= add_associated_record %>
|
193
|
+
<% end %>
|
209
194
|
```
|
210
195
|
|
211
|
-
|
212
|
-
|
213
|
-
abyme_for :association, limit: 3, allow_destroy: false
|
214
|
-
```
|
196
|
+
*If you're not passing a block*, the `abyme_for` method can take a few additional options:
|
197
|
+
* `button_text: ` this will set the `add_association` button text to the string of your choice.
|
215
198
|
|
216
|
-
|
199
|
+
💡 All options that should be passed to either `records` or `new_records` below can be passed here and will be passed down.
|
217
200
|
|
218
201
|
#### #records
|
219
202
|
A few options can be passed to `abyme.records`:
|
@@ -250,7 +233,7 @@ A few options can be passed to `abyme.records`:
|
|
250
233
|
<%= add_associated_record %>
|
251
234
|
<% end %>
|
252
235
|
```
|
253
|
-
* `wrapper_html:` : gives you the possibility to add any HTML attribute you may want to the wrapper containing all fields.
|
236
|
+
* `wrapper_html:` : gives you the possibility to add any HTML attribute you may want to the wrapper containing all persisted fields.
|
254
237
|
```ruby
|
255
238
|
<%= f.abyme_for(:tasks) do |abyme| %>
|
256
239
|
<%= abyme.records(wrapper_html: { class: "persisted-records" }) %>
|
@@ -296,39 +279,6 @@ As you may have seen above, you can also pass a block to the method to give it w
|
|
296
279
|
<% end %>
|
297
280
|
```
|
298
281
|
|
299
|
-
#### #abyme_for(:association, form_object)
|
300
|
-
This is the container for all your nested fields. It takes two parameters (the symbolized association and the `form_builder`), and some optional ones. Please note an id is automatically added to this element, which value is : `abyme--association`.
|
301
|
-
* `partial:` : allows you to indicate a custom partial path for both `records` and `new_records`
|
302
|
-
```ruby
|
303
|
-
<%= f.abyme_for(:tasks, partial: 'projects/task_fields') do |abyme| %>
|
304
|
-
<%= abyme.records %>
|
305
|
-
<%= abyme.new_records %>
|
306
|
-
<%= add_associated_record %>
|
307
|
-
<% end %>
|
308
|
-
```
|
309
|
-
* `limit:` : allows you to limit the number of new fields that can be created through JS. If you need to limit the number of associations in database, you will need to add validations. You can also pass an option [in your model as well](https://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html#method-i-accepts_nested_attributes_for).
|
310
|
-
```ruby
|
311
|
-
<%= f.abyme_for(:tasks, limit: 5) do |abyme| %>
|
312
|
-
# Beyond 5 tasks, the add button won't add any more fields. See events section below to see how to handle the 'abyme:limit-reached' event
|
313
|
-
<%= abyme.records %>
|
314
|
-
<%= abyme.new_records %>
|
315
|
-
<%= add_associated_record %>
|
316
|
-
<% end %>
|
317
|
-
```
|
318
|
-
* `min_count` : by default, there won't be any blank fields added on page load. By passing a `min_count` option, you can set how many empty fields should appear in the form.
|
319
|
-
```ruby
|
320
|
-
<%= f.abyme_for(:tasks, min_count: 1) do |abyme| %>
|
321
|
-
# 1 blank task will automatically be added to the form.
|
322
|
-
<%= abyme.records %>
|
323
|
-
<%= abyme.new_records %>
|
324
|
-
<%= add_associated_record %>
|
325
|
-
<% end %>
|
326
|
-
```
|
327
|
-
|
328
|
-
*When in auto mode*, the abyme_for method can take a few options:
|
329
|
-
* `button_text:` : this will set the `add_associated_record` button text to the string of your choice.
|
330
|
-
* All options that should be passed to either `records` or `new_records` can be passed here and will be passed down.
|
331
|
-
|
332
282
|
## Events
|
333
283
|
This part is still a work in progress and subject to change. We're providing some basic self-explanatory events to attach to. These are emitted by the main container (created by the `abyme_for` method).
|
334
284
|
|
@@ -358,7 +308,7 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
358
308
|
|
359
309
|
## Contributing
|
360
310
|
|
361
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
311
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/eki-177/abyme.
|
362
312
|
|
363
313
|
## License
|
364
314
|
|