bp3-formtastic 0.1.1 → 0.2.0

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: badca2d2bd57d4a8e74bf01fb63699e98b556e9bde9bacf841493003085218a5
4
- data.tar.gz: 71e33e1a799e9b1a4329f1e8470056dfd75ee3c6a816f703f0559487de8063ff
3
+ metadata.gz: e1603f265734ec82fa61ee1d03f6098acbd898cc1caf6d5362340dde619f36ed
4
+ data.tar.gz: dba9f2dd5248e1426cb065d2b76c8a187b6c2c8e6005143725eaa6d1d09ec896
5
5
  SHA512:
6
- metadata.gz: c2c5fe8aa33f2389357a510b7fc50383924369cf27d7177391bd389fbb6c5b54a56a44cec8109536680941d658c98c948bd22a14bfab11ab5346e6b57ac8e607
7
- data.tar.gz: ed2e4a9f370d0dde477a0e72c7ce8b660da795b9fcc00fea36ce3865d276875169b0f05e4d54544fe0dce024cd515311b6ffaaf77e1ffa0dfb7e01f3ab8041cc
6
+ metadata.gz: 78a3bc4fd2dd535e89e5fff5eed8522fecc1572a76016ad1e4224f18c2010c6afde894f6133bc9dc09467c06def15dd5b746790ddb3fa0ab3d885a0664f7305c
7
+ data.tar.gz: b4b4871c0d0f222434190b62961db96a58ad694dde513ca0602e9caaa33f780770c865f170ba97cd9e3d08f71e187e12289447ffa8a7f6358adf13cb3e7ada47
data/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.2.0] - 2024-08-20
4
+
5
+ - Create form builders
6
+ - Update #input_wrapping to use new form builders
7
+ - Allow nil input_control_class_name
8
+
9
+ ## [0.1.2] - 2024-07-01
10
+
11
+ - Check for builder.id
12
+ - Tweaks
13
+
3
14
  ## [0.1.1] - 2024-05-31
4
15
 
5
16
  - Tweaks and documentation
data/Gemfile.lock CHANGED
@@ -1,17 +1,19 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bp3-formtastic (0.1.1)
4
+ bp3-formtastic (0.2.0)
5
5
  actionpack (>= 7.1.2, < 8)
6
+ actionview (>= 7.1.2, < 8)
6
7
  activesupport (>= 7.1.2, < 8)
7
8
  formtastic (~> 5.0)
9
+ railties (>= 7.1.2, < 8)
8
10
 
9
11
  GEM
10
12
  remote: https://rubygems.org/
11
13
  specs:
12
- actionpack (7.1.3)
13
- actionview (= 7.1.3)
14
- activesupport (= 7.1.3)
14
+ actionpack (7.1.3.4)
15
+ actionview (= 7.1.3.4)
16
+ activesupport (= 7.1.3.4)
15
17
  nokogiri (>= 1.8.5)
16
18
  racc
17
19
  rack (>= 2.2.4)
@@ -19,13 +21,13 @@ GEM
19
21
  rack-test (>= 0.6.3)
20
22
  rails-dom-testing (~> 2.2)
21
23
  rails-html-sanitizer (~> 1.6)
22
- actionview (7.1.3)
23
- activesupport (= 7.1.3)
24
+ actionview (7.1.3.4)
25
+ activesupport (= 7.1.3.4)
24
26
  builder (~> 3.1)
25
27
  erubi (~> 1.11)
26
28
  rails-dom-testing (~> 2.2)
27
29
  rails-html-sanitizer (~> 1.6)
28
- activesupport (7.1.3)
30
+ activesupport (7.1.3.4)
29
31
  base64
30
32
  bigdecimal
31
33
  concurrent-ruby (~> 1.0, >= 1.0.2)
@@ -37,39 +39,47 @@ GEM
37
39
  tzinfo (~> 2.0)
38
40
  ast (2.4.2)
39
41
  base64 (0.2.0)
40
- bigdecimal (3.1.6)
41
- builder (3.2.4)
42
+ bigdecimal (3.1.8)
43
+ builder (3.3.0)
42
44
  byebug (11.1.3)
43
- concurrent-ruby (1.2.3)
45
+ concurrent-ruby (1.3.3)
44
46
  connection_pool (2.4.1)
45
47
  crass (1.0.6)
46
- diff-lcs (1.5.0)
47
- drb (2.2.0)
48
- ruby2_keywords
49
- erubi (1.12.0)
48
+ diff-lcs (1.5.1)
49
+ drb (2.2.1)
50
+ erubi (1.13.0)
50
51
  formtastic (5.0.0)
51
52
  actionpack (>= 6.0.0)
52
- i18n (1.14.1)
53
+ i18n (1.14.5)
53
54
  concurrent-ruby (~> 1.0)
54
- json (2.7.1)
55
+ io-console (0.7.2)
56
+ irb (1.14.0)
57
+ rdoc (>= 4.0.0)
58
+ reline (>= 0.4.2)
59
+ json (2.7.2)
55
60
  language_server-protocol (3.17.0.3)
56
61
  loofah (2.22.0)
57
62
  crass (~> 1.0.2)
58
63
  nokogiri (>= 1.12.0)
59
- minitest (5.21.2)
64
+ minitest (5.24.1)
60
65
  mutex_m (0.2.0)
61
- nokogiri (1.16.0-x86_64-darwin)
66
+ nokogiri (1.16.6-x86_64-darwin)
62
67
  racc (~> 1.4)
63
- parallel (1.24.0)
64
- parser (3.3.0.4)
68
+ parallel (1.25.1)
69
+ parser (3.3.3.0)
65
70
  ast (~> 2.4.1)
66
71
  racc
67
- racc (1.7.3)
68
- rack (3.0.8)
72
+ psych (5.1.2)
73
+ stringio
74
+ racc (1.8.0)
75
+ rack (3.1.4)
69
76
  rack-session (2.0.0)
70
77
  rack (>= 3.0.0)
71
78
  rack-test (2.1.0)
72
79
  rack (>= 1.3)
80
+ rackup (2.1.0)
81
+ rack (>= 3)
82
+ webrick (~> 1.8)
73
83
  rails-dom-testing (2.2.0)
74
84
  activesupport (>= 5.0.0)
75
85
  minitest
@@ -77,24 +87,37 @@ GEM
77
87
  rails-html-sanitizer (1.6.0)
78
88
  loofah (~> 2.21)
79
89
  nokogiri (~> 1.14)
90
+ railties (7.1.3.4)
91
+ actionpack (= 7.1.3.4)
92
+ activesupport (= 7.1.3.4)
93
+ irb
94
+ rackup (>= 1.0.0)
95
+ rake (>= 12.2)
96
+ thor (~> 1.0, >= 1.2.2)
97
+ zeitwerk (~> 2.6)
80
98
  rainbow (3.1.1)
81
- rake (13.1.0)
82
- regexp_parser (2.9.0)
83
- rexml (3.2.6)
84
- rspec (3.12.0)
85
- rspec-core (~> 3.12.0)
86
- rspec-expectations (~> 3.12.0)
87
- rspec-mocks (~> 3.12.0)
88
- rspec-core (3.12.2)
89
- rspec-support (~> 3.12.0)
90
- rspec-expectations (3.12.3)
99
+ rake (13.2.1)
100
+ rdoc (6.7.0)
101
+ psych (>= 4.0.0)
102
+ regexp_parser (2.9.2)
103
+ reline (0.5.9)
104
+ io-console (~> 0.5)
105
+ rexml (3.3.1)
106
+ strscan
107
+ rspec (3.13.0)
108
+ rspec-core (~> 3.13.0)
109
+ rspec-expectations (~> 3.13.0)
110
+ rspec-mocks (~> 3.13.0)
111
+ rspec-core (3.13.0)
112
+ rspec-support (~> 3.13.0)
113
+ rspec-expectations (3.13.1)
91
114
  diff-lcs (>= 1.2.0, < 2.0)
92
- rspec-support (~> 3.12.0)
93
- rspec-mocks (3.12.6)
115
+ rspec-support (~> 3.13.0)
116
+ rspec-mocks (3.13.1)
94
117
  diff-lcs (>= 1.2.0, < 2.0)
95
- rspec-support (~> 3.12.0)
96
- rspec-support (3.12.1)
97
- rubocop (1.60.1)
118
+ rspec-support (~> 3.13.0)
119
+ rspec-support (3.13.1)
120
+ rubocop (1.64.1)
98
121
  json (~> 2.3)
99
122
  language_server-protocol (>= 3.17.0)
100
123
  parallel (~> 1.10)
@@ -102,26 +125,33 @@ GEM
102
125
  rainbow (>= 2.2.2, < 4.0)
103
126
  regexp_parser (>= 1.8, < 3.0)
104
127
  rexml (>= 3.2.5, < 4.0)
105
- rubocop-ast (>= 1.30.0, < 2.0)
128
+ rubocop-ast (>= 1.31.1, < 2.0)
106
129
  ruby-progressbar (~> 1.7)
107
130
  unicode-display_width (>= 2.4.0, < 3.0)
108
- rubocop-ast (1.30.0)
109
- parser (>= 3.2.1.0)
110
- rubocop-capybara (2.20.0)
111
- rubocop (~> 1.41)
112
- rubocop-factory_bot (2.25.1)
131
+ rubocop-ast (1.31.3)
132
+ parser (>= 3.3.1.0)
133
+ rubocop-capybara (2.21.0)
113
134
  rubocop (~> 1.41)
135
+ rubocop-factory_bot (2.26.1)
136
+ rubocop (~> 1.61)
114
137
  rubocop-rake (0.6.0)
115
138
  rubocop (~> 1.0)
116
- rubocop-rspec (2.26.1)
139
+ rubocop-rspec (2.31.0)
117
140
  rubocop (~> 1.40)
118
141
  rubocop-capybara (~> 2.17)
119
142
  rubocop-factory_bot (~> 2.22)
143
+ rubocop-rspec_rails (~> 2.28)
144
+ rubocop-rspec_rails (2.29.1)
145
+ rubocop (~> 1.61)
120
146
  ruby-progressbar (1.13.0)
121
- ruby2_keywords (0.0.5)
147
+ stringio (3.1.1)
148
+ strscan (3.1.0)
149
+ thor (1.3.1)
122
150
  tzinfo (2.0.6)
123
151
  concurrent-ruby (~> 1.0)
124
152
  unicode-display_width (2.5.0)
153
+ webrick (1.8.1)
154
+ zeitwerk (2.6.17)
125
155
 
126
156
  PLATFORMS
127
157
  x86_64-darwin-22
data/README.md CHANGED
@@ -4,7 +4,6 @@ bp3-formtastic adapts formtastic for BP3, the persuavis/black_phoebe_3
4
4
  multi-site multi-tenant rails application.
5
5
 
6
6
  ## Installation
7
-
8
7
  Add this line to your application's Gemfile:
9
8
 
10
9
  ```ruby
@@ -20,14 +19,23 @@ Or install it yourself as:
20
19
  $ gem install bp3-formtastic
21
20
 
22
21
  ## Usage
23
-
24
- In your application's `config/initializers/bp3-action_dispatch` initializer, specify the name of the class
22
+ In your application's `config/initializers/bp3-formtastic` initializer, specify the name of the class
25
23
  that controls whether to show a formtastic input control or not:
26
24
  ```ruby
27
25
  Bp3::Formtastic.input_control_class_name = 'Vizfact::Input'
28
26
  ```
29
- ## Development
30
27
 
28
+ In your application's formtastic configuration file (typically `config/initializers/formtastic`),
29
+ specify which form builder to use:
30
+ ```ruby
31
+ Rails.application.config.after_initialize do
32
+ Formtastic::Helpers::FormHelper.builder = Bp3::Formtastic::VizFormBuilder
33
+ end
34
+ ```
35
+ Specify `Bp3::Formtastice::VizFormBuilderWithCreate` if you want new `Bp3::Formtastic.input_control_class_name`
36
+ records to be added for each form input encountered on a form.
37
+
38
+ ## Development
31
39
  After checking out the repo, run `bin/setup` to install dependencies. Then, run
32
40
  `rake spec` to run the tests. You can also run `bin/console` for an interactive
33
41
  prompt that will allow you to experiment.
@@ -44,5 +52,4 @@ Run `rake` to run rspec tests and rubocop linting.
44
52
  A `.yardopts` file is provided to support yard documentation.
45
53
 
46
54
  ## License
47
-
48
55
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.authors = ['Wim den Braven']
9
9
  spec.email = ['wimdenbraven@persuavis.com']
10
10
 
11
- spec.summary = 'bp3-formtastic adapts formtastic for BP3 (persuavis/black_phoebe_3)..'
11
+ spec.summary = 'bp3-formtastic adapts formtastic for BP3 (persuavis/black_phoebe_3).'
12
12
  # spec.description = "TODO: Write a longer description or delete this line."
13
13
  spec.homepage = 'https://www.black-phoebe.com'
14
14
  spec.license = 'MIT'
@@ -32,8 +32,10 @@ Gem::Specification.new do |spec|
32
32
  spec.require_paths = ['lib']
33
33
 
34
34
  spec.add_dependency 'actionpack', ['>= 7.1.2', '< 8']
35
+ spec.add_dependency 'actionview', ['>= 7.1.2', '< 8']
35
36
  spec.add_dependency 'activesupport', ['>= 7.1.2', '< 8']
36
37
  spec.add_dependency 'formtastic', '~> 5.0'
38
+ spec.add_dependency 'railties', ['>= 7.1.2', '< 8']
37
39
 
38
40
  spec.add_development_dependency 'byebug'
39
41
  spec.add_development_dependency 'rake', '~> 13.0'
@@ -12,31 +12,16 @@ module Bp3
12
12
  EXCLUDED_COLUMNS = %w[rqid sqnr].freeze
13
13
  UUID_REGEX = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/
14
14
 
15
- # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
16
15
  # PrependInputs provides formtastic input overrides
17
16
  module PrependInputs
18
17
  def input_wrapping(&)
19
18
  return super if column.nil? # e.g. when called for individual details fields
19
+ return super if Bp3::Formtastic.input_control_class.nil?
20
+ return super unless builder.respond_to?(:viz)
20
21
  return nil if column.name.in?(EXCLUDED_COLUMNS)
21
22
 
22
- # url = template.controller.request.url
23
- site = template.controller.send(:current_site)
24
- # tenant = template.controller.send(:current_tenant)
25
- # workspace = template.controller.send(:current_workspace)
26
- controller = template.controller.class.name
27
- action = template.controller.action_name
28
- builder.id.gsub(/_#{UUID_REGEX}/, '')
29
- # puts "input_wrapping s:#{site.id} c:#{controller} a:#{action} " \
30
- # "e:#{method} n:#{field_name} as:#{options[:as].inspect}"
31
-
32
- viz = input_control_class.where(sites_site: site,
33
- element_controller: controller,
34
- element_action: action,
35
- element_name: field_name)
36
- .or(input_control_class.where(sites_site: site,
37
- element_controller: controller,
38
- element_action: action,
39
- element_ident: dom_id)).first
23
+ builder.id&.gsub(/_#{UUID_REGEX}/, '')
24
+ viz = builder.viz(field_name, dom_id)
40
25
  return nil if viz.present? && !viz.show_element
41
26
 
42
27
  super
@@ -52,7 +37,6 @@ module Bp3
52
37
  "#{object_name}[#{input_name}]"
53
38
  end
54
39
  end
55
- # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
56
40
 
57
41
  module Base
58
42
  prepend PrependInputs
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Bp3
4
4
  module Formtastic
5
- VERSION = '0.1.1'
5
+ VERSION = '0.2.0'
6
6
  end
7
7
  end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support'
4
+ require 'action_view/helpers/form_options_helper'
5
+ require 'rails/engine'
6
+ require 'formtastic'
7
+
8
+ module Bp3
9
+ module Formtastic
10
+ class VizFormBuilder < ::Formtastic::FormBuilder
11
+ attr_reader :vizfacts
12
+
13
+ def initialize(...)
14
+ super
15
+ load_vizfacts
16
+ end
17
+
18
+ def input(method, options = {})
19
+ super
20
+ end
21
+
22
+ def viz(element_name, element_ident)
23
+ return if vizfacts.nil?
24
+
25
+ vizfacts.detect { |vf| vf.element_name == element_name || vf.element_ident == element_ident }
26
+ end
27
+
28
+ private
29
+
30
+ def vizfact_attrs(element_name, element_ident)
31
+ {
32
+ element_controller: template.controller.class.name,
33
+ element_action: template.controller.action_name,
34
+ element_name:,
35
+ element_ident:,
36
+ show_element: true
37
+ }
38
+ end
39
+
40
+ def load_vizfacts
41
+ return if input_control_class.nil?
42
+
43
+ site = template.controller.send(:current_site)
44
+ controller = template.controller.class.name
45
+ action = template.controller.action_name
46
+ @vizfacts = input_control_class.where(sites_site: site, element_controller: controller,
47
+ element_action: action).to_a
48
+ end
49
+
50
+ def input_control_class
51
+ Bp3::Formtastic.input_control_class
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bp3
4
+ module Formtastic
5
+ class VizFormBuilderWithCreate < VizFormBuilder
6
+ def viz(element_name, element_ident)
7
+ return if vizfacts.nil?
8
+
9
+ record = super
10
+ return record if record
11
+
12
+ create_input_control_record(element_name, element_ident)
13
+ end
14
+
15
+ private
16
+
17
+ def create_input_control_record(element_name, element_ident)
18
+ attrs = vizfact_attrs(element_name, element_ident)
19
+ Vizfact::Input.unscoped.create!(attrs)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -3,6 +3,8 @@
3
3
  require 'active_support/core_ext/module/attribute_accessors'
4
4
  require 'active_support/inflector'
5
5
 
6
+ require_relative 'formtastic/viz_form_builder'
7
+ require_relative 'formtastic/viz_form_builder_with_create'
6
8
  require_relative 'formtastic/railtie'
7
9
  require_relative 'formtastic/version'
8
10
 
@@ -11,7 +13,7 @@ module Bp3
11
13
  mattr_accessor :input_control_class_name
12
14
 
13
15
  def self.input_control_class
14
- @@input_control_class ||= input_control_class_name.constantize # rubocop:disable Style/ClassVars
16
+ @@input_control_class ||= input_control_class_name&.constantize # rubocop:disable Style/ClassVars
15
17
  end
16
18
  end
17
19
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bp3-formtastic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wim den Braven
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-05-31 00:00:00.000000000 Z
11
+ date: 2024-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -30,6 +30,26 @@ dependencies:
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '8'
33
+ - !ruby/object:Gem::Dependency
34
+ name: actionview
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 7.1.2
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '8'
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 7.1.2
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '8'
33
53
  - !ruby/object:Gem::Dependency
34
54
  name: activesupport
35
55
  requirement: !ruby/object:Gem::Requirement
@@ -64,6 +84,26 @@ dependencies:
64
84
  - - "~>"
65
85
  - !ruby/object:Gem::Version
66
86
  version: '5.0'
87
+ - !ruby/object:Gem::Dependency
88
+ name: railties
89
+ requirement: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: 7.1.2
94
+ - - "<"
95
+ - !ruby/object:Gem::Version
96
+ version: '8'
97
+ type: :runtime
98
+ prerelease: false
99
+ version_requirements: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: 7.1.2
104
+ - - "<"
105
+ - !ruby/object:Gem::Version
106
+ version: '8'
67
107
  - !ruby/object:Gem::Dependency
68
108
  name: byebug
69
109
  requirement: !ruby/object:Gem::Requirement
@@ -169,6 +209,8 @@ files:
169
209
  - lib/bp3/formtastic.rb
170
210
  - lib/bp3/formtastic/railtie.rb
171
211
  - lib/bp3/formtastic/version.rb
212
+ - lib/bp3/formtastic/viz_form_builder.rb
213
+ - lib/bp3/formtastic/viz_form_builder_with_create.rb
172
214
  - sig/bp3/formtastic.rbs
173
215
  homepage: https://www.black-phoebe.com
174
216
  licenses:
@@ -197,5 +239,5 @@ requirements: []
197
239
  rubygems_version: 3.5.11
198
240
  signing_key:
199
241
  specification_version: 4
200
- summary: bp3-formtastic adapts formtastic for BP3 (persuavis/black_phoebe_3)..
242
+ summary: bp3-formtastic adapts formtastic for BP3 (persuavis/black_phoebe_3).
201
243
  test_files: []