base_editing_bootstrap 0.12.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2ebd5f42f60f886ca0e8c5ecff7d5be53531bf015ea7c44f763f6d07127f69ec
4
- data.tar.gz: 007b28d61ec3058efdc94488578cc2fdae37d1477296511db5e5653f77b94bee
3
+ metadata.gz: 1f4da39d416d3107b6e4f40d63a33c136eed02e5d5c8cb6b2e91423be99460c1
4
+ data.tar.gz: f71d9cfd3efeef8edbd20ee5da7ec9b98f198ce6a9fc99ed7b8cc0af7038983c
5
5
  SHA512:
6
- metadata.gz: 530342bff9cac4c81404c568d89faf99293f1992e3c2aedea0042ec4ed9a3f30bf72f9a9da75036bef84eb29c8b7e8299baa4b5c548d5ef7ca2e9497732a3478
7
- data.tar.gz: 4b9e115f5ee49c9857bb243091e4ca58c70f0e02d16e241dbb93c09337728fee62455c673818fb963810d0dec36462ce332194217d590c3848bd013213126c55
6
+ metadata.gz: c93f3d73d379b66d37a039064ac5f6cb8638f32e9785d2998c7d3353f060dde6c6be02db38d8ac6f1e2ef29e3e0a1ab4e265b73959bbd3dacbff5ecc367d87e1
7
+ data.tar.gz: ef9c876ff6628cdbc7b200240b3785952e58d951a610bd8275a587d2d6c9b6ea03724bd03c5f6def17c81c04b268a79c5330a7288931418ace32062356c214df
data/CHANGELOG.md CHANGED
@@ -2,6 +2,32 @@
2
2
  All notable changes to this project will be documented in this file. See [conventional commits](https://www.conventionalcommits.org/) for commit guidelines.
3
3
 
4
4
  - - -
5
+ ## 0.14.0 - 2024-10-14
6
+ #### Bug Fixes
7
+ - Namespaced resources (#7) - (e85f926) - Marino Bonetti
8
+ #### Continuous Integration
9
+ - Start Enabling Rails 8.0 - (9c66914) - Marino Bonetti
10
+ - Fix scaffold generator questions - (0379151) - Marino Bonetti
11
+ #### Documentation
12
+ - Add more info in spec desc - (82ab3a7) - Marino Bonetti
13
+ - Add docs for Development - (616a0ea) - Marino Bonetti
14
+ - Add locals form partial - (022eb83) - Marino Bonetti
15
+ #### Features
16
+ - Boolean field - (8c7d0a2) - Marino Bonetti
17
+ - Auto remove input-group for checkboxes - (d5b13d2) - Marino Bonetti
18
+ - Add searchable columns - (9ccfb6f) - Marino Bonetti
19
+ - Add option to FullDisallowPolicy - (6468967) - Marino Bonetti
20
+
21
+ - - -
22
+
23
+ ## 0.13.0 - 2024-10-02
24
+ #### Bug Fixes
25
+ - Correct generator - (c3a5e60) - Marino Bonetti
26
+ #### Features
27
+ - Rails Matrix versions (#4) - (1deaa4e) - Marino Bonetti
28
+
29
+ - - -
30
+
5
31
  ## 0.12.0 - 2024-10-01
6
32
  #### Documentation
7
33
  - Update documentation - (e49af20) - Marino Bonetti
data/README.md CHANGED
@@ -146,6 +146,7 @@ Utilizzo per modello base, in questo esempio prendiamo come modello Post come es
146
146
  - Decimal => _decimal.html.erb
147
147
  - DateTime => _datetime.html.erb
148
148
  - Date => _date.html.erb
149
+ - Boolean => _boolean.html.erb
149
150
  - Enum => _enum.html.erb
150
151
  Per gli enum, le traduzioni dei labels di ogni valore provvengono da i18n
151
152
  attraverso l'helper: `Utilities::EnumHelper#enum_translation`
@@ -222,7 +223,15 @@ end
222
223
 
223
224
 
224
225
  ## Contributing
225
- Contribution directions go here.
226
+ 1. Setup env with:
227
+ ```shell
228
+ docker compose run app spec/dummy/bin/setup
229
+ ```
230
+
231
+ 2. Start environment with:
232
+ ```shell
233
+ docker compose up
234
+ ```
226
235
 
227
236
  ## License
228
237
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -86,12 +86,14 @@ class BaseEditingController < RestrictedAreaController
86
86
 
87
87
  def base_class
88
88
  return @_base_class if @_base_class
89
- controller = controller_path
90
- modello = controller.singularize.camelize.safe_constantize
91
- logger.debug { "Editazione del controller:#{controller} per modello: #{modello.to_s}" }
92
- raise "Non riesco a restituire la classe base per il controller #{controller}" if modello.nil?
89
+ finder = BaseEditingBootstrap::ResourceFinder.new(controller_path)
90
+ if finder.model
91
+ logger.debug { "Editazione del controller:#{controller_path} per modello: #{finder.model.to_s}" }
92
+ else
93
+ raise "Non riesco a restituire la classe base per il controller #{controller_path}"
94
+ end
93
95
 
94
- @_base_class = modello
96
+ @_base_class = finder.model
95
97
  end
96
98
 
97
99
  private
@@ -3,20 +3,7 @@ module BaseEditingHelper
3
3
  include Utilities::EnumHelper
4
4
  include Utilities::SearchHelper
5
5
  include Utilities::FormHelper
6
+ include Utilities::IconHelper
6
7
 
7
8
 
8
- ##
9
- # Genera le icone di Bootstrap icons
10
- def icon( name, text = nil, html_options = {})
11
- text, html_options = nil, text if text.is_a?(Hash)
12
-
13
- content_class = "bi-#{name}"
14
- content_class << " #{html_options[:class]}" if html_options.key?(:class)
15
- html_options[:class] = content_class
16
- html_options['aria-hidden'] ||= true
17
-
18
- html = content_tag(:i, nil, html_options)
19
- html << ' ' << text.to_s unless text.blank?
20
- html
21
- end
22
9
  end
@@ -35,6 +35,8 @@ module Utilities
35
35
  generic_field = "decimal"
36
36
  when :integer
37
37
  generic_field = "integer"
38
+ when :boolean
39
+ generic_field = "boolean"
38
40
  else
39
41
  generic_field = "base"
40
42
  end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Utilities::IconHelper
4
+
5
+ ##
6
+ # Genera le icone di Bootstrap icons
7
+ def icon( name, text = nil, html_options = {})
8
+ text, html_options = nil, text if text.is_a?(Hash)
9
+
10
+ content_class = "bi-#{name}"
11
+ content_class += " #{html_options[:class]}" if html_options.key?(:class)
12
+ html_options[:class] = content_class
13
+ html_options['aria-hidden'] ||= true
14
+
15
+ html = content_tag(:i, nil, html_options)
16
+ html << ' ' << text.to_s unless text.blank?
17
+ html
18
+ end
19
+ end
@@ -1,6 +1,8 @@
1
1
  module Utilities
2
2
  module SearchHelper
3
3
  include TemplateHelper
4
+ include PageHelper
5
+ include IconHelper
4
6
 
5
7
  ##
6
8
  # Per aggiungere bottoni:
@@ -32,7 +34,14 @@ module Utilities
32
34
  when :created_at, :updated_at
33
35
  "timestamps"
34
36
  else
35
- "base"
37
+ type = obj.class.type_for_attribute(field).type
38
+ case type
39
+ when :boolean
40
+ "boolean"
41
+ else
42
+ "base"
43
+ end
44
+
36
45
  end
37
46
  template = find_template_with_fallbacks(
38
47
  obj,
@@ -1,7 +1,27 @@
1
- <%= form.label(form_field, class: ["form-label","form-#{form_field}-label"]) %>
2
- <div class="input-group mb-2 <%= form.object.validated? ? "has-validation" : "" %><%= "form-#{form_field}-input-group" %>">
1
+ <%
2
+ ##
3
+ # Template per il rendering campo
4
+ # - form -> FormBuilder
5
+ # - form_field -> Array[String]
6
+ %>
7
+ <%# locals: (form:, form_field:) -%>
8
+ <%= form.label(form_field, class: ["form-label", "form-#{form_field}-label"]) %>
9
+
10
+ <%
11
+ button_group_classes = ["mb-2"]
12
+
13
+ content = form_print_field(form, form_field)
14
+ unless content.match "checkbox"
15
+ button_group_classes << "input-group"
16
+ end
17
+
18
+ button_group_classes << (form.object.validated? ? "has-validation" : "")
19
+ button_group_classes << "form-#{form_field}-input-group"
20
+
21
+ %>
22
+ <%= content_tag :div, class: button_group_classes.join(" ") do %>
3
23
  <%= render partial: "editing_form_measure_unit", locals: {object: form.object, field: form_field} %>
4
- <%= form_print_field(form, form_field) %>
24
+ <%= content %>
5
25
  <%= error_messages_for(form.object, form_field) %>
6
- </div>
26
+ <% end %>
7
27
  <%= render partial: "editing_form_help_text", locals: {object: form.object, field: form_field} %>
@@ -0,0 +1,3 @@
1
+ <%# Renderizza il campo nella tabella della pagina dei risultati %>
2
+ <%# locals: (obj:,field:) -%>
3
+ <td><%= boolean_to_icon obj.read_attribute(field) %></td>
@@ -0,0 +1,2 @@
1
+ <%# locals: (form:, field:) -%>
2
+ <%= form.switch_box(field) %>
@@ -29,7 +29,7 @@ Gem::Specification.new do |spec|
29
29
  end
30
30
  spec.files += Dir['spec/support/external_shared/*.rb']
31
31
 
32
- spec.add_dependency "rails", [">= 7.0", "< 8.0"]
32
+ spec.add_dependency "rails", [">= 7.0", "< 8.1"]
33
33
  # Policy
34
34
  spec.add_dependency "pundit", ["~> 2.3", ">= 2.3.1"]
35
35
  # Search
@@ -38,11 +38,11 @@ Gem::Specification.new do |spec|
38
38
  spec.add_dependency 'kaminari', ['~> 1.2', '>= 1.2.2']
39
39
  spec.add_dependency 'kaminari-i18n', '~> 0.5'
40
40
 
41
- spec.add_development_dependency "rspec-rails", '~> 6.0'
41
+ spec.add_development_dependency "rspec-rails", '~> 7.0'
42
42
  spec.add_development_dependency "factory_bot_rails", '~> 6.4'
43
43
  spec.add_development_dependency 'faker', '~> 3.3'
44
44
  spec.add_development_dependency "puma", '~> 6.4'
45
- spec.add_development_dependency "sqlite3", '~> 1.7'
45
+ spec.add_development_dependency "sqlite3", '>= 1.7.x'
46
46
  spec.add_development_dependency "sprockets-rails", '~> 3.4'
47
47
  spec.add_development_dependency 'rails-i18n', '~> 7.0' # For 7.0.0
48
48
  spec.add_development_dependency "i18n-debug", '~> 1.2'
@@ -1 +1 @@
1
- 0.12.0
1
+ 0.14.0
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BaseEditingBootstrap
4
+ ##
5
+ # PORO to find the base classe in the BaseEditingController
6
+ class ResourceFinder
7
+ def initialize(controllar_path)
8
+ @controllar_path = controllar_path
9
+ @_model_class = false
10
+ end
11
+
12
+ # @return [NilClass|Object]
13
+ def model
14
+ if @_model_class === false
15
+ @_model_class = nil
16
+ if (anything = @controllar_path.singularize.camelize.safe_constantize)
17
+ @_model_class = anything
18
+ else
19
+ if @controllar_path.include?("/")
20
+ demodulize_one_level = @controllar_path.split("/")[1..].join("/")
21
+ if demodulize_one_level != @controllar_path
22
+ @_model_class = ResourceFinder.new(demodulize_one_level).model
23
+ end
24
+ end
25
+ end
26
+ end
27
+ @_model_class
28
+ end
29
+ end
30
+ end
@@ -7,7 +7,7 @@ module BaseEditingBootstrap
7
7
  argument :name, type: :string, banner: "Post", required: true
8
8
  argument :attributes, type: :array, default: [], banner: "field field:type"
9
9
 
10
- TYPES = [:base,:timestamps].freeze
10
+ TYPES = [:base, :timestamps, :boolean].freeze
11
11
 
12
12
  desc <<-DESCRIPTION.strip_heredoc
13
13
  Description:
@@ -7,7 +7,7 @@ module BaseEditingBootstrap
7
7
  argument :name, type: :string, banner: "Post", required: true
8
8
  argument :attributes, type: :array, default: [], banner: "field field:type"
9
9
 
10
- TYPES = %i[base date datetime decimal integer enum]
10
+ TYPES = %i[base date datetime decimal integer enum boolean]
11
11
 
12
12
  desc <<-DESCRIPTION.strip_heredoc
13
13
  Description:
@@ -11,12 +11,12 @@ BaseEditingBootstrap.configure do |config|
11
11
  # Configurazione per alterare lo standard di azione post aggiornamento record
12
12
  # il default è andare nella pagina di editing del record
13
13
  # possibili valori :edit , :index
14
- # config.inherited_controller = :edit
14
+ # config.after_success_update_redirect = :edit
15
15
 
16
16
  ##
17
17
  # Configurazione per alterare lo standard di azione post creazione record
18
18
  # il default è andare nella pagina di editing del record
19
19
  # possibili valori :edit , :index
20
- # config.inherited_controller = :edit
20
+ # config.after_success_create_redirect = :edit
21
21
 
22
22
  end
@@ -31,7 +31,8 @@ module BaseEditingBootstrap
31
31
 
32
32
  def add_policy
33
33
  @search_attrs = []
34
- if yes? "Vuoi poter ricercare determinati campi con form di ricerca?"
34
+ @permitted_attributes = []
35
+ if yes? "Vuoi poter ricercare determinati campi con form di ricerca?(y/n)"
35
36
 
36
37
  say "Gli attributi che hai indicato sono: #{ attributes_names.join(",")}"
37
38
  say <<~MESSAGE
@@ -52,11 +53,11 @@ module BaseEditingBootstrap
52
53
  out << [attr, *matchers.keys.collect{|m| "#{attr}#{m}" } ]
53
54
  end
54
55
 
55
- puts out.inspect
56
-
57
56
  print_table(out,borders:true)
58
57
  @search_attrs = ask("Inserisce un elenco diviso da virgola degli attributi da ricercare").split(",")
59
-
58
+ #cerchiamo di estrapolare gli attributi da rendere disponibili a ransack per la ricerca
59
+ @permitted_attributes = out.select{|c| c[1..].intersect?(@search_attrs) }.collect(&:first)
60
+ puts @permitted_attributes.inspect
60
61
  end
61
62
 
62
63
  template "policy.rb", File.join("app/policies", "#{singular_name}_policy.rb")
@@ -8,4 +8,10 @@ class <%= class_name %>Policy < BaseModelPolicy
8
8
  %i[<%= @search_attrs.join(" ") %>]
9
9
  end
10
10
  <%- end -%>
11
+ <%- if @permitted_attributes.any? -%>
12
+ # TODO check if correct with search_fields
13
+ def permitted_attributes_for_ransack
14
+ %w[<%= @permitted_attributes.join(" ") %>]
15
+ end
16
+ <%- end -%>
11
17
  end
@@ -190,7 +190,13 @@ default_unathorized_failure = -> { raise "TODO - passare proc con richiesta che
190
190
 
191
191
  RSpec.shared_examples "fail with unauthorized" do |request: default_unathorized_failure|
192
192
  it "is expected to redirect to root" do
193
- expect(Pundit).to receive(:authorize).with(user, any_args).and_raise(Pundit::NotAuthorizedError)
193
+
194
+ if Gem::Version.create( Pundit::VERSION) < Gem::Version.create('2.3.2')
195
+ allow(Pundit).to receive(:authorize).with(user, any_args).and_raise(Pundit::NotAuthorizedError)
196
+ else
197
+ allow_any_instance_of(Pundit::Context).to receive(:authorize).and_raise(Pundit::NotAuthorizedError)
198
+ end
199
+
194
200
  instance_exec(&request)
195
201
  expect(response).to redirect_to(root_path)
196
202
  expect(flash[:error]).not_to be_nil
@@ -28,6 +28,14 @@ RSpec.shared_examples "a standard base model policy" do |factory, check_default_
28
28
  create: true,
29
29
  index: true
30
30
  }
31
+ elsif check_default_responses == :full_disallow
32
+ checks = {
33
+ show: false,
34
+ destroy: false,
35
+ update: false,
36
+ create: false,
37
+ index: false
38
+ }
31
39
  elsif check_default_responses.is_a? Hash
32
40
  checks = check_default_responses
33
41
  elsif check_default_responses == false
@@ -37,6 +45,7 @@ RSpec.shared_examples "a standard base model policy" do |factory, check_default_
37
45
  Acceptable values for check_default_responses are:
38
46
  - true
39
47
  - false
48
+ - :full_disallow -> all methods to false
40
49
  - Hash with:
41
50
  show
42
51
  destroy
@@ -64,7 +73,7 @@ RSpec.shared_examples "a standard base model policy" do |factory, check_default_
64
73
  end
65
74
 
66
75
  with_them do
67
- it "should " do
76
+ it "should respond_to? #{params[:method]}" do
68
77
  expect(instance).to respond_to(method)
69
78
  end
70
79
  if check_default_responses
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: base_editing_bootstrap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marino Bonetti
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-10-01 00:00:00.000000000 Z
11
+ date: 2024-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '7.0'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '8.0'
22
+ version: '8.1'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '7.0'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '8.0'
32
+ version: '8.1'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: pundit
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -110,14 +110,14 @@ dependencies:
110
110
  requirements:
111
111
  - - "~>"
112
112
  - !ruby/object:Gem::Version
113
- version: '6.0'
113
+ version: '7.0'
114
114
  type: :development
115
115
  prerelease: false
116
116
  version_requirements: !ruby/object:Gem::Requirement
117
117
  requirements:
118
118
  - - "~>"
119
119
  - !ruby/object:Gem::Version
120
- version: '6.0'
120
+ version: '7.0'
121
121
  - !ruby/object:Gem::Dependency
122
122
  name: factory_bot_rails
123
123
  requirement: !ruby/object:Gem::Requirement
@@ -164,16 +164,16 @@ dependencies:
164
164
  name: sqlite3
165
165
  requirement: !ruby/object:Gem::Requirement
166
166
  requirements:
167
- - - "~>"
167
+ - - ">="
168
168
  - !ruby/object:Gem::Version
169
- version: '1.7'
169
+ version: 1.7.x
170
170
  type: :development
171
171
  prerelease: false
172
172
  version_requirements: !ruby/object:Gem::Requirement
173
173
  requirements:
174
- - - "~>"
174
+ - - ">="
175
175
  - !ruby/object:Gem::Version
176
- version: '1.7'
176
+ version: 1.7.x
177
177
  - !ruby/object:Gem::Dependency
178
178
  name: sprockets-rails
179
179
  requirement: !ruby/object:Gem::Requirement
@@ -302,6 +302,7 @@ files:
302
302
  - app/helpers/base_editing_helper.rb
303
303
  - app/helpers/utilities/enum_helper.rb
304
304
  - app/helpers/utilities/form_helper.rb
305
+ - app/helpers/utilities/icon_helper.rb
305
306
  - app/helpers/utilities/page_helper.rb
306
307
  - app/helpers/utilities/search_helper.rb
307
308
  - app/helpers/utilities/template_helper.rb
@@ -331,9 +332,11 @@ files:
331
332
  - app/views/base_editing/_search_result_row.html.erb
332
333
  - app/views/base_editing/_tabs.html.erb
333
334
  - app/views/base_editing/cell_field/_base.html.erb
335
+ - app/views/base_editing/cell_field/_boolean.html.erb
334
336
  - app/views/base_editing/cell_field/_timestamps.html.erb
335
337
  - app/views/base_editing/edit.html.erb
336
338
  - app/views/base_editing/form_field/_base.html.erb
339
+ - app/views/base_editing/form_field/_boolean.html.erb
337
340
  - app/views/base_editing/form_field/_date.html.erb
338
341
  - app/views/base_editing/form_field/_datetime.html.erb
339
342
  - app/views/base_editing/form_field/_decimal.html.erb
@@ -359,6 +362,7 @@ files:
359
362
  - lib/base_editing_bootstrap/engine.rb
360
363
  - lib/base_editing_bootstrap/forms/base.rb
361
364
  - lib/base_editing_bootstrap/is_validated.rb
365
+ - lib/base_editing_bootstrap/resource_finder.rb
362
366
  - lib/base_editing_bootstrap/searches/base.rb
363
367
  - lib/base_editing_bootstrap/searches/field.rb
364
368
  - lib/base_editing_bootstrap/version.rb