base_editing_bootstrap 0.1.4 → 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: e95ef3ba43c9fd79ca3df0c1950e3b5b16fe52730e77174f227f7c7a046c7d4a
4
- data.tar.gz: 631eae428893bf3722901da4d2fa28984f55507edfb2f6e8fe34c8c82d488fae
3
+ metadata.gz: 0f935f929fda6d975ddd3d969fe03d639e0c523a19824733227bec64865e982e
4
+ data.tar.gz: 12448bdc9765b31fe9660d9116092cd5ff3e61bd160b8d0cfc0d699b56a85212
5
5
  SHA512:
6
- metadata.gz: '0659da3676b00f197ebf69b15b55db8e733e51eae8f2b5c95088c8f136ceac3269040eed02c1f850f5c9861421b7e3669d6828c2f9570125fcb2c327b811d53a'
7
- data.tar.gz: 4d34b433a33117af8b9c8e3470d93fa9da92e7bcf9dc3156e5e5e001611cb44d18db68dcd205dc2ecfc26c9c959d15639c5da3f01cbb98cef445fa8147b378bb
6
+ metadata.gz: f86e276eb409edff874465dfdea52e44f581d5db4ab47d0d44bd33f0b7b24c0a871125f4807371eb0f199b5bf8a56edd6768f1787d66f8fae314e4d77fc1b16b
7
+ data.tar.gz: cbb77961f4f3df339a474472a6669039505ffbe2e31aa37abea4a7eae02481ea02e459f2f47fe0e802a6ef579d4bbcb81c3058c84ad9e12636462b3a28617f22
data/CHANGELOG.md CHANGED
@@ -2,6 +2,22 @@
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.2.0 - 2024-04-23
6
+ #### Documentation
7
+ - Add documntation for installation - (b528daa) - Marino Bonetti
8
+ - Fix documentation - (28e2e0b) - Marino Bonetti
9
+ #### Features
10
+ - Add Automatic Enum editing - (aab85a5) - Marino Bonetti
11
+ #### Miscellaneous Chores
12
+ - Remove code - (e07516a) - Marino Bonetti
13
+ - Fix Cog hooks - (2045412) - Marino Bonetti
14
+ #### Refactoring
15
+ - Rewrite helpers for base request editing - (1a08528) - Marino Bonetti
16
+ #### Tests
17
+ - Add test for enum helper - (4f48b48) - Marino Bonetti
18
+
19
+ - - -
20
+
5
21
  ## 0.1.4 - 2024-04-21
6
22
  #### Miscellaneous Chores
7
23
  - Fix Cog hooks - (ebd2d77) - Marino Bonetti
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
1
  # BaseEditingBootstrap
2
+ [![Gem Version](https://badge.fury.io/rb/base_editing_bootstrap.svg)](https://badge.fury.io/rb/base_editing_bootstrap)
3
+
2
4
  WIP
3
5
 
4
6
  ## Installation
@@ -42,10 +44,26 @@ config.generators do |g|
42
44
  g.factory_bot dir: 'spec/factories'
43
45
  end
44
46
  ```
47
+ ### Initializers
48
+ E' possibile configurare BaseEditingBootstrap con alcune impostazioni:
49
+ ```ruby
50
+ BaseEditingBootstrap.configure do |config|
51
+ ##
52
+ # Controller da cui derivare poi il BaseEditingController da cui derivano
53
+ # tutti i controller sottostanti
54
+ # @default "ApplicationController"
55
+ # config.inherited_controller = 'ApplicationController'
56
+ end
57
+
58
+ ```
59
+
45
60
  ## Usage
46
61
  Utilizzo per modello base, in questo esempio prendiamo come modello Post come esempio del dummy.
47
62
 
48
- - Creare il Modello ed includere `include BaseEditingBootstrap::BaseModel`
63
+ - Creare il Modello ed includere
64
+ ```ruby
65
+ include BaseEditingBootstrap::BaseModel
66
+ ```
49
67
  - Creare Controller:
50
68
  ```ruby
51
69
  class PostsController < BaseEditingController
@@ -99,11 +117,15 @@ Utilizzo per modello base, in questo esempio prendiamo come modello Post come es
99
117
  - updated_at => timestamps.html.erb
100
118
  - default => base.html.erb
101
119
  **Form Field**
102
- - Integer => _integer.html.erb
103
- - Float => _decimal.html.erb
104
- - Decimal => _decimal.html.erb
105
- - DateTime => _detetime.html.erb
106
- - Date => _date.html.erb
120
+ - Integer => _integer.html.erb
121
+ - Float => _decimal.html.erb
122
+ - Decimal => _decimal.html.erb
123
+ - DateTime => _detetime.html.erb
124
+ - Date => _date.html.erb
125
+ - Enum => _enum.html.erb
126
+ Per gli enum, le traduzioni dei labels di ogni valore provvengono da i18n
127
+ attraverso l'helper: `Utilities::EnumHelper#enum_translation`
128
+ il quale utilizza il nome dell'attributo con
107
129
  - Default/String => _base.html.erb
108
130
 
109
131
  In futuro si prevede di aggiungere automatismi per renderizzare senza
@@ -18,7 +18,10 @@ module Utilities
18
18
  def enum_translation(model, attribute, value, variant = nil)
19
19
  return '' if value.nil?
20
20
  variant = "_#{variant}" unless variant.nil?
21
- model.human_attribute_name("#{attribute}.#{value}#{variant}")
21
+ model.human_attribute_name(
22
+ "#{attribute}.#{value}#{variant}",
23
+ default: model.human_attribute_name("#{attribute}.#{value}")
24
+ )
22
25
  end
23
26
  end
24
27
  end
@@ -1,6 +1,7 @@
1
1
  module Utilities
2
2
  module FormHelper
3
3
  include TemplateHelper
4
+ include EnumHelper
4
5
  ##
5
6
  # Metodo su cui eseguire override per i campi specifici rispetto all'oggetto gestito dal controller
6
7
  # @deprecated Utilizza form_print_field(form, field) senza sovrascriverlo
@@ -17,7 +18,8 @@ module Utilities
17
18
  # @param [Symbol] field
18
19
  def form_print_field(form, field)
19
20
  locals = {form:, field:}
20
- case form.object.class.type_for_attribute(field).type
21
+ type = form.object.class.type_for_attribute(field).type
22
+ case type
21
23
  when :datetime
22
24
  generic_field = "datetime"
23
25
  when :date
@@ -31,7 +33,11 @@ module Utilities
31
33
  when :integer
32
34
  generic_field = "integer"
33
35
  else
34
- generic_field = "base"
36
+ if form.object.class.defined_enums.key?(field.to_s)
37
+ generic_field = "enum"
38
+ else
39
+ generic_field = "base"
40
+ end
35
41
  end
36
42
 
37
43
  template = find_template_with_fallbacks(
@@ -40,7 +46,7 @@ module Utilities
40
46
  "form_field",
41
47
  generic_field
42
48
  )
43
- Rails.logger.debug { "#{template}->#{ locals.inspect}" }
49
+ Rails.logger.debug { "#{type}->#{generic_field}->#{template}->#{ locals.inspect}" }
44
50
  render template, **locals
45
51
  end
46
52
 
@@ -0,0 +1,2 @@
1
+ <%# locals: (form:, field:) -%>
2
+ <%= form.select(field, enum_collection(form.object.class, field)) %>
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
13
13
 
14
14
  spec.metadata["homepage_uri"] = spec.homepage
15
15
  spec.metadata["source_code_uri"] = "https://github.com/oniram88/BaseEditingBootstrap"
16
- spec.metadata["changelog_uri"] = "https://github.com/oniram88/BaseEditingBootstrap/CHANGELOG"
16
+ spec.metadata["changelog_uri"] = "https://github.com/oniram88/BaseEditingBootstrap/blob/main/CHANGELOG.md"
17
17
 
18
18
  # Specify which files should be added to the gem when it is released.
19
19
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
data/cog.toml CHANGED
@@ -13,7 +13,8 @@ post_bump_hooks = [
13
13
  "git push",
14
14
  "git push origin {{version}}",
15
15
  "docker compose run app gem build base_editing_bootstrap.gemspec",
16
- "docker compose run app gem push base_editing_bootstrap-{{version}}.gem"
16
+ "docker compose run app gem push base_editing_bootstrap-{{version}}.gem",
17
+ "rm -fr base_editing_bootstrap-{{version}}.gem"
17
18
  ]
18
19
  pre_package_bump_hooks = []
19
20
  post_package_bump_hooks = []
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.2.0
@@ -15,6 +15,11 @@ loader.setup
15
15
 
16
16
  module BaseEditingBootstrap
17
17
  include ActiveSupport::Configurable
18
+
19
+ ##
20
+ # Controller da cui derivare poi il BaseEditingController da cui derivano
21
+ # tutti i controller sottostanti
22
+ # @default "ApplicationController"
18
23
  config_accessor :inherited_controller, default: "ApplicationController"
19
24
 
20
25
  def self.deprecator
@@ -23,13 +23,13 @@ RSpec.shared_examples "base editing controller" do |factory: nil, only: [], exce
23
23
  ##
24
24
  # Possibili override per la costruzione delle path
25
25
  #
26
- let(:url_for_new) { [model.new, action: :new] }
26
+ let(:url_for_new) { url_for([model.new, action: :new]) }
27
27
  let(:url_for_index) { url_for(model) }
28
- let(:url_for_create) { [model.new] }
28
+ let(:url_for_create) { url_for(model.new) }
29
29
  let(:url_for_succ_delete) { url_for(model) }
30
30
  let(:url_for_fail_delete) { url_for_succ_delete }
31
- let(:url_for_edit) { [persisted_instance, action: :edit] }
32
- let(:url_for_update) { [persisted_instance, params: {param_key => valid_attributes}] }
31
+ let(:url_for_edit) { url_for([persisted_instance, action: :edit]) }
32
+ let(:url_for_update) { url_for(persisted_instance) }
33
33
  ## non sempre abbiamo l'index nelle action disponibili, dobbiamo quindi avere modo di eseguire un override
34
34
  let(:url_for_unauthorized) { url_for_index }
35
35
  ##
@@ -69,7 +69,7 @@ RSpec.shared_examples "base editing controller" do |factory: nil, only: [], exce
69
69
  if check_if_should_execute(only, except, :new)
70
70
  describe "new" do
71
71
  it "response" do
72
- get url_for(url_for_new)
72
+ get url_for_new
73
73
  expect(response).to have_http_status(:ok)
74
74
  expect(assigns[:object]).to be_an_instance_of(model)
75
75
  end
@@ -79,7 +79,7 @@ RSpec.shared_examples "base editing controller" do |factory: nil, only: [], exce
79
79
  if check_if_should_execute(only, except, :edit)
80
80
  describe "edit" do
81
81
  it "response" do
82
- get url_for(url_for_edit)
82
+ get url_for_edit
83
83
  expect(response).to have_http_status(:ok)
84
84
  expect(assigns[:object]).to be_an_instance_of(model)
85
85
  end
@@ -89,14 +89,14 @@ RSpec.shared_examples "base editing controller" do |factory: nil, only: [], exce
89
89
  if check_if_should_execute(only, except, :update)
90
90
  describe "update" do
91
91
  it "response" do
92
- put url_for(url_for_update)
92
+ put url_for_update, params: {param_key => valid_attributes}
93
93
  expect(assigns[:object]).to be_an_instance_of(model)
94
94
  expect(response).to have_http_status(:see_other)
95
95
  end
96
96
 
97
97
  unless skip_invalid_checks
98
98
  it "not valid" do
99
- put url_for([persisted_instance, params: {param_key => invalid_attributes}])
99
+ put url_for_update, params: {param_key => invalid_attributes}
100
100
  expect(response).to have_http_status(:unprocessable_entity)
101
101
  end
102
102
  end
@@ -106,14 +106,14 @@ RSpec.shared_examples "base editing controller" do |factory: nil, only: [], exce
106
106
  if check_if_should_execute(only, except, :create)
107
107
  describe "create" do
108
108
  it "response" do
109
- post url_for([*url_for_create, params: {param_key => valid_attributes}])
109
+ post url_for_create, params: {param_key => valid_attributes}
110
110
  expect(assigns[:object]).to be_an_instance_of(model)
111
111
  expect(response).to have_http_status(:see_other)
112
112
  end
113
113
 
114
114
  unless skip_invalid_checks
115
115
  it "not valid" do
116
- post url_for([*url_for_create, params: {param_key => invalid_attributes}])
116
+ post url_for_create, params: {param_key => invalid_attributes}
117
117
  expect(response).to have_http_status(:unprocessable_entity)
118
118
  end
119
119
  end
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.1.4
4
+ version: 0.2.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-04-21 00:00:00.000000000 Z
11
+ date: 2024-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -121,7 +121,6 @@ files:
121
121
  - app/helpers/base_editing_helper.rb
122
122
  - app/helpers/utilities/enum_helper.rb
123
123
  - app/helpers/utilities/form_helper.rb
124
- - app/helpers/utilities/modal_helper.rb
125
124
  - app/helpers/utilities/page_helper.rb
126
125
  - app/helpers/utilities/search_helper.rb
127
126
  - app/helpers/utilities/template_helper.rb
@@ -155,6 +154,7 @@ files:
155
154
  - app/views/base_editing/form_field/_date.html.erb
156
155
  - app/views/base_editing/form_field/_datetime.html.erb
157
156
  - app/views/base_editing/form_field/_decimal.html.erb
157
+ - app/views/base_editing/form_field/_enum.html.erb
158
158
  - app/views/base_editing/form_field/_integer.html.erb
159
159
  - app/views/base_editing/index.html.erb
160
160
  - app/views/base_editing/new.html.erb
@@ -192,7 +192,7 @@ licenses:
192
192
  metadata:
193
193
  homepage_uri: https://github.com/oniram88/BaseEditingBootstrap
194
194
  source_code_uri: https://github.com/oniram88/BaseEditingBootstrap
195
- changelog_uri: https://github.com/oniram88/BaseEditingBootstrap/CHANGELOG
195
+ changelog_uri: https://github.com/oniram88/BaseEditingBootstrap/blob/main/CHANGELOG.md
196
196
  post_install_message:
197
197
  rdoc_options: []
198
198
  require_paths:
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Utilities::ModalHelper
4
- ##
5
- # Metodo speciale per l'inclusione del contenuto nelle modal, forzando il flush in modo da poter utilizzare
6
- # più modal contemporaneamente
7
- def content_for_modal(*args, &block)
8
- opts = args.extract_options!
9
- content_for(*args, opts.merge(flush: true), &block)
10
- end
11
- end