pg_rails 7.0.1 → 7.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +6 -4
  3. data/pg_associable/app/assets/css/pg_associable.scss +99 -0
  4. data/pg_associable/app/assets/js/asociable_controller.js +59 -0
  5. data/pg_associable/app/assets/js/asociable_inline_controller.js +141 -0
  6. data/pg_associable/app/assets/js/modal_controller.js +130 -0
  7. data/pg_associable/app/helpers/pg_associable/form_builder_methods.rb +31 -0
  8. data/pg_associable/app/helpers/pg_associable/helpers.rb +19 -0
  9. data/pg_associable/app/inputs/pg_associable/pg_associable_inline_input.rb +39 -0
  10. data/pg_associable/app/inputs/pg_associable/pg_associable_input.rb +41 -0
  11. data/pg_associable/app/views/pg_associable/_resultados.html.slim +9 -0
  12. data/pg_associable/app/views/pg_associable/_resultados_inline.html.slim +12 -0
  13. data/pg_associable/app/views/pg_engine/base/_pg_associable_modal.html.slim +39 -0
  14. data/pg_associable/index.js +7 -0
  15. data/pg_associable/lib/pg_associable/engine.rb +12 -0
  16. data/pg_associable/lib/pg_associable/simple_form_initializer.rb +34 -0
  17. data/pg_associable/lib/pg_associable.rb +5 -0
  18. data/{lib/tasks/pg_rails_tasks.rake → pg_associable/lib/tasks/pg_associable_tasks.rake} +1 -2
  19. data/pg_engine/app/assets/stylesheets/pg_rails_b5.scss +74 -0
  20. data/pg_engine/app/controllers/pg_engine/base_controller.rb +365 -0
  21. data/pg_engine/app/controllers/pg_engine/devise_controller.rb +9 -0
  22. data/pg_engine/app/controllers/pg_engine/signed_in_controller.rb +7 -0
  23. data/{app/decorators/pg_rails → pg_engine/app/decorators/pg_engine}/base_decorator.rb +21 -23
  24. data/pg_engine/app/helpers/pg_engine/flash_helper.rb +26 -0
  25. data/pg_engine/app/helpers/pg_engine/form_helper.rb +33 -0
  26. data/pg_engine/app/helpers/pg_engine/index_helper.rb +42 -0
  27. data/{app/helpers/pg_rails → pg_engine/app/helpers/pg_engine}/postgres_helper.rb +1 -1
  28. data/{app/helpers/pg_rails → pg_engine/app/helpers/pg_engine}/print_helper.rb +15 -31
  29. data/pg_engine/app/helpers/pg_engine/route_helper.rb +41 -0
  30. data/pg_engine/app/inputs/pg_engine/fecha_input.rb +20 -0
  31. data/{app/lib/pg_rails → pg_engine/app/lib/pg_engine}/filtros_builder.rb +16 -17
  32. data/pg_engine/app/lib/pg_form_builder.rb +22 -0
  33. data/pg_engine/app/models/pg_engine/base_record.rb +63 -0
  34. data/{app/policies/pg_rails → pg_engine/app/policies/pg_engine}/application_policy.rb +2 -2
  35. data/pg_engine/app/views/pg_engine/base/download.xlsx.axlsx +14 -0
  36. data/pg_engine/app/views/pg_engine/base/index.html.slim +51 -0
  37. data/pg_engine/config/locales/es.yml +48 -0
  38. data/pg_engine/config/simple_form/simple_form.rb +178 -0
  39. data/pg_engine/config/simple_form/simple_form_bootstrap.rb +371 -0
  40. data/{lib/pg_rails → pg_engine/lib/pg_engine}/configuracion.rb +3 -1
  41. data/pg_engine/lib/pg_engine/engine.rb +53 -0
  42. data/{lib/pg_rails → pg_engine/lib/pg_engine}/utils/logueador.rb +8 -1
  43. data/pg_engine/lib/pg_engine.rb +35 -0
  44. data/{lib → pg_engine/lib}/tasks/auto_anotar_modelos.rake +1 -1
  45. data/pg_engine/lib/templates/activeadmin/audits.rb +53 -0
  46. data/pg_engine/lib/templates/activeadmin/users.rb +54 -0
  47. data/pg_layout/app/assets/stylesheets/sidebar.scss +106 -0
  48. data/pg_layout/app/javascript/cookies.js +23 -0
  49. data/pg_layout/app/javascript/navbar_controller.js +10 -0
  50. data/pg_layout/app/lib/navbar.rb +61 -0
  51. data/pg_layout/app/views/devise/confirmations/new.html.erb +20 -0
  52. data/pg_layout/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
  53. data/pg_layout/app/views/devise/mailer/email_changed.html.erb +7 -0
  54. data/pg_layout/app/views/devise/mailer/password_change.html.erb +3 -0
  55. data/pg_layout/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
  56. data/pg_layout/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
  57. data/pg_layout/app/views/devise/passwords/edit.html.erb +27 -0
  58. data/pg_layout/app/views/devise/passwords/new.html.erb +18 -0
  59. data/pg_layout/app/views/devise/registrations/edit.html.erb +35 -0
  60. data/pg_layout/app/views/devise/registrations/new.html.erb +25 -0
  61. data/pg_layout/app/views/devise/sessions/new.html.erb +20 -0
  62. data/pg_layout/app/views/devise/shared/_error_messages.html.erb +15 -0
  63. data/pg_layout/app/views/devise/shared/_links.html.erb +25 -0
  64. data/pg_layout/app/views/devise/unlocks/new.html.erb +19 -0
  65. data/pg_layout/app/views/kaminari/_first_page.html.slim +3 -0
  66. data/pg_layout/app/views/kaminari/_gap.html.slim +2 -0
  67. data/pg_layout/app/views/kaminari/_last_page.html.slim +3 -0
  68. data/pg_layout/app/views/kaminari/_next_page.html.slim +3 -0
  69. data/pg_layout/app/views/kaminari/_page.html.slim +6 -0
  70. data/pg_layout/app/views/kaminari/_paginator.html.slim +12 -0
  71. data/pg_layout/app/views/kaminari/_prev_page.html.slim +3 -0
  72. data/pg_layout/app/views/layouts/pg_layout/devise.html.slim +24 -0
  73. data/pg_layout/app/views/layouts/pg_layout/layout.html.slim +30 -0
  74. data/pg_layout/app/views/pg_layout/_flash.html.slim +10 -0
  75. data/pg_layout/app/views/pg_layout/_navbar.html.erb +43 -0
  76. data/pg_layout/app/views/pg_layout/_sidebar.html.erb +42 -0
  77. data/pg_layout/index.js +35 -0
  78. data/pg_layout/lib/pg_layout/engine.rb +7 -0
  79. data/pg_layout/lib/pg_layout.rb +9 -0
  80. data/pg_rails/js/index.js +2 -0
  81. data/pg_rails/lib/pg_rails.rb +7 -0
  82. data/{lib/pg_rails → pg_rails/lib}/version.rb +1 -1
  83. data/pg_rails/scss/pg_rails.scss +3 -0
  84. data/pg_scaffold/lib/generators/pg_active_record/model/model_generator.rb +34 -0
  85. data/pg_scaffold/lib/generators/pg_active_record/model/templates/admin.rb +19 -0
  86. data/pg_scaffold/lib/generators/pg_active_record/model/templates/create_table_migration.rb.tt +46 -0
  87. data/pg_scaffold/lib/generators/pg_active_record/model/templates/migration.rb.tt +48 -0
  88. data/pg_scaffold/lib/generators/pg_active_record/model/templates/model.rb +47 -0
  89. data/pg_scaffold/lib/generators/pg_active_record/model/templates/module.rb +9 -0
  90. data/pg_scaffold/lib/generators/pg_decorator/USAGE +8 -0
  91. data/pg_scaffold/lib/generators/pg_decorator/pg_decorator_generator.rb +31 -0
  92. data/pg_scaffold/lib/generators/pg_decorator/templates/decorator.rb +22 -0
  93. data/pg_scaffold/lib/generators/pg_factory_bot/model/model_generator.rb +95 -0
  94. data/pg_scaffold/lib/generators/pg_factory_bot/model/templates/factories.erb +14 -0
  95. data/pg_scaffold/lib/generators/pg_pundit/USAGE +8 -0
  96. data/pg_scaffold/lib/generators/pg_pundit/pg_pundit_generator.rb +21 -0
  97. data/pg_scaffold/lib/generators/pg_pundit/templates/policy.rb +37 -0
  98. data/pg_scaffold/lib/generators/pg_rails/instalar/USAGE +8 -0
  99. data/pg_scaffold/lib/generators/pg_rails/instalar/instalar_generator.rb +17 -0
  100. data/pg_scaffold/lib/generators/pg_rails/instalar/templates/pg_rails.rb +10 -0
  101. data/pg_scaffold/lib/generators/pg_resource_route/pg_resource_route_generator.rb +27 -0
  102. data/pg_scaffold/lib/generators/pg_rspec/model/model_generator.rb +30 -0
  103. data/pg_scaffold/lib/generators/pg_rspec/model/templates/model_spec.rb +15 -0
  104. data/pg_scaffold/lib/generators/pg_rspec/scaffold/scaffold_generator.rb +43 -0
  105. data/pg_scaffold/lib/generators/pg_rspec/scaffold/templates/api_controller_spec.rb +167 -0
  106. data/pg_scaffold/lib/generators/pg_rspec/scaffold/templates/controller_spec.rb +269 -0
  107. data/pg_scaffold/lib/generators/pg_rspec/scaffold/templates/edit_spec.rb +34 -0
  108. data/pg_scaffold/lib/generators/pg_rspec/scaffold/templates/index_spec.rb +28 -0
  109. data/pg_scaffold/lib/generators/pg_rspec/scaffold/templates/new_spec.rb +34 -0
  110. data/pg_scaffold/lib/generators/pg_rspec/scaffold/templates/routing_spec.rb +50 -0
  111. data/pg_scaffold/lib/generators/pg_rspec/scaffold/templates/show_spec.rb +26 -0
  112. data/pg_scaffold/lib/generators/pg_scaffold/USAGE +8 -0
  113. data/pg_scaffold/lib/generators/pg_scaffold/pg_scaffold_generator.rb +87 -0
  114. data/pg_scaffold/lib/generators/pg_scaffold/templates/controller.rb +37 -0
  115. data/pg_scaffold/lib/generators/pg_slim/USAGE +8 -0
  116. data/pg_scaffold/lib/generators/pg_slim/pg_slim_generator.rb +31 -0
  117. data/pg_scaffold/lib/generators/pg_slim/templates/_form.html.slim +12 -0
  118. data/pg_scaffold/lib/generators/pg_slim/templates/download.xlsx.axlsx +14 -0
  119. data/pg_scaffold/lib/generators/pg_slim/templates/edit.html.slim +5 -0
  120. data/pg_scaffold/lib/generators/pg_slim/templates/index.html.slim +51 -0
  121. data/pg_scaffold/lib/generators/pg_slim/templates/new.html.slim +5 -0
  122. data/pg_scaffold/lib/generators/pg_slim/templates/partial.html.slim +1 -0
  123. data/pg_scaffold/lib/generators/pg_slim/templates/show.html.slim +38 -0
  124. data/pg_scaffold/lib/pg_scaffold/monkey_patches/mejoras_a_named_base.rb +37 -0
  125. data/pg_scaffold/lib/pg_scaffold/monkey_patches/mejoras_de_atributos.rb +116 -0
  126. data/pg_scaffold/lib/pg_scaffold/railtie.rb +16 -0
  127. data/pg_scaffold/lib/pg_scaffold.rb +4 -0
  128. metadata +134 -48
  129. data/Rakefile +0 -36
  130. data/app/assets/javascripts/pg_rails/asociacion_creable.js +0 -85
  131. data/app/assets/javascripts/pg_rails/best_in_place_datepicker.js +0 -58
  132. data/app/assets/javascripts/pg_rails/librerias.js +0 -13
  133. data/app/assets/javascripts/pg_rails/librerias_b3.js +0 -14
  134. data/app/assets/javascripts/pg_rails/validaciones.js +0 -44
  135. data/app/assets/javascripts/pg_rails.js +0 -318
  136. data/app/assets/stylesheets/pg_rails/librerias.scss +0 -5
  137. data/app/assets/stylesheets/pg_rails/pg_chosen.scss +0 -29
  138. data/app/assets/stylesheets/pg_rails/pg_rails.scss +0 -199
  139. data/app/assets/stylesheets/pg_rails_b3.scss +0 -10
  140. data/app/assets/stylesheets/pg_rails_b4.scss +0 -12
  141. data/app/assets/stylesheets/pg_rails_b5.scss +0 -1
  142. data/app/controllers/pg_rails/application_controller.rb +0 -316
  143. data/app/controllers/pg_rails/editar_en_lugar_controller.rb +0 -24
  144. data/app/helpers/pg_rails/editar_en_lugar_helper.rb +0 -106
  145. data/app/helpers/pg_rails/form_helper.rb +0 -25
  146. data/app/inputs/pg_rails/asociacion_creable_input.rb +0 -72
  147. data/app/inputs/pg_rails/fecha_input.rb +0 -20
  148. data/app/inputs/pg_rails/selects_dependientes_input.rb +0 -9
  149. data/app/lib/pg_form_builder.rb +0 -31
  150. data/app/models/pg_rails/application_record.rb +0 -51
  151. data/app/views/application/_abrir_modal.js.erb +0 -14
  152. data/app/views/application/_actualizar_smart_listing.html.slim +0 -3
  153. data/app/views/application/_cerrar_modal.js.erb +0 -8
  154. data/app/views/application/_modal_ajax_form.js.erb +0 -7
  155. data/config/brakeman.ignore +0 -42
  156. data/config/locales/es.yml +0 -17
  157. data/config/routes.rb +0 -3
  158. data/config/spring.rb +0 -1
  159. data/lib/pg_rails/engine.rb +0 -42
  160. data/lib/pg_rails/simple_form/initializer.rb +0 -583
  161. data/lib/pg_rails.rb +0 -23
  162. /data/{lib/pg_rails → pg_engine/lib/pg_engine}/core_ext.rb +0 -0
@@ -0,0 +1,50 @@
1
+ # generado con pg_rails
2
+
3
+ require "rails_helper"
4
+
5
+ <% module_namespacing do -%>
6
+ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:routing) %> do
7
+ describe "routing" do
8
+ <% unless options[:singleton] -%>
9
+ it "routes to #index" do
10
+ expect(:get => "/<%= ns_table_name %>").to route_to("<%= ns_table_name %>#index")
11
+ end
12
+
13
+ <% end -%>
14
+ <% unless options[:api] -%>
15
+ it "routes to #new" do
16
+ expect(:get => "/<%= ns_table_name %>/new").to route_to("<%= ns_table_name %>#new")
17
+ end
18
+
19
+ <% end -%>
20
+ it "routes to #show" do
21
+ expect(:get => "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#show", :id => "1")
22
+ end
23
+
24
+ <% unless options[:api] -%>
25
+ it "routes to #edit" do
26
+ expect(:get => "/<%= ns_table_name %>/1/edit").to route_to("<%= ns_table_name %>#edit", :id => "1")
27
+ end
28
+
29
+ <% end -%>
30
+
31
+ it "routes to #create" do
32
+ expect(:post => "/<%= ns_table_name %>").to route_to("<%= ns_table_name %>#create")
33
+ end
34
+
35
+ it "routes to #update via PUT" do
36
+ expect(:put => "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#update", :id => "1")
37
+ end
38
+
39
+ <% if Rails::VERSION::STRING > '4' -%>
40
+ it "routes to #update via PATCH" do
41
+ expect(:patch => "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#update", :id => "1")
42
+ end
43
+
44
+ <% end -%>
45
+ it "routes to #destroy" do
46
+ expect(:delete => "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#destroy", :id => "1")
47
+ end
48
+ end
49
+ end
50
+ <% end -%>
@@ -0,0 +1,26 @@
1
+ # generado con pg_rails
2
+
3
+ require 'rails_helper'
4
+
5
+ <% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
6
+ RSpec.describe "<%= ruta_vistas %>/show", <%= type_metatag(:view) %> do
7
+ PgEngine::ConfiguradorRSpec.helpers(self)
8
+ <% if mountable_engine? -%>
9
+ helper <%= mountable_engine? %>::Engine.routes.url_helpers
10
+ <% end -%>
11
+
12
+ let(:user) { create(:user, :admin) }
13
+
14
+ before(:each) do
15
+ sign_in user
16
+ @<%= singular_name %> = assign(:<%= singular_name %>, create(:<%= nombre_tabla_completo_singular %>).decorate)
17
+ @clase_modelo = assign(:clase_modelo, <%= nombre_clase_completo %>)
18
+ end
19
+
20
+ it "renders attributes in <p>" do
21
+ render
22
+ <% for attribute in output_attributes -%>
23
+ expect(rendered).to match(/<%= raw_value_for(attribute).try :capitalize %>/)
24
+ <% end -%>
25
+ end
26
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate mi_scaffold Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,87 @@
1
+ # frozen_string_literal: true
2
+
3
+ class PgScaffoldGenerator < Rails::Generators::NamedBase
4
+ source_root File.expand_path('templates', __dir__)
5
+
6
+ include Rails::Generators::ResourceHelpers
7
+
8
+ class_option :orm, banner: 'NAME', type: :string, required: true,
9
+ desc: 'ORM to generate the controller for'
10
+
11
+ class_option :decorator, type: :boolean, default: true, desc: 'Generate view specs'
12
+
13
+ class_option :paranoia, type: :boolean, default: false, desc: 'Paranoid y deleted_at.'
14
+ class_option :discard, type: :boolean, default: false, desc: 'Discard y discarded_at.'
15
+ class_option :trackeo_de_usuarios, type: :boolean, default: true,
16
+ desc: 'Genera campos creado_por y actualizado_por.'
17
+
18
+ argument :attributes, type: :array, default: [], banner: 'field:type field:type'
19
+
20
+ def create_controller_files
21
+ template 'controller.rb',
22
+ File.join('app/controllers', controller_class_path,
23
+ "#{controller_file_name}_controller.rb")
24
+ end
25
+
26
+ hook_for :test_framework, as: :scaffold
27
+
28
+ invoke :model
29
+ invoke :pg_resource_route
30
+ invoke :pg_slim
31
+
32
+ def decorator
33
+ invoke :pg_decorator if options[:decorator]
34
+ end
35
+
36
+ invoke :pg_pundit
37
+
38
+ def print_output
39
+ puts "
40
+ !!!
41
+ - Agregar al locale: es.yml:
42
+ #{singular_table_name}:
43
+ one: #{singular_table_name.titleize}
44
+ other: #{plural_table_name.titleize}
45
+
46
+ - Chequear parent class de #{controller_class_name.split('::').last}
47
+ "
48
+ end
49
+
50
+ private
51
+
52
+ def get_class(class_name)
53
+ Module.const_get(class_name)
54
+ rescue NameError
55
+ nil
56
+ end
57
+
58
+ def parent_controller
59
+ parts = controller_class_name.split('::')
60
+ if parts.length > 1
61
+ if get_class "#{parts.first}Controller"
62
+ "#{parts.first}Controller"
63
+ else
64
+ 'PgEngine::SignedInController'
65
+ end
66
+ else
67
+ 'PgEngine::SignedInController'
68
+ end
69
+ end
70
+
71
+ def atributos_a_filtrar
72
+ attributes
73
+ end
74
+
75
+ # :doc:
76
+ def module_namespacing_2(&)
77
+ content = capture(&)
78
+ content = wrap_with_namespace_2(content)
79
+ concat(content)
80
+ end
81
+
82
+ # :doc:
83
+ def wrap_with_namespace_2(content)
84
+ content = indent(content).chomp
85
+ "module #{controller_class_name.split('::').first}\n#{content}\nend\n"
86
+ end
87
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ # generado con pg_rails
4
+
5
+ <% if namespaced? -%>
6
+ require_dependency "<%= namespaced_path %>/application_controller"
7
+
8
+ <% end -%>
9
+ <% module_namespacing_2 do -%>
10
+ class <%= controller_class_name.split('::').last %>Controller < <%= parent_controller %>
11
+ before_action { @clase_modelo = <%= class_name %> }
12
+
13
+ before_action(only: :index) { authorize <%= class_name %> }
14
+
15
+ before_action :set_instancia_modelo, only: %i[new create show edit update destroy]
16
+
17
+ add_breadcrumb <%= class_name %>.nombre_plural, :<%= plural_route_name %>_path
18
+
19
+ private
20
+
21
+ def atributos_permitidos
22
+ %i[<%= attributes_names.join(' ') %>]
23
+ end
24
+
25
+ def atributos_para_buscar
26
+ %i[<%= atributos_a_filtrar.map(&:name).join(' ') %>]
27
+ end
28
+
29
+ def atributos_para_listar
30
+ %i[<%= atributos_a_filtrar.map(&:name).join(' ') %>]
31
+ end
32
+
33
+ def atributos_para_mostrar
34
+ %i[<%= atributos_a_filtrar.map(&:name).join(' ') %>]
35
+ end
36
+ end
37
+ <% end -%>
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate pg_slim Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'generators/slim/scaffold/scaffold_generator'
4
+
5
+ class PgSlimGenerator < Slim::Generators::ScaffoldGenerator
6
+ source_root File.expand_path('templates', __dir__)
7
+
8
+ class_option :paranoia, type: :boolean, default: false, desc: 'Paranoid y deleted_at.'
9
+ class_option :discard, type: :boolean, default: false, desc: 'Discard y discarded_at.'
10
+ class_option :trackeo_de_usuarios, type: :boolean, default: true,
11
+ desc: 'Genera campos creado_por y actualizado_por.'
12
+ class_option :download_file, type: :boolean, default: false, desc: 'Archivo de download'
13
+ class_option :index_file, type: :boolean, default: false, desc: 'Archivo de index'
14
+
15
+ def copiar_download
16
+ return unless options[:download_file]
17
+
18
+ template 'download.xlsx.axlsx',
19
+ File.join('app', 'views', controller_file_path, 'download.xlsx.axlsx')
20
+ end
21
+
22
+ protected
23
+
24
+ def available_views
25
+ if options[:index_file]
26
+ %w[index edit show new _form]
27
+ else
28
+ %w[edit show new _form]
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,12 @@
1
+ / # locals: (object: nil, asociable: false)
2
+
3
+ div style="max-width: 300px"
4
+ = pg_form_for(@<%= singular_name %> || object) do |f|
5
+ = f.mensajes_de_error
6
+
7
+ = hidden_field_tag :asociable, true if asociable
8
+ <%- attributes.each do |attribute| -%>
9
+ = f.<%= attribute.reference? ? :pg_associable_inline : :input %> :<%= attribute.name %>
10
+ <%- end -%>
11
+ .mt-2
12
+ = f.button :submit
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ wb = xlsx_package.workbook
4
+ wb.add_worksheet(name: '<%= human_name %>') do |sheet|
5
+ sheet.add_row [
6
+ <%= attributes.map {|attribute| "@clase_modelo.human_attribute_name(:#{ attribute.name })" }.join(",\n ") %>
7
+ ]
8
+
9
+ @<%= plural_name %>.decorate.each do |<%= singular_name %>|
10
+ sheet.add_row [
11
+ <%= attributes.map {|attribute| "#{ singular_name }.#{ attribute.name }" }.join(",\n ") %>
12
+ ]
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ - content_for :title do
2
+ | Modificar #{@clase_modelo.nombre_singular.downcase}
3
+
4
+ .p-3
5
+ = render 'form'
@@ -0,0 +1,51 @@
1
+ - content_for(:title, @clase_modelo.nombre_plural)
2
+ - content_for :actions do
3
+ button.btn.btn-sm.btn-primary[type="button" data-bs-toggle="collapse"
4
+ data-bs-target="#filtros" aria-expanded="false"
5
+ aria-controls="filtros"]
6
+ span.bi.bi-funnel-fill
7
+ span.d-none.d-sm-inline Filtrar
8
+ .ms-1
9
+ = @clase_modelo.new.decorate.new_link
10
+ .ms-1
11
+ = @clase_modelo.new.decorate.export_link(request.url)
12
+ .collapse.p-2.border-bottom#filtros class="#{ 'show' if any_filter? }"
13
+ .d-flex.align-items-center
14
+ .px-2.d-none.d-sm-inline-block
15
+ span.bi.bi-funnel-fill
16
+ = form_tag nil, class: '', method: :get do
17
+ .row.g-1
18
+ = @filtros.filtros_html
19
+ .col-auto
20
+ = button_tag class: 'btn btn-sm btn-primary col-auto' do
21
+ span.bi.bi-search
22
+ .col-auto
23
+ = link_to <%= plural_route_name %>_path(clean: true),
24
+ class: 'btn btn-sm btn-secondary col-auto' do
25
+ | Limpiar
26
+
27
+ div
28
+ - if @collection.any?
29
+ .table-responsive
30
+ table.table.table-sm.listado.xpg-revert-width.xborder-end
31
+ caption.ps-3 = page_entries_info @collection
32
+ thead.table-light
33
+ tr
34
+ - atributos_para_listar.each do |att|
35
+ th = encabezado att, ordenable: true
36
+ th
37
+ tbody
38
+ - @collection.each do |object|
39
+ - object = object.decorate
40
+ tr id="#{dom_id(object)}"
41
+ - atributos_para_listar.each do |att|
42
+ th = object.send(att)
43
+ td.text-nowrap.text-end.ps-5
44
+ = object.show_link
45
+ = object.edit_link
46
+ = object.destroy_link
47
+
48
+ .ps-3.justify-content-center
49
+ = paginate(@collection)
50
+ - else
51
+ p.m-3 No hay #{@clase_modelo.nombre_plural.downcase} que mostrar
@@ -0,0 +1,5 @@
1
+ - content_for :title do
2
+ | Crear #{@clase_modelo.nombre_singular.downcase}
3
+
4
+ .p-3
5
+ = render 'form'
@@ -0,0 +1,38 @@
1
+ - content_for :title do
2
+ = @<%= singular_name %>.to_s
3
+ - content_for :actions do
4
+ = @<%= singular_name %>.destroy_link
5
+ .ms-1
6
+ = @<%= singular_name %>.edit_link
7
+
8
+ table.table.table-borderless.table-sm.w-auto.mb-0.m-3
9
+ - atributos_para_mostrar.each do |att|
10
+ tr
11
+ th = @clase_modelo.human_attribute_name(att)
12
+ td = @<%= singular_name %>.send(att)
13
+ <%- if options[:trackeo_de_usuarios] -%>
14
+ tr
15
+ th = t('attributes.creado_por')
16
+ td = @<%= singular_name %>.creado_por
17
+ <%- end -%>
18
+ tr
19
+ th = t('attributes.created_at')
20
+ td = dmy_time @<%= singular_name %>.created_at
21
+ <%- if options[:trackeo_de_usuarios] -%>
22
+ tr
23
+ th = t('attributes.actualizado_por')
24
+ td = @<%= singular_name %>.actualizado_por
25
+ <%- end -%>
26
+ tr
27
+ th = t('attributes.updated_at')
28
+ td = dmy_time @<%= singular_name %>.updated_at
29
+ <%- if options[:paranoia] -%>
30
+ tr
31
+ th = t('attributes.deleted_at')
32
+ td = dmy_time @<%= singular_name %>.deleted_at
33
+ <%- end -%>
34
+ <%- if options[:discard] -%>
35
+ tr
36
+ th = t('attributes.discarded_at')
37
+ td = dmy_time @<%= singular_name %>.discarded_at
38
+ <%- end -%>
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/generators/named_base'
4
+
5
+ module Rails
6
+ module Generators
7
+ class NamedBase < Base
8
+ def nombre_clase_completo
9
+ # if namespaced?
10
+ # (namespaced_class_path + [file_name]).map!(&:camelize).join('::')
11
+ # else
12
+ # (regular_class_path + [file_name]).map!(&:camelize).join('::')
13
+ # end
14
+ file_name.camelize
15
+ end
16
+
17
+ def nombre_tabla_completo_singular
18
+ if namespaced?
19
+ (namespaced_class_path + [singular_name]).join('_')
20
+ else
21
+ (regular_class_path + [singular_name]).join('_')
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ # Deprecado?
28
+ def ruta_vistas
29
+ if namespaced?
30
+ namespaced_class_path.dup.push(plural_name).join('/')
31
+ else
32
+ regular_class_path.dup.push(plural_name).join('/')
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,116 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/generators'
4
+ require 'rails/generators/generated_attribute'
5
+ require 'generators/rspec'
6
+
7
+ module Rails
8
+ module Generators
9
+ class GeneratedAttribute # :nodoc:
10
+ class << self
11
+ private
12
+
13
+ def parse_type_and_options(type)
14
+ case type
15
+ when /(string|text|binary|integer)\{(\d+)\}/
16
+ [Regexp.last_match(1), { limit: Regexp.last_match(2).to_i }]
17
+ when /(string|text|binary|float|integer|date|datetime)\{(.+)\}/
18
+ type = Regexp.last_match(1)
19
+ provided_options = Regexp.last_match(2).split(/[,.-]/)
20
+ options = provided_options.to_h { |opt| [opt.to_sym, true] }
21
+ [type, options]
22
+ when /decimal\{(\d+)[,.-](\d+)\}/
23
+ [:decimal, { precision: Regexp.last_match(1).to_i, scale: Regexp.last_match(2).to_i }]
24
+ when /(references|belongs_to)\{(.+)\}/
25
+ type = Regexp.last_match(1)
26
+ provided_options = Regexp.last_match(2).split(/[,.-]/)
27
+ options = provided_options.to_h { |opt| parsear_opcion(opt) }
28
+
29
+ # si es referencia le mando índice siempre
30
+ options[:index] = true
31
+ [type, options]
32
+ else
33
+ [type, {}]
34
+ end
35
+ end
36
+
37
+ def parsear_opcion(opcion)
38
+ partes = opcion.split('=')
39
+ if partes.count == 2
40
+ [partes[0].to_sym, partes[1]]
41
+ else
42
+ [opcion.to_sym, true]
43
+ end
44
+ end
45
+ end
46
+
47
+ def clase_con_modulo
48
+ return name.camelize unless tiene_nombre_de_clase_explicito?
49
+
50
+ @attr_options[:clase].gsub('/', '::')
51
+ end
52
+
53
+ # def tiene_modulo?
54
+ # @attr_options[:modulo].present?
55
+ # end
56
+
57
+ def tiene_nombre_de_clase_explicito?
58
+ @attr_options[:clase].present?
59
+ end
60
+
61
+ # def tiene_tabla?
62
+ # @attr_options[:tabla].present?
63
+ # end
64
+
65
+ def es_enum?
66
+ @attr_options[:enum].present?
67
+ end
68
+
69
+ def tabla_referenciada_singular
70
+ return singular_name unless tiene_nombre_de_clase_explicito?
71
+
72
+ @attr_options[:clase].gsub('/', '').underscore
73
+ end
74
+
75
+ def tabla_referenciada
76
+ return plural_name unless tiene_nombre_de_clase_explicito?
77
+
78
+ @attr_options[:clase].gsub('/', '').underscore.pluralize
79
+ end
80
+
81
+ # pisa geneators/rspec
82
+ def input_type
83
+ @input_type ||= if type == :text
84
+ 'textarea'
85
+ elsif es_enum? || type == :references
86
+ 'select'
87
+ else
88
+ 'input'
89
+ end
90
+ end
91
+
92
+ def required?
93
+ attr_options[:required]
94
+ end
95
+
96
+ private
97
+
98
+ def options_for_migration
99
+ @attr_options.dup.tap do |options|
100
+ if required?
101
+ options.delete(:required)
102
+ options[:null] = false
103
+ end
104
+
105
+ if reference? && !polymorphic? && !tiene_nombre_de_clase_explicito?
106
+ options[:foreign_key] =
107
+ true
108
+ end
109
+ # options.delete(:modulo)
110
+ options.delete(:enum)
111
+ options.delete(:clase)
112
+ end
113
+ end
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,16 @@
1
+ module PgScaffold
2
+ class Railtie < ::Rails::Railtie
3
+ initializer 'configurar_generators', after: 'factory_bot.set_fixture_replacement' do
4
+ require_relative 'monkey_patches/mejoras_de_atributos'
5
+ require_relative 'monkey_patches/mejoras_a_named_base'
6
+
7
+ config.app_generators do |g|
8
+ g.test_framework :pg_rspec
9
+ g.orm :pg_active_record
10
+
11
+ g.fallbacks[:pg_rspec] = :rspec
12
+ g.fallbacks[:pg_active_record] = :active_record
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,4 @@
1
+ require_relative 'pg_scaffold/railtie'
2
+
3
+ module PgScaffold
4
+ end