bp3-formtastic 0.1.2 → 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: 4fd4667ebdd632b2a5fb80e8b9498dc1594990719d2cbae101d52618d97793ac
4
- data.tar.gz: 57b9b6579614d3e4cfd9e439a85fefdcc6eb6b0f391501133997035b25132b20
3
+ metadata.gz: e1603f265734ec82fa61ee1d03f6098acbd898cc1caf6d5362340dde619f36ed
4
+ data.tar.gz: dba9f2dd5248e1426cb065d2b76c8a187b6c2c8e6005143725eaa6d1d09ec896
5
5
  SHA512:
6
- metadata.gz: 1def99fea2ec09af93804aa32d9229debaf918222126a08bf5470c30d3b6900476aa22995b7231025a3e502599149f76e5e2f39d7057ccf797f5a0028e0acb6b
7
- data.tar.gz: 3797ae7d099d5044f65813981963e5d2559d64b57557e2514c49d494675a6840e14a4ae1d4e106e03e98d615d2e8a39fca0c8358a2ba911c1b0974732843edfa
6
+ metadata.gz: 78a3bc4fd2dd535e89e5fff5eed8522fecc1572a76016ad1e4224f18c2010c6afde894f6133bc9dc09467c06def15dd5b746790ddb3fa0ab3d885a0664f7305c
7
+ data.tar.gz: b4b4871c0d0f222434190b62961db96a58ad694dde513ca0602e9caaa33f780770c865f170ba97cd9e3d08f71e187e12289447ffa8a7f6358adf13cb3e7ada47
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
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
+
3
9
  ## [0.1.2] - 2024-07-01
4
10
 
5
11
  - Check for builder.id
data/Gemfile.lock CHANGED
@@ -1,10 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bp3-formtastic (0.1.2)
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/
@@ -50,6 +52,10 @@ GEM
50
52
  actionpack (>= 6.0.0)
51
53
  i18n (1.14.5)
52
54
  concurrent-ruby (~> 1.0)
55
+ io-console (0.7.2)
56
+ irb (1.14.0)
57
+ rdoc (>= 4.0.0)
58
+ reline (>= 0.4.2)
53
59
  json (2.7.2)
54
60
  language_server-protocol (3.17.0.3)
55
61
  loofah (2.22.0)
@@ -63,12 +69,17 @@ GEM
63
69
  parser (3.3.3.0)
64
70
  ast (~> 2.4.1)
65
71
  racc
72
+ psych (5.1.2)
73
+ stringio
66
74
  racc (1.8.0)
67
75
  rack (3.1.4)
68
76
  rack-session (2.0.0)
69
77
  rack (>= 3.0.0)
70
78
  rack-test (2.1.0)
71
79
  rack (>= 1.3)
80
+ rackup (2.1.0)
81
+ rack (>= 3)
82
+ webrick (~> 1.8)
72
83
  rails-dom-testing (2.2.0)
73
84
  activesupport (>= 5.0.0)
74
85
  minitest
@@ -76,9 +87,21 @@ GEM
76
87
  rails-html-sanitizer (1.6.0)
77
88
  loofah (~> 2.21)
78
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)
79
98
  rainbow (3.1.1)
80
99
  rake (13.2.1)
100
+ rdoc (6.7.0)
101
+ psych (>= 4.0.0)
81
102
  regexp_parser (2.9.2)
103
+ reline (0.5.9)
104
+ io-console (~> 0.5)
82
105
  rexml (3.3.1)
83
106
  strscan
84
107
  rspec (3.13.0)
@@ -121,10 +144,14 @@ GEM
121
144
  rubocop-rspec_rails (2.29.1)
122
145
  rubocop (~> 1.61)
123
146
  ruby-progressbar (1.13.0)
147
+ stringio (3.1.1)
124
148
  strscan (3.1.0)
149
+ thor (1.3.1)
125
150
  tzinfo (2.0.6)
126
151
  concurrent-ruby (~> 1.0)
127
152
  unicode-display_width (2.5.0)
153
+ webrick (1.8.1)
154
+ zeitwerk (2.6.17)
128
155
 
129
156
  PLATFORMS
130
157
  x86_64-darwin-22
data/README.md CHANGED
@@ -19,12 +19,22 @@ Or install it yourself as:
19
19
  $ gem install bp3-formtastic
20
20
 
21
21
  ## Usage
22
- 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
23
23
  that controls whether to show a formtastic input control or not:
24
24
  ```ruby
25
25
  Bp3::Formtastic.input_control_class_name = 'Vizfact::Input'
26
26
  ```
27
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
+
28
38
  ## Development
29
39
  After checking out the repo, run `bin/setup` to install dependencies. Then, run
30
40
  `rake spec` to run the tests. You can also run `bin/console` for an interactive
@@ -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
23
  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
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.2'
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.2
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-07-01 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: