base_editing_bootstrap 0.7.0 → 0.8.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: f49f0f2c12bba569f7cc1d5dae8c7539939b2f98214800c405566fc20a2b8597
4
- data.tar.gz: 2f5c46bad766c8212f9d8684cb951c8156d6c26a279d411c5cc61e9e117abb54
3
+ metadata.gz: 5b1619def3100d40ea9c0af463dae74782d4a1a66b6b01fd823fb8a6fb4a7be0
4
+ data.tar.gz: 81fb33920d91b1273f7055f6522552de71c0cb0098bae8b9af2e896fcbd21695
5
5
  SHA512:
6
- metadata.gz: '058cca4f47850ca85f902e591f0c48df33ac520d47a593ef0c1f307fb838c911aa8100330fbe8b0391c7d4f9ef3d1551666c4ad18e760ab0959bdb70f7478997'
7
- data.tar.gz: 6f05b31efdf2862ff1e7ff5f90ccf9b98645493223f801245e2e7efed0794718c9e57fa79bb851c0edb6cebd13a3c51a0cc595c4ec28ced82eb3bd8fcd082cb8
6
+ metadata.gz: a22d5a35dfc17ff26c47373ee4815d8706f53dcf164f6fb9701c5855bfaa83b99f20be9e9e62c94f6acbcb6df36076b38d53a2d6589e6837271a7a4169daae3a
7
+ data.tar.gz: dacc99dbc960c9e98170ce249238343036fdae23d7de23c4c439d3b0c80765168f6d0ad27a9de47b707663a130d865d5fd04100186f5440ca6573b3f28221aef
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.8.0 - 2024-06-12
6
+ #### Documentation
7
+ - Update Documentation - (1c7c723) - Marino Bonetti
8
+ #### Features
9
+ - Scaffolding - (34c203c) - Marino Bonetti
10
+ #### Miscellaneous Chores
11
+ - Remove useless configuration - (30f862d) - Marino Bonetti
12
+ - Remove useless configuration - (985af64) - Marino Bonetti
13
+ - Add Ruby 3.3 - (ed35587) - Marino Bonetti
14
+ - Remove unused file - (eceaa88) - Marino Bonetti
15
+ - Fix gemspec info - (73bb7e4) - Marino Bonetti
16
+ #### Tests
17
+ - Restore Test - (0053349) - Marino Bonetti
18
+
19
+ - - -
20
+
5
21
  ## 0.7.0 - 2024-05-30
6
22
  #### Bug Fixes
7
23
  - Generators with enum - (7f25cac) - Marino Bonetti
data/README.md CHANGED
@@ -41,15 +41,8 @@ La versione più semplice è attraverso: https://github.com/rails/cssbundling-ra
41
41
  Una volta installato basta lanciare bin/rails css:install:bootstrap come da
42
42
  documentazione e avrete la vostra versione di boostrap installata.
43
43
 
44
- Installare `gem "factory_bot_rails"`,
45
- Optional configurarlo correttamente in application.rb
46
- ```ruby
47
- config.generators do |g|
48
- g.test_framework :rspec
49
- g.fixture_replacement :factory_bot
50
- g.factory_bot dir: 'spec/factories'
51
- end
52
- ```
44
+ Installare `gem "factory_bot_rails"`
45
+
53
46
  ### Initializers
54
47
  E' possibile configurare BaseEditingBootstrap con alcune impostazioni:
55
48
  ```ruby
@@ -100,40 +93,35 @@ Utilizzo per modello base, in questo esempio prendiamo come modello Post come es
100
93
  ```ruby
101
94
  class PostPolicy < BaseModelPolicy
102
95
 
103
- def editable_attributes
104
- [
105
- :title,
106
- :description
107
- ]
108
- end
109
-
110
- def permitted_attributes
111
- [
112
- :title,
113
- :description
114
- ]
115
- end
96
+ def editable_attributes
97
+ [
98
+ :title,
99
+ :description
100
+ ]
101
+ end
102
+
103
+ def permitted_attributes
104
+ [
105
+ :title,
106
+ :description
107
+ ]
108
+ end
109
+
110
+ def search_result_fields
111
+ [:title]
112
+ end
116
113
 
117
- def search_result_fields
118
- [:title]
119
- end
120
114
  end
121
115
 
122
116
  ```
123
- - [OPTIONAL] nel caso si volesse fare override dei campi della form:
124
- Per il campo che si vuole fare override creare un nuovo file nella cartella
125
- del modello `app/views/posts/post/form_field/_NOME_CAMPO.html.erb`
126
- al cui interno renderizzare il campo come si preferisce:
127
- ```erbruby
128
- <%# locals: (form:, field:) -%>
129
- <%= form.text_field(field) %>
117
+ - [OPTIONAL] nel caso si volesse fare override dei campi della form chiamare il generatore:
118
+ ```shell
119
+ rails g base_editing_bootstrap:field_override ModelName field1 field2:type
130
120
  ```
131
121
  - [OPTIONAL] la medesima cosa è possibile fare con il rendering dei campi
132
- delle celle della tabella della pagina index.
133
- La cartella da generare in questo caso sarà: `app/views/posts/post/cell_field/_NOME_CAMPO.html.erb`
134
- ```erbruby
135
- <%# locals: (obj:,field:) -%>
136
- <td><%= obj.read_attribute(field) %></td>
122
+ delle celle della tabella
123
+ ```shell
124
+ rails g base_editing_bootstrap:cell_override ModelName field1 field2:type
137
125
  ```
138
126
  - [OPTIONAL] Base overrides:
139
127
  E' possibile anche fare un override generico dei campi, sono previsti questi tipi di partial
@@ -60,33 +60,6 @@ module Utilities
60
60
  end
61
61
  end
62
62
 
63
- def search_result_buttons(rec)
64
- btns = ActiveSupport::SafeBuffer.new
65
-
66
- if policy(rec).edit?
67
- btns << link_to(icon("pencil-square"),
68
- edit_custom_polymorphic_path(rec),
69
- class: "btn btn-sm btn-primary me-1")
70
- end
71
-
72
- if policy(rec).show?
73
- btns << link_to(icon(:eye),
74
- show_custom_polymorphic_path(rec),
75
- class: "btn btn-sm btn-primary me-1")
76
- end
77
-
78
- if policy(rec).destroy?
79
- btns << link_to(icon(:trash),
80
- destroy_custom_polymorphic_path(rec),
81
- data: {
82
- turbo_method: :delete,
83
- turbo_confirm: t("are_you_sure")
84
- },
85
- class: "btn btn-sm btn-danger me-1")
86
- end
87
- btns
88
- end
89
-
90
63
  ##
91
64
  # Possibile override dei parametri da passare a ransack nella form
92
65
  def search_form_for_params(ransack_instance)
@@ -100,11 +73,22 @@ Abbiamo migrato ad un sistema di rendering tramite views,
100
73
  è stato lasciato come memo per una migrazione semplificata
101
74
  nel caso si voglia renderizzare un determinato campo in modo differente dal normale dato del DB
102
75
  creare nalla path del modello la cartella cell_field e creare al suo interno il file con il nome
103
- del _campo.html.erb e quindi inserire li il rendering (ES modello User, campo :name):
76
+ del _campo.html.erb e quindi inserire il rendering (ES modello User, campo :name):
104
77
  app/views/users/user/cell_field/_campo.html.erb
105
78
  ```
106
79
  <%# locals: (obj:,field:) -%>
107
80
  <td><%= obj.name.upcase %></td>
108
81
  ```
82
+
83
+ Altrimenti in modo semplificato basta lanciare il generatore:
84
+ ```
85
+ rails g base_editing_bootstrap:cell_override ClasseModello nome_campo
86
+ ```
87
+ MESSAGE
88
+ )
89
+
90
+ BaseEditingBootstrap.deprecator.deprecate_methods(Utilities::SearchHelper, search_result_buttons: <<-MESSAGE
91
+ Come per il raw field, anche i bottoni sono stati spostati nelle viste.
92
+ Sovrascrivi la vista _search_result_buttons.html.erb
109
93
  MESSAGE
110
94
  )
@@ -0,0 +1,18 @@
1
+ <%# locals: (obj:) -%>
2
+ <%= link_to(icon("pencil-square"),
3
+ edit_custom_polymorphic_path(obj),
4
+ class: "btn btn-sm btn-primary me-1") if policy(obj).edit? %>
5
+
6
+
7
+ <%= link_to(icon(:eye),
8
+ show_custom_polymorphic_path(obj),
9
+ class: "btn btn-sm btn-primary me-1") if policy(obj).show? %>
10
+
11
+
12
+ <%= link_to(icon(:trash),
13
+ destroy_custom_polymorphic_path(obj),
14
+ data: {
15
+ turbo_method: :delete,
16
+ turbo_confirm: t("are_you_sure")
17
+ },
18
+ class: "btn btn-sm btn-danger me-1") if policy(obj).destroy? %>
@@ -3,6 +3,6 @@
3
3
  <%= render_cell_field(obj, srf) %>
4
4
  <% end %>
5
5
  <td>
6
- <%= search_result_buttons(obj) %>
6
+ <%= render partial: "search_result_buttons", locals: {obj:} %>
7
7
  </td>
8
8
  </tr>
@@ -11,8 +11,7 @@ Gem::Specification.new do |spec|
11
11
  spec.license = "MIT"
12
12
  spec.required_ruby_version = ">= 3.1"
13
13
 
14
- spec.metadata["homepage_uri"] = spec.homepage
15
- spec.metadata["source_code_uri"] = "https://github.com/oniram88/BaseEditingBootstrap"
14
+ spec.metadata["source_code_uri"] = spec.homepage
16
15
  spec.metadata["changelog_uri"] = "https://github.com/oniram88/BaseEditingBootstrap/blob/main/CHANGELOG.md"
17
16
 
18
17
  # Specify which files should be added to the gem when it is released.
@@ -48,7 +47,7 @@ Gem::Specification.new do |spec|
48
47
  spec.add_development_dependency 'rails-i18n', '~> 7.0' # For 7.0.0
49
48
  spec.add_development_dependency "i18n-debug", '~> 1.2'
50
49
  spec.add_development_dependency "cssbundling-rails", '~> 1.4'
51
- spec.add_development_dependency "rspec-parameterized", ">= 1.0.0" # https://github.com/tomykaira/rspec-parameterized
50
+ spec.add_development_dependency "rspec-parameterized", "~> 1.0", ">= 1.0.0" # https://github.com/tomykaira/rspec-parameterized
52
51
  spec.add_development_dependency 'rspec-html-matchers', '~> 0.10' # https://github.com/kucaahbe/rspec-html-matchers
53
52
  spec.add_development_dependency 'rails-controller-testing', '~>1.0'
54
53
 
@@ -1 +1 @@
1
- 0.7.0
1
+ 0.8.0
@@ -1,12 +1,6 @@
1
1
  module BaseEditingBootstrap
2
2
  class Engine < ::Rails::Engine
3
3
 
4
- config.generators do |g|
5
- g.test_framework :rspec
6
- g.fixture_replacement :factory_bot
7
- g.factory_bot dir: 'spec/factories'
8
- end
9
-
10
4
  initializer "base_editing_bootstrap.deprecator" do |app|
11
5
  app.deprecators[:base_editing_bootstrap] = BaseEditingBootstrap.deprecator
12
6
  end
@@ -18,14 +18,7 @@ module BaseEditingBootstrap
18
18
 
19
19
  def prepare_test_environment
20
20
  gem "factory_bot_rails", group: :test, version: '~> 6.4', comment: "Necessary for spec"
21
- gem 'rails-controller-testing',group: :test,comment:"Required if used with controllers spec"
22
- inject_into_class "config/application.rb", "Application", <<~RUBY
23
- config.generators do |g|
24
- g.test_framework :rspec
25
- g.fixture_replacement :factory_bot
26
- g.factory_bot dir: 'spec/factories'
27
- end
28
- RUBY
21
+ gem 'rails-controller-testing', group: :test, comment: "Required if used with controllers spec"
29
22
  end
30
23
  end
31
24
  end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BaseEditingBootstrap
4
+ module Generators
5
+ class ScaffoldGenerator < ::Rails::Generators::NamedBase
6
+ include Rails::Generators::ResourceHelpers
7
+
8
+ source_root File.expand_path("templates", __dir__)
9
+ argument :attributes, type: :array, default: [], banner: "field:type field:type"
10
+
11
+ invoke :model
12
+
13
+ def add_base_model
14
+ inject_into_class "app/models/#{model_resource_name}.rb", class_name do
15
+ " include BaseEditingBootstrap::BaseModel\n"
16
+ end
17
+
18
+ template "spec/model.rb", File.join("spec/models", "#{singular_name}_spec.rb")
19
+ end
20
+
21
+ def add_controller
22
+ opts = ["--no-helper", "--parent=BaseEditingController"]
23
+ opts << "--force" if options.force?
24
+ generate "controller", controller_class_name, *opts
25
+
26
+ route "resources :#{plural_name}"
27
+
28
+ template "spec/request.rb", File.join("spec/requests", "#{plural_file_name}_spec.rb")
29
+
30
+ end
31
+
32
+ def add_policy
33
+ @search_attrs = []
34
+ if yes? "Vuoi poter ricercare determinati campi con form di ricerca?"
35
+
36
+ say "Gli attributi che hai indicato sono: #{ attributes_names.join(",")}"
37
+ say <<~MESSAGE
38
+ La ricerca avviene tramite le logiche di ransack.
39
+ Puoi trovare la documentazione dei predicati di ricerca qua:
40
+ https://activerecord-hackery.github.io/ransack/getting-started/search-matches/
41
+ Ecco alcuni esempi di possibili modi di ricercare:
42
+ MESSAGE
43
+
44
+ matchers = {
45
+ "_eq":"Equal",
46
+ "_not_eq":"Not equal",
47
+ "_i_cont":"Contains insensitive",
48
+ }
49
+
50
+ out = [["",*matchers.values]]
51
+ attributes_names.each do |attr|
52
+ out << [attr, *matchers.keys.collect{|m| "#{attr}#{m}" } ]
53
+ end
54
+
55
+ puts out.inspect
56
+
57
+ print_table(out,borders:true)
58
+ @search_attrs = ask("Inserisce un elenco diviso da virgola degli attributi da ricercare").split(",")
59
+
60
+ end
61
+
62
+ template "policy.rb", File.join("app/policies", "#{singular_name}_policy.rb")
63
+ template "spec/policy.rb", File.join("spec/policies", "#{singular_name}_policy_spec.rb")
64
+
65
+ end
66
+
67
+
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,11 @@
1
+ class <%= class_name %>Policy < BaseModelPolicy
2
+
3
+ def editable_attributes = %w[<%= attributes_names.join(" ") %>]
4
+ def permitted_attributes = %w[<%= attributes_names.join(" ") %>]
5
+ def search_result_fields = %w[<%= attributes_names.join(" ") %>]
6
+ <%- if @search_attrs.any? -%>
7
+ def search_fields
8
+ %i[<%= @search_attrs.join(" ") %>]
9
+ end
10
+ <%- end -%>
11
+ end
@@ -0,0 +1,6 @@
1
+ require 'rails_helper'
2
+ RSpec.describe <%= class_name %>, type: :model do
3
+ it_behaves_like "a base model",
4
+ ransack_permitted_attributes: %w[<%= attributes_names.join(" ") %>],
5
+ ransack_permitted_associations: []
6
+ end
@@ -0,0 +1,5 @@
1
+ require 'rails_helper'
2
+ RSpec.describe <%= class_name %>Policy, type: :policy do
3
+ it_behaves_like "a standard base model policy", :<%=singular_name %>
4
+
5
+ end
@@ -0,0 +1,6 @@
1
+ require 'rails_helper'
2
+ RSpec.describe "<%= controller_class_name %>", type: :request do
3
+ it_behaves_like "as logged in user" do
4
+ it_behaves_like "base editing controller", factory: :<%= singular_name %>
5
+ end
6
+ 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.7.0
4
+ version: 0.8.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-05-30 00:00:00.000000000 Z
11
+ date: 2024-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -234,6 +234,9 @@ dependencies:
234
234
  name: rspec-parameterized
235
235
  requirement: !ruby/object:Gem::Requirement
236
236
  requirements:
237
+ - - "~>"
238
+ - !ruby/object:Gem::Version
239
+ version: '1.0'
237
240
  - - ">="
238
241
  - !ruby/object:Gem::Version
239
242
  version: 1.0.0
@@ -241,6 +244,9 @@ dependencies:
241
244
  prerelease: false
242
245
  version_requirements: !ruby/object:Gem::Requirement
243
246
  requirements:
247
+ - - "~>"
248
+ - !ruby/object:Gem::Version
249
+ version: '1.0'
244
250
  - - ">="
245
251
  - !ruby/object:Gem::Version
246
252
  version: 1.0.0
@@ -320,6 +326,7 @@ files:
320
326
  - app/views/base_editing/_search_field.erb
321
327
  - app/views/base_editing/_search_footer.html.erb
322
328
  - app/views/base_editing/_search_result.html.erb
329
+ - app/views/base_editing/_search_result_buttons.html.erb
323
330
  - app/views/base_editing/_search_result_row.html.erb
324
331
  - app/views/base_editing/_tabs.html.erb
325
332
  - app/views/base_editing/cell_field/_base.html.erb
@@ -359,6 +366,11 @@ files:
359
366
  - lib/generators/base_editing_bootstrap/install/USAGE
360
367
  - lib/generators/base_editing_bootstrap/install/install_generator.rb
361
368
  - lib/generators/base_editing_bootstrap/install/templates/initializer.rb
369
+ - lib/generators/base_editing_bootstrap/scaffold/scaffold_generator.rb
370
+ - lib/generators/base_editing_bootstrap/scaffold/templates/policy.rb.tt
371
+ - lib/generators/base_editing_bootstrap/scaffold/templates/spec/model.rb.tt
372
+ - lib/generators/base_editing_bootstrap/scaffold/templates/spec/policy.rb.tt
373
+ - lib/generators/base_editing_bootstrap/scaffold/templates/spec/request.rb.tt
362
374
  - lib/tasks/base_editing_bootstrap_tasks.rake
363
375
  - spec/support/external_shared/base_editing_controller_helpers.rb
364
376
  - spec/support/external_shared/base_model.rb
@@ -368,7 +380,6 @@ homepage: https://github.com/oniram88/BaseEditingBootstrap
368
380
  licenses:
369
381
  - MIT
370
382
  metadata:
371
- homepage_uri: https://github.com/oniram88/BaseEditingBootstrap
372
383
  source_code_uri: https://github.com/oniram88/BaseEditingBootstrap
373
384
  changelog_uri: https://github.com/oniram88/BaseEditingBootstrap/blob/main/CHANGELOG.md
374
385
  post_install_message: