abyme 0.2.3 → 0.2.4

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
  SHA256:
3
- metadata.gz: c47483c64b5a49b57f83cf3e779b089aff6cfb218a6cc4cc56c35b7cf14ea44a
4
- data.tar.gz: ad6152628fe3731f04a19bf3afabf45f1f9c2fc92f7af2637ce990cd8ad801e8
3
+ metadata.gz: 585adff10e80cf9646d03a7d2251188d6d8be083a3f9f9b3e7fe019187904c39
4
+ data.tar.gz: 1e17608e8bde56231bf57016d4d5f880f29915e7cf7c98cd51f46e21ff06609b
5
5
  SHA512:
6
- metadata.gz: 1fb02ef0524a28ae5a7445c1f51d3144e1ae11b4bbe710dd5e4d87b8a767d4b0e598f512293892cc114f06e492c73074a4c409a902a2911e29b0329bdf0a1a96
7
- data.tar.gz: 6bb56a17944fd6f4577580bc19cb5a004903e7dc149c65aedbc3d6e34469565c66f26318147cdb7cde107d7adc06ad3176b875557c6cb8ef8412489d3131ea09
6
+ metadata.gz: efc39dc12b33a25c5b5b61f5079b2b0f7605b7b6ae557cebad526c9efa88475ce4f3e3841fce0e3a04bc87d823e9b52c15a6a2655203cd324ff6985ef229bec8
7
+ data.tar.gz: fe4dd5956a8afe5ac9d48df970a5c71a0fbabd880f36b19e8de997dc0a622bee5f23c1064e7f1db8b876439909b48bccdbe66bc514bd51573945f950a66699a4
data/.DS_Store CHANGED
Binary file
@@ -0,0 +1,60 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: build
9
+
10
+ on:
11
+ push:
12
+ branches: [ master ]
13
+ pull_request:
14
+ branches: [ master ]
15
+
16
+ jobs:
17
+ test:
18
+ runs-on: ubuntu-latest
19
+
20
+ steps:
21
+ - uses: actions/checkout@v2
22
+ - name: Set up Ruby
23
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
24
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
25
+ # uses: ruby/setup-ruby@v1
26
+ uses: ruby/setup-ruby@ec106b438a1ff6ff109590de34ddc62c540232e0
27
+ with:
28
+ ruby-version: 2.6
29
+ - name: Install sqlite headers
30
+ run: |
31
+ sudo apt-get update
32
+ sudo apt-get install libsqlite3-dev
33
+
34
+ - name: Install dependencies
35
+ run: bundle install
36
+
37
+ - name: Prepare Database
38
+ run: bundle exec rails db:create db:migrate
39
+ env:
40
+ DB_CONNECTION: sqlite
41
+ DB_DATABASE: db/test.sqlite3
42
+ RAILS_ENV: test
43
+
44
+ - name: Run tests
45
+ run: bundle exec rake
46
+ env:
47
+ DB_CONNECTION: sqlite
48
+ DB_DATABASE: db/test.sqlite3
49
+ RAILS_ENV: test
50
+
51
+ - name: Coveralls
52
+ uses: coverallsapp/github-action@master
53
+ with:
54
+ github-token: ${{ secrets.GITHUB_TOKEN }}
55
+
56
+ - name: Create Coverage Artifact
57
+ uses: actions/upload-artifact@v2
58
+ with:
59
+ name: code-coverage
60
+ path: coverage/
data/.gitignore CHANGED
@@ -19,3 +19,4 @@ spec/dummy/db/*.sqlite3-journal
19
19
  spec/dummy/db/log/*.log
20
20
  spec/dummy/tmp/
21
21
  spec/dummy/.sass-cache
22
+ spec/dummy/public
File without changes
@@ -1,11 +1,28 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- abyme (0.2.3)
4
+ abyme (0.2.4)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
+ actioncable (6.0.3.4)
10
+ actionpack (= 6.0.3.4)
11
+ nio4r (~> 2.0)
12
+ websocket-driver (>= 0.6.1)
13
+ actionmailbox (6.0.3.4)
14
+ actionpack (= 6.0.3.4)
15
+ activejob (= 6.0.3.4)
16
+ activerecord (= 6.0.3.4)
17
+ activestorage (= 6.0.3.4)
18
+ activesupport (= 6.0.3.4)
19
+ mail (>= 2.7.1)
20
+ actionmailer (6.0.3.4)
21
+ actionpack (= 6.0.3.4)
22
+ actionview (= 6.0.3.4)
23
+ activejob (= 6.0.3.4)
24
+ mail (~> 2.5, >= 2.5.4)
25
+ rails-dom-testing (~> 2.0)
9
26
  actionpack (6.0.3.4)
10
27
  actionview (= 6.0.3.4)
11
28
  activesupport (= 6.0.3.4)
@@ -13,41 +30,105 @@ GEM
13
30
  rack-test (>= 0.6.3)
14
31
  rails-dom-testing (~> 2.0)
15
32
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
33
+ actiontext (6.0.3.4)
34
+ actionpack (= 6.0.3.4)
35
+ activerecord (= 6.0.3.4)
36
+ activestorage (= 6.0.3.4)
37
+ activesupport (= 6.0.3.4)
38
+ nokogiri (>= 1.8.5)
16
39
  actionview (6.0.3.4)
17
40
  activesupport (= 6.0.3.4)
18
41
  builder (~> 3.1)
19
42
  erubi (~> 1.4)
20
43
  rails-dom-testing (~> 2.0)
21
44
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
45
+ activejob (6.0.3.4)
46
+ activesupport (= 6.0.3.4)
47
+ globalid (>= 0.3.6)
48
+ activemodel (6.0.3.4)
49
+ activesupport (= 6.0.3.4)
50
+ activerecord (6.0.3.4)
51
+ activemodel (= 6.0.3.4)
52
+ activesupport (= 6.0.3.4)
53
+ activestorage (6.0.3.4)
54
+ actionpack (= 6.0.3.4)
55
+ activejob (= 6.0.3.4)
56
+ activerecord (= 6.0.3.4)
57
+ marcel (~> 0.3.1)
22
58
  activesupport (6.0.3.4)
23
59
  concurrent-ruby (~> 1.0, >= 1.0.2)
24
60
  i18n (>= 0.7, < 2)
25
61
  minitest (~> 5.1)
26
62
  tzinfo (~> 1.1)
27
63
  zeitwerk (~> 2.2, >= 2.2.2)
64
+ addressable (2.7.0)
65
+ public_suffix (>= 2.0.2, < 5.0)
28
66
  builder (3.2.4)
67
+ capybara (3.33.0)
68
+ addressable
69
+ mini_mime (>= 0.1.3)
70
+ nokogiri (~> 1.8)
71
+ rack (>= 1.6.0)
72
+ rack-test (>= 0.6.3)
73
+ regexp_parser (~> 1.5)
74
+ xpath (~> 3.2)
75
+ childprocess (3.0.0)
29
76
  concurrent-ruby (1.1.7)
30
77
  crass (1.0.6)
78
+ database_cleaner (1.8.5)
79
+ database_cleaner-active_record (1.8.0)
80
+ activerecord
81
+ database_cleaner (~> 1.8.0)
31
82
  diff-lcs (1.4.4)
83
+ docile (1.3.2)
32
84
  erubi (1.9.0)
85
+ globalid (0.4.2)
86
+ activesupport (>= 4.2.0)
33
87
  i18n (1.8.5)
34
88
  concurrent-ruby (~> 1.0)
35
89
  loofah (2.7.0)
36
90
  crass (~> 1.0.2)
37
91
  nokogiri (>= 1.5.9)
92
+ mail (2.7.1)
93
+ mini_mime (>= 0.1.1)
94
+ marcel (0.3.3)
95
+ mimemagic (~> 0.3.2)
38
96
  method_source (1.0.0)
97
+ mimemagic (0.3.5)
98
+ mini_mime (1.0.2)
39
99
  mini_portile2 (2.4.0)
40
100
  minitest (5.14.2)
101
+ nio4r (2.5.4)
41
102
  nokogiri (1.10.10)
42
103
  mini_portile2 (~> 2.4.0)
104
+ public_suffix (4.0.6)
105
+ puma (4.3.6)
106
+ nio4r (~> 2.0)
43
107
  rack (2.2.3)
44
108
  rack-test (1.1.0)
45
109
  rack (>= 1.0, < 3)
110
+ rails (6.0.3.4)
111
+ actioncable (= 6.0.3.4)
112
+ actionmailbox (= 6.0.3.4)
113
+ actionmailer (= 6.0.3.4)
114
+ actionpack (= 6.0.3.4)
115
+ actiontext (= 6.0.3.4)
116
+ actionview (= 6.0.3.4)
117
+ activejob (= 6.0.3.4)
118
+ activemodel (= 6.0.3.4)
119
+ activerecord (= 6.0.3.4)
120
+ activestorage (= 6.0.3.4)
121
+ activesupport (= 6.0.3.4)
122
+ bundler (>= 1.3.0)
123
+ railties (= 6.0.3.4)
124
+ sprockets-rails (>= 2.0.0)
125
+ rails-controller-testing (1.0.5)
126
+ actionpack (>= 5.0.1.rc1)
127
+ actionview (>= 5.0.1.rc1)
128
+ activesupport (>= 5.0.1.rc1)
46
129
  rails-dom-testing (2.0.3)
47
130
  activesupport (>= 4.2.0)
48
131
  nokogiri (>= 1.6)
49
- rails-dummy (0.1.0)
50
- railties
51
132
  rails-html-sanitizer (1.3.0)
52
133
  loofah (~> 2.3)
53
134
  railties (6.0.3.4)
@@ -57,6 +138,7 @@ GEM
57
138
  rake (>= 0.8.7)
58
139
  thor (>= 0.20.3, < 2.0)
59
140
  rake (13.0.1)
141
+ regexp_parser (1.8.2)
60
142
  rspec-core (3.9.3)
61
143
  rspec-support (~> 3.9.3)
62
144
  rspec-expectations (3.9.2)
@@ -74,11 +156,36 @@ GEM
74
156
  rspec-mocks (~> 3.9)
75
157
  rspec-support (~> 3.9)
76
158
  rspec-support (3.9.3)
159
+ rubyzip (2.3.0)
160
+ selenium-webdriver (3.142.7)
161
+ childprocess (>= 0.5, < 4.0)
162
+ rubyzip (>= 1.2.2)
163
+ simplecov (0.19.0)
164
+ docile (~> 1.1)
165
+ simplecov-html (~> 0.11)
166
+ simplecov-html (0.12.2)
167
+ simplecov-lcov (0.8.0)
168
+ sprockets (4.0.2)
169
+ concurrent-ruby (~> 1.0)
170
+ rack (> 1, < 3)
171
+ sprockets-rails (3.2.2)
172
+ actionpack (>= 4.0)
173
+ activesupport (>= 4.0)
174
+ sprockets (>= 3.0.0)
77
175
  sqlite3 (1.4.2)
78
176
  thor (1.0.1)
79
177
  thread_safe (0.3.6)
80
178
  tzinfo (1.2.7)
81
179
  thread_safe (~> 0.1)
180
+ webdrivers (4.4.1)
181
+ nokogiri (~> 1.6)
182
+ rubyzip (>= 1.3.0)
183
+ selenium-webdriver (>= 3.0, < 4.0)
184
+ websocket-driver (0.7.3)
185
+ websocket-extensions (>= 0.1.0)
186
+ websocket-extensions (0.1.5)
187
+ xpath (3.2.0)
188
+ nokogiri (~> 1.8)
82
189
  zeitwerk (2.4.0)
83
190
 
84
191
  PLATFORMS
@@ -87,10 +194,17 @@ PLATFORMS
87
194
  DEPENDENCIES
88
195
  abyme!
89
196
  bundler (~> 2.0)
90
- rails-dummy
197
+ capybara
198
+ database_cleaner-active_record
199
+ puma
200
+ rails
201
+ rails-controller-testing
91
202
  rake (~> 13.0)
92
203
  rspec-rails
204
+ simplecov
205
+ simplecov-lcov
93
206
  sqlite3
207
+ webdrivers
94
208
 
95
209
  BUNDLED WITH
96
210
  2.1.4
data/README.md CHANGED
@@ -2,15 +2,23 @@
2
2
 
3
3
  abyme is a modern take on handling dynamic nested forms in Rails 6+ using StimulusJS.
4
4
 
5
+ [![Gem Version](https://badge.fury.io/rb/abyme.svg)](https://badge.fury.io/rb/abyme)
6
+ ![build](https://github.com/bear-in-mind/abyme/workflows/build/badge.svg)
7
+ [![Maintainability](https://api.codeclimate.com/v1/badges/f591a9e00f7cf5188ad5/maintainability)](https://codeclimate.com/github/bear-in-mind/abyme/maintainability)
8
+ [![Coverage Status](https://coveralls.io/repos/github/bear-in-mind/abyme/badge.svg)](https://coveralls.io/github/bear-in-mind/abyme?branch=master)
9
+
5
10
  ## Disclaimer
6
- This project is still a work in progress and subject to change. We encourage not to use it in production code just yet.
11
+ This project is still a work in progress and subject to change. We would advise not to use it in production code just yet.
7
12
 
8
13
  Any enhancement proposition or bug report welcome !
9
14
 
10
- General remarks :
11
- * A demo app will soon be online.
12
- * For now, the gem is tested through our demo app. Specific autonomous tests will be transfered/written in the following days.
13
- * Help is very much wanted on the Events part of the gem (see bottom of this documentation)
15
+ ## Demo app
16
+
17
+ ![Demo preview](https://res.cloudinary.com/aux-belles-autos/image/upload/v1603040053/abyme-preview.gif)
18
+
19
+ Check out our demo app here : https://abyme-demo.herokuapp.com/
20
+
21
+ Source code is right here : https://github.com/bear-in-mind/abyme_demo
14
22
 
15
23
  ## Installation
16
24
 
@@ -271,7 +279,6 @@ As you may have seen above, you can also pass a block to the method to give it w
271
279
  <% end %>
272
280
  ```
273
281
 
274
-
275
282
  #### #abymize(:association, form_object)
276
283
  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`.
277
284
  * `partial:` : allows you to indicate a custom partial path for both `records` and `new_records`
data/Rakefile CHANGED
@@ -1,15 +1,31 @@
1
- require "bundler/gem_tasks"
1
+ # require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
- require 'rails/dummy/tasks'
3
+ # require 'rails/dummy/tasks'
4
4
 
5
5
  RSpec::Core::RakeTask.new(:spec)
6
6
  task :default => :spec
7
7
 
8
- APP_RAKEFILE = File.expand_path("spec/dummy/Rakefile", __dir__)
9
- load 'rails/tasks/engine.rake'
10
- load 'rails/tasks/statistics.rake'
8
+ # APP_RAKEFILE = File.expand_path("spec/dummy/Rakefile", __dir__)
9
+ # load 'rails/tasks/engine.rake'
10
+ # load 'rails/tasks/statistics.rake'
11
11
 
12
- Bundler::GemHelper.install_tasks
12
+ # Bundler::GemHelper.install_tasks
13
+
14
+ # begin
15
+ # require 'bundler/setup'
16
+ # rescue LoadError
17
+ # puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
18
+ # end
19
+
20
+ # require 'rdoc/task'
21
+
22
+ # RDoc::Task.new(:rdoc) do |rdoc|
23
+ # rdoc.rdoc_dir = 'rdoc'
24
+ # rdoc.title = 'Abyme'
25
+ # rdoc.options << '--line-numbers'
26
+ # rdoc.rdoc_files.include('README.md')
27
+ # rdoc.rdoc_files.include('lib/**/*.rb')
28
+ # end
13
29
 
14
30
  begin
15
31
  require 'bundler/setup'
@@ -21,8 +37,15 @@ require 'rdoc/task'
21
37
 
22
38
  RDoc::Task.new(:rdoc) do |rdoc|
23
39
  rdoc.rdoc_dir = 'rdoc'
24
- rdoc.title = 'Abyme'
40
+ rdoc.title = 'SampleEngineWithRspecAndCucumber'
25
41
  rdoc.options << '--line-numbers'
26
- rdoc.rdoc_files.include('README.md')
42
+ rdoc.rdoc_files.include('README.rdoc')
27
43
  rdoc.rdoc_files.include('lib/**/*.rb')
28
44
  end
45
+
46
+ APP_RAKEFILE = File.expand_path("spec/dummy/Rakefile", __dir__)
47
+
48
+ load 'rails/tasks/engine.rake'
49
+ load 'rails/tasks/statistics.rake'
50
+
51
+ Bundler::GemHelper.install_tasks
@@ -28,7 +28,17 @@ Gem::Specification.new do |spec|
28
28
 
29
29
  spec.add_development_dependency "bundler", "~> 2.0"
30
30
  spec.add_development_dependency "rake", "~> 13.0"
31
+ # Tests
31
32
  spec.add_development_dependency "rspec-rails"
32
- spec.add_development_dependency "rails-dummy"
33
+ spec.add_development_dependency 'rails-controller-testing'
34
+ spec.add_development_dependency 'database_cleaner-active_record'
35
+ spec.add_development_dependency 'capybara'
36
+ spec.add_development_dependency 'webdrivers'
37
+
38
+ # Dummy app
33
39
  spec.add_development_dependency "sqlite3"
40
+ spec.add_development_dependency 'rails'
41
+ spec.add_development_dependency 'puma'
42
+ spec.add_development_dependency 'simplecov'
43
+ spec.add_development_dependency 'simplecov-lcov'
34
44
  end
@@ -4,24 +4,53 @@ export default class extends Controller {
4
4
  static targets = ['template', 'associations', 'fields', 'newFields'];
5
5
 
6
6
  connect() {
7
+ console.log("Abyme Connected")
8
+
7
9
  if (this.count) {
8
- this.addDefaultAssociations();
10
+ // If data-count is present,
11
+ // add n default fields on page load
12
+
13
+ this.add_default_associations();
9
14
  }
10
15
  }
11
16
 
17
+ // return the value of the data-count attribute
18
+
12
19
  get count() {
13
20
  return this.element.dataset.minCount || 0;
14
21
  }
15
22
 
23
+ // return the value of the data-position attribute
24
+ // if there is no position specified set end as default
25
+
16
26
  get position() {
17
27
  return this.associationsTarget.dataset.abymePosition === 'end' ? 'beforeend' : 'afterbegin';
18
28
  }
19
29
 
30
+ // ADD_ASSOCIATION
31
+
32
+ // this function is call whenever a click occurs
33
+ // on the element with the click->abyme#add_association
34
+ // <button> element by default
35
+
36
+ // if a data-count is present the add_association
37
+ // will be call without an event so we have to check
38
+ // this case
39
+
40
+ // check for limit reached
41
+ // dispatch an event if the limit is reached
42
+
43
+ // - call the function build_html that take care
44
+ // for building the correct html to be inserted in the DOM
45
+ // - dispatch an event before insert
46
+ // - insert html into the dom
47
+ // - dispatch an event after insert
48
+
20
49
  add_association(event) {
21
50
  if (event) {
22
51
  event.preventDefault();
23
52
  }
24
- // check for limit reached
53
+
25
54
  if (this.element.dataset.limit && this.limit_check()) {
26
55
  this.create_event('limit-reached')
27
56
  return false
@@ -33,8 +62,21 @@ export default class extends Controller {
33
62
  this.create_event('after-add');
34
63
  }
35
64
 
65
+ // REMOVE_ASSOCIATION
66
+
67
+ // this function is call whenever a click occurs
68
+ // on the element with the click->abyme#remove_association
69
+ // <button> element by default
70
+
71
+ // - call the function mark_for_destroy that takes care
72
+ // of marking the element for destruction and hiding it
73
+ // - dispatch an event before mark & hide
74
+ // - mark for descrution + hide the element
75
+ // - dispatch an event after mark and hide
76
+
36
77
  remove_association(event) {
37
78
  event.preventDefault();
79
+
38
80
  this.create_event('before-remove');
39
81
  this.mark_for_destroy(event);
40
82
  this.create_event('after-remove');
@@ -42,6 +84,12 @@ export default class extends Controller {
42
84
 
43
85
  // LIFECYCLE EVENTS RELATED
44
86
 
87
+ // CREATE_EVENT
88
+
89
+ // take a stage (String) => before-add, after-add...
90
+ // create a new custom event
91
+ // and dispatch at at the controller level
92
+
45
93
  create_event(stage, html = null) {
46
94
  const event = new CustomEvent(`abyme:${stage}`, { detail: {controller: this, content: html} });
47
95
  this.element.dispatchEvent(event);
@@ -69,9 +117,14 @@ export default class extends Controller {
69
117
  abymeAfterRemove(event) {
70
118
  }
71
119
 
72
- // UTILITIES
120
+ // BUILD HTML
121
+
122
+ // takes the html template and substitutes the sub-string
123
+ // NEW_RECORD for a generated timestamp
124
+ // then if there is a sub template in the html (multiple nested level)
125
+ // set all the sub timestamps back as NEW_RECORD
126
+ // finally returns the html
73
127
 
74
- // build html
75
128
  build_html() {
76
129
  let html = this.templateTarget.innerHTML.replace(
77
130
  /NEW_RECORD/g,
@@ -88,8 +141,15 @@ export default class extends Controller {
88
141
 
89
142
  return html;
90
143
  }
91
-
92
- // mark association for destroy
144
+
145
+ // MARK_FOR_DESTROY
146
+
147
+ // mark association for destruction
148
+ // get the closest abyme--fields from the remove_association button
149
+ // set the _destroy input value as 1
150
+ // hide the element
151
+ // add the class of abyme--marked-for-destroy to the element
152
+
93
153
  mark_for_destroy(event) {
94
154
  let item = event.target.closest('.abyme--fields');
95
155
  item.querySelector("input[name*='_destroy']").value = 1;
@@ -97,20 +157,29 @@ export default class extends Controller {
97
157
  item.classList.add('abyme--marked-for-destroy')
98
158
  }
99
159
 
100
- // check if associations limit is reached
160
+
161
+ // LIMIT_CHECK
162
+
163
+ // Check if associations limit is reached
164
+ // based on newFieldsTargets only
165
+ // persisted fields are ignored
166
+
101
167
  limit_check() {
102
168
  return (this.newFieldsTargets
103
169
  .filter(item => !item.classList.contains('abyme--marked-for-destroy'))).length
104
170
  >= parseInt(this.element.dataset.limit)
105
171
  }
106
172
 
107
- // Add default blank associations at page load
108
- async addDefaultAssociations() {
173
+ // ADD_DEFAULT_ASSOCIATION
174
+
175
+ // Add n default blank associations at page load
176
+ // call sleep function to ensure uniqueness of timestamp
177
+
178
+ async add_default_associations() {
109
179
  let i = 0
110
180
  while (i < this.count) {
111
181
  this.add_association()
112
182
  i++
113
- // Sleep function to ensure uniqueness of timestamp
114
183
  await this.sleep(1);
115
184
  }
116
185
  }
@@ -2,6 +2,12 @@ module Abyme
2
2
  class AbymeBuilder < ActionView::Base
3
3
  include ActionView
4
4
 
5
+ # If a block is given to the #abymize helper
6
+ # it will instanciate a new AbymeBuilder
7
+ # and pass to it the association name (Symbol)
8
+ # the form object, lookup_context optionaly a partial path
9
+ # then yield itself to the block
10
+
5
11
  def initialize(association:, form:, lookup_context:, partial:, &block)
6
12
  @association = association
7
13
  @form = form
@@ -9,12 +15,22 @@ module Abyme
9
15
  @partial = partial
10
16
  yield(self) if block_given?
11
17
  end
18
+
19
+ # RECORDS
20
+
21
+ # calls the #persisted_records_for helper method
22
+ # passing association, form and options to it
12
23
 
13
24
  def records(options = {})
14
25
  persisted_records_for(@association, @form, options) do |fields_for_association|
15
26
  render_association_partial(fields_for_association, options)
16
27
  end
17
28
  end
29
+
30
+ # NEW_RECORDS
31
+
32
+ # calls the #new_records_for helper method
33
+ # passing association, form and options to it
18
34
 
19
35
  def new_records(options = {}, &block)
20
36
  new_records_for(@association, @form, options) do |fields_for_association|
@@ -1,9 +1,11 @@
1
+ # :nocov:
1
2
  module Abyme
2
3
  module VERSION
3
4
  MAJOR = 0
4
5
  MINOR = 2
5
- PATCH = 3
6
+ PATCH = 4
6
7
 
7
8
  STRING = [MAJOR, MINOR, PATCH].join(".")
8
9
  end
9
10
  end
11
+ # :nocov:
@@ -3,6 +3,41 @@ require_relative "abyme_builder"
3
3
  module Abyme
4
4
  module ViewHelpers
5
5
 
6
+ # ABYMIZE
7
+
8
+ # this helper will generate the top level wrapper markup
9
+ # with the bare minimum html attributes (data-controller="abyme")
10
+ # it takes the Symbolized name of the association (plural) and the form object
11
+ # then you can pass a hash of options (see exemple below)
12
+ # if no block given it will generate a default markup for
13
+ # #persisted_records_for, #new_records_for & #add_association methods
14
+ # if a block is given it will instanciate a new AbymeBuilder and pass to it
15
+ # the name of the association, the form object and the lookup_context
16
+
17
+ # == Options
18
+
19
+ # - limit (Integer)
20
+ # you can set a limit for the new association fields to display
21
+
22
+ # - min_count (Integer)
23
+ # set the default number of blank fields to display
24
+
25
+ # - partial (String)
26
+ # to customize the partial path by default #abymize will expect
27
+ # a partial to bbe present in views/abyme
28
+
29
+ # - Exemple
30
+
31
+ # <%= abymize(:tasks, f, limit: 3) do |abyme| %>
32
+ # ...
33
+ # <% end %>
34
+
35
+ # will output this html
36
+
37
+ # <div data-controller="abyme" data-limit="3" id="abyme--tasks">
38
+ # ...
39
+ # </div>
40
+
6
41
  def abymize(association, form, options = {}, &block)
7
42
  content_tag(:div, data: { controller: 'abyme', limit: options[:limit], min_count: options[:min_count] }, id: "abyme--#{association}") do
8
43
  if block_given?
@@ -19,6 +54,47 @@ module Abyme
19
54
  end
20
55
  end
21
56
 
57
+ # NEW_RECORDS_FOR
58
+
59
+ # this helper is call by the AbymeBuilder #new_records instance method
60
+ # it generates the html markup for new associations fields
61
+ # it takes the association (Symbol) and the form object
62
+ # then a hash of options.
63
+
64
+ # - Exemple
65
+ # <%= abymize(:tasks, f) do |abyme| %>
66
+ # <%= abyme.new_records %>
67
+ # ...
68
+ # <% end %>
69
+
70
+ # will output this html
71
+
72
+ # <div data-target="abyme.associations" data-association="tasks" data-abyme-position="end">
73
+ # <template class="abyme--task_template" data-target="abyme.template">
74
+ # <div data-target="abyme.fields abyme.newFields" class="abyme--fields task-fields">
75
+ # ... partial html goes here
76
+ # </div>
77
+ # </template>
78
+ # ... new rendered fields goes here
79
+ # </div>
80
+
81
+ # == Options
82
+ # - position (:start, :end)
83
+ # allows you to specify whether new fields added dynamically
84
+ # should go at the top or at the bottom
85
+ # :end is the default value
86
+
87
+ # - partial (String)
88
+ # to customize the partial path by default #abymize will expect
89
+ # a partial to bbe present in views/abyme
90
+
91
+ # - fields_html (Hash)
92
+ # allows you to pass any html attributes to each fields wrapper
93
+
94
+ # - wrapper_html (Hash)
95
+ # allows you to pass any html attributes to the the html element
96
+ # wrapping all the fields
97
+
22
98
  def new_records_for(association, form, options = {}, &block)
23
99
  options[:wrapper_html] ||= {}
24
100
 
@@ -43,6 +119,47 @@ module Abyme
43
119
  end
44
120
  end
45
121
  end
122
+
123
+ # PERSISTED_RECORDS_FOR
124
+
125
+ # this helper is call by the AbymeBuilder #records instance method
126
+ # it generates the html markup for persisted associations fields
127
+ # it takes the association (Symbol) and the form object
128
+ # then a hash of options.
129
+
130
+ # - Exemple
131
+ # <%= abymize(:tasks, f) do |abyme| %>
132
+ # <%= abyme.records %>
133
+ # ...
134
+ # <% end %>
135
+
136
+ # will output this html
137
+
138
+ # <div>
139
+ # <div data-target="abyme.fields" class="abyme--fields task-fields">
140
+ # ... partial html goes here
141
+ # </div>
142
+ # </div>
143
+
144
+ # == Options
145
+ # - collection (Active Record Collection)
146
+ # allows you to pass an AR collection
147
+ # by default every associated records will be present
148
+
149
+ # - order (Hash)
150
+ # allows you to order the collection
151
+ # ex: order: { created_at: :desc }
152
+
153
+ # - partial (String)
154
+ # to customize the partial path by default #abymize will expect
155
+ # a partial to bbe present in views/abyme
156
+
157
+ # - fields_html (Hash)
158
+ # allows you to pass any html attributes to each fields wrapper
159
+
160
+ # - wrapper_html (Hash)
161
+ # allows you to pass any html attributes to the the html element
162
+ # wrapping all the fields
46
163
 
47
164
  def persisted_records_for(association, form, options = {})
48
165
  records = options[:collection] || form.object.send(association)
@@ -51,7 +168,9 @@ module Abyme
51
168
 
52
169
  if options[:order].present?
53
170
  records = records.order(options[:order])
54
- # Get invalid records
171
+ # by calling the order method on the AR collection
172
+ # we get rid of the records with errors
173
+ # so we have to get them back with the 2 lines below
55
174
  invalids = form.object.send(association).reject(&:persisted?)
56
175
  records = records.to_a.concat(invalids) if invalids.any?
57
176
  end
@@ -64,23 +183,46 @@ module Abyme
64
183
  end
65
184
  end
66
185
  end
186
+
187
+ # ADD & REMOVE ASSOCIATION
188
+
189
+ # these helpers will call the #create_button method
190
+ # to generate the buttons for add and remove associations
191
+ # with the right action and a default content text for each button
67
192
 
68
193
  def add_association(options = {}, &block)
69
194
  action = 'click->abyme#add_association'
195
+ options[:content] ||= 'Add Association'
70
196
  create_button(action, options, &block)
71
197
  end
72
198
 
73
199
  def remove_association(options = {}, &block)
74
200
  action = 'click->abyme#remove_association'
201
+ options[:content] ||= 'Remove Association'
75
202
  create_button(action, options, &block)
76
203
  end
77
204
 
78
205
  private
206
+
207
+ # CREATE_BUTTON
208
+
209
+ # this helper is call by either add_association or remove_association
210
+ # by default it will generate a button tag.
211
+
212
+ # == Options
213
+ # - content (String)
214
+ # allows you to set the button text
215
+
216
+ # - tag (Symbol)
217
+ # allows you to set the html tag of your choosing
218
+ # default if :button
219
+
220
+ # - html (Hash)
221
+ # to pass any html attributes you want.
79
222
 
80
223
  def create_button(action, options, &block)
81
224
  options[:html] ||= {}
82
225
  options[:tag] ||= :button
83
- options[:content] ||= 'Add Association'
84
226
 
85
227
  if block_given?
86
228
  content_tag(options[:tag], { data: { action: action } }.merge(options[:html])) do
@@ -91,6 +233,11 @@ module Abyme
91
233
  end
92
234
  end
93
235
 
236
+ # BASIC_FIELDS_MARKUP
237
+
238
+ # generates the default html classes for fields
239
+ # add optional classes if present
240
+
94
241
  def basic_fields_markup(html, association = nil)
95
242
  if html && html[:class]
96
243
  html[:class] = "abyme--fields #{association.to_s.singularize}-fields #{html[:class]}"
@@ -101,17 +248,23 @@ module Abyme
101
248
  html
102
249
  end
103
250
 
251
+ # BUILD_ATTRIBUTES
252
+
253
+ # add optionals html attributes without overwritting
254
+ # the default or already present ones
255
+
104
256
  def build_attributes(default, attr)
105
- # ADD NEW DATA ATTRIBUTES VALUES TO THE DEFAULT ONES (ONLY VALUES)
257
+ # Add new data attributes values to the default ones (only values)
106
258
  if attr[:data]
107
259
  default[:data].each do |key, value|
108
260
  default[:data][key] = "#{value} #{attr[:data][key]}".strip
109
261
  end
110
- # ADD NEW DATA ATTRIBUTES (KEYS & VALUES)
262
+ # Add new data attributes (keys & values)
111
263
  default[:data] = default[:data].merge(attr[:data].reject { |key, _| default[:data][key] })
112
264
  end
113
- # MERGE THE DATA ATTRIBUTES TO THE HASH OF HTML ATTRIBUTES
265
+ # Merge data attributes to the hash ok html attributes
114
266
  default.merge(attr.reject { |key, _| key == :data })
115
267
  end
268
+
116
269
  end
117
270
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: abyme
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Romain Sanson
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2020-10-15 00:00:00.000000000 Z
12
+ date: 2020-10-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -54,7 +54,49 @@ dependencies:
54
54
  - !ruby/object:Gem::Version
55
55
  version: '0'
56
56
  - !ruby/object:Gem::Dependency
57
- name: rails-dummy
57
+ name: rails-controller-testing
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: database_cleaner-active_record
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: capybara
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: webdrivers
58
100
  requirement: !ruby/object:Gem::Requirement
59
101
  requirements:
60
102
  - - ">="
@@ -81,6 +123,62 @@ dependencies:
81
123
  - - ">="
82
124
  - !ruby/object:Gem::Version
83
125
  version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: rails
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ - !ruby/object:Gem::Dependency
141
+ name: puma
142
+ requirement: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ type: :development
148
+ prerelease: false
149
+ version_requirements: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ - !ruby/object:Gem::Dependency
155
+ name: simplecov
156
+ requirement: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ type: :development
162
+ prerelease: false
163
+ version_requirements: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ - !ruby/object:Gem::Dependency
169
+ name: simplecov-lcov
170
+ requirement: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ version: '0'
175
+ type: :development
176
+ prerelease: false
177
+ version_requirements: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - ">="
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
84
182
  description:
85
183
  email:
86
184
  - louis.sommer@hey.com
@@ -89,9 +187,10 @@ extensions: []
89
187
  extra_rdoc_files: []
90
188
  files:
91
189
  - ".DS_Store"
190
+ - ".github/workflows/build.yml"
92
191
  - ".gitignore"
93
192
  - ".rspec"
94
- - ".travis.yml"
193
+ - ".simplecov"
95
194
  - Gemfile
96
195
  - Gemfile.lock
97
196
  - LICENSE.txt
@@ -110,9 +209,6 @@ files:
110
209
  - lib/abyme/model.rb
111
210
  - lib/abyme/version.rb
112
211
  - lib/abyme/view_helpers.rb
113
- - lib/generators/.DS_Store
114
- - lib/generators/abyme/install_generator.rb
115
- - lib/generators/abyme/templates/abyme_controller.js
116
212
  - node_modules/.yarn-integrity
117
213
  - package.json
118
214
  - yarn-error.log
@@ -1,7 +0,0 @@
1
- ---
2
- sudo: false
3
- language: ruby
4
- cache: bundler
5
- rvm:
6
- - 2.6.3
7
- before_install: gem install bundler -v 2.0.2
Binary file
@@ -1,25 +0,0 @@
1
- # require 'rails/generators'
2
- # require 'json'
3
-
4
- # module Abyme
5
- # module Generators
6
- # class InstallGenerator < Rails::Generators::Base
7
- # source_root File.expand_path("templates", __dir__)
8
-
9
- # def setup
10
- # # Creating stimulus abyme_controller.js file
11
- # # ==========================================
12
- # template "abyme_controller.js", "app/javascript/controllers/abyme_controller.js"
13
- # add_stimulus
14
- # end
15
-
16
- # def add_stimulus
17
- # # Checking if stimulus is present in package.json => yarn add if it's not
18
- # # =======================================================================
19
- # package = JSON.parse(File.open('package.json').read)
20
- # exec('yarn add stimulus') if !package['dependencies'].keys.include?('stimulus')
21
- # end
22
-
23
- # end
24
- # end
25
- # end
@@ -1,17 +0,0 @@
1
- import { Controller } from 'stimulus';
2
-
3
- export default class extends Controller {
4
- connect() {
5
- console.log('Abyme Controller Connected');
6
- }
7
-
8
- add_association(event) {
9
- event.preventDefault();
10
- console.log('Add Association');
11
- }
12
-
13
- remove_association(event) {
14
- event.preventDefault();
15
- console.log('Remove Association');
16
- }
17
- }