plutonium 0.10.2 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (228) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -0
  3. data/Rakefile +1 -2
  4. data/app/assets/application.js.bk +31419 -0
  5. data/app/assets/plutonium-logo-original.png +0 -0
  6. data/app/assets/plutonium-logo-white.png +0 -0
  7. data/app/assets/plutonium-logo.png +0 -0
  8. data/app/assets/plutonium.css +1 -0
  9. data/app/assets/plutonium.ico +0 -0
  10. data/app/assets/plutonium.js +12416 -0
  11. data/app/assets/plutonium.js.map +7 -0
  12. data/app/assets/plutonium.min.js +39 -0
  13. data/app/assets/plutonium.min.js.map +7 -0
  14. data/app/views/application/_flash_alerts.html.erb +5 -2
  15. data/app/views/application/_flash_toasts.html.erb +2 -0
  16. data/app/views/application/_resource_header.html.erb +263 -697
  17. data/app/views/application/_resource_sidebar.html.erb +14 -12
  18. data/app/views/components/action_button/action_button_component.rb +3 -3
  19. data/app/views/components/attributes.rb +184 -0
  20. data/app/views/components/base.rb +19 -40
  21. data/app/views/components/block/block_component.html.erb +1 -1
  22. data/app/views/components/block/block_component.rb +11 -7
  23. data/app/views/components/breadcrumbs/breadcrumbs_component.rb +3 -3
  24. data/app/views/components/button/button_component.html.erb +2 -2
  25. data/app/views/components/button/button_component.rb +10 -5
  26. data/app/views/components/dyna_frame_content/dyna_frame_content_component.html.erb +1 -0
  27. data/app/views/components/dyna_frame_content/dyna_frame_content_component.rb +3 -3
  28. data/app/views/components/dyna_frame_host/dyna_frame_host_component.html.erb +1 -2
  29. data/app/views/components/dyna_frame_host/dyna_frame_host_component.rb +12 -5
  30. data/app/views/components/empty_card/empty_card_component.rb +3 -3
  31. data/app/views/components/form/form_builder.rb +1 -1
  32. data/app/views/components/form/form_component.rb +3 -3
  33. data/app/views/components/has_many_panel/has_many_panel_component.html.erb +25 -0
  34. data/app/views/components/has_many_panel/has_many_panel_component.rb +16 -0
  35. data/app/views/components/header/header_component.rb +3 -3
  36. data/app/views/components/interactive_action_form/interactive_action_form_component.rb +3 -3
  37. data/app/views/components/nav_grid_menu/nav_grid_menu_component.html.erb +24 -0
  38. data/app/views/components/nav_grid_menu/nav_grid_menu_component.rb +23 -0
  39. data/app/views/components/nav_grid_menu_item/nav_grid_menu_item_component.html.erb +4 -0
  40. data/app/views/components/nav_grid_menu_item/nav_grid_menu_item_component.rb +20 -0
  41. data/app/views/components/nav_user/nav_user_component.html.erb +50 -0
  42. data/app/views/components/nav_user/nav_user_component.rb +32 -0
  43. data/app/views/components/nav_user_link/nav_user_link_component.html.erb +7 -0
  44. data/app/views/components/nav_user_link/nav_user_link_component.rb +23 -0
  45. data/app/views/components/nav_user_section/nav_user_section_component.html.erb +7 -0
  46. data/app/views/components/nav_user_section/nav_user_section_component.rb +18 -0
  47. data/app/views/components/nested_resource_form_fields/nested_resource_form_fields_component.html.erb +1 -3
  48. data/app/views/components/nested_resource_form_fields/nested_resource_form_fields_component.rb +11 -5
  49. data/app/views/components/pagination/pagination_component.html.erb +1 -1
  50. data/app/views/components/pagination/pagination_component.rb +10 -7
  51. data/app/views/components/panel/panel_component.html.erb +13 -6
  52. data/app/views/components/panel/panel_component.rb +11 -5
  53. data/app/views/components/resource_header/resource_header_component.html.erb +81 -0
  54. data/app/views/components/resource_header/resource_header_component.rb +20 -0
  55. data/app/views/components/resource_layout/resource_layout_component.html.erb +32 -0
  56. data/app/views/components/resource_layout/resource_layout_component.rb +39 -0
  57. data/app/views/components/sidebar/sidebar_component.html.erb +3 -33
  58. data/app/views/components/sidebar/sidebar_component.rb +3 -3
  59. data/app/views/components/sidebar_menu/sidebar_menu_component.html.erb +4 -2
  60. data/app/views/components/sidebar_menu/sidebar_menu_component.rb +10 -6
  61. data/app/views/components/sidebar_menu_item/sidebar_menu_item_component.html.erb +63 -71
  62. data/app/views/components/sidebar_menu_item/sidebar_menu_item_component.rb +27 -8
  63. data/app/views/components/skeleton/table/table_component.html.erb +1 -1
  64. data/app/views/components/skeleton/table/table_component.rb +3 -3
  65. data/app/views/components/table/table_component.html.erb +40 -89
  66. data/app/views/components/table/table_component.rb +124 -28
  67. data/app/views/components/table_search_input/table_search_input_component.html.erb +1 -1
  68. data/app/views/components/table_search_input/table_search_input_component.rb +11 -6
  69. data/app/views/components/table_toolbar/table_toolbar_component.html.erb +1 -1
  70. data/app/views/components/table_toolbar/table_toolbar_component.rb +11 -3
  71. data/app/views/components/toolbar/toolbar_component.html.erb +2 -2
  72. data/app/views/components/toolbar/toolbar_component.rb +16 -8
  73. data/app/views/layouts/resource.html copy.erb +2 -2
  74. data/app/views/layouts/resource.html.erb +21 -37
  75. data/app/views/layouts/rodauth.html.erb +32 -25
  76. data/app/views/resource/_interactive_resource_action_form.html.erb +1 -1
  77. data/app/views/resource/_resource_details.html.erb +8 -5
  78. data/app/views/resource/_resource_table.html.erb +70 -1
  79. data/app/views/resource/interactive_resource_collection_action.html.erb +1 -0
  80. data/app/views/resource/interactive_resource_record_action.html.erb +1 -0
  81. data/app/views/resource/interactive_resource_recordless_action.html.erb +1 -0
  82. data/app/views/resource/new.html.erb +1 -0
  83. data/app/views/rodauth/add_recovery_codes.html.erb +8 -7
  84. data/app/views/rodauth/otp_auth.html.erb +1 -1
  85. data/app/views/rodauth/otp_setup.html.erb +10 -8
  86. data/config/initializers/simple_form.rb +22 -2
  87. data/esbuild.config.js +35 -31
  88. data/lib/generators/pu/core/assets/assets_generator.rb +41 -0
  89. data/lib/generators/pu/core/assets/templates/tailwind.config.js +18 -0
  90. data/lib/generators/pu/core/install/templates/config/initializers/plutonium.rb +3 -0
  91. data/lib/generators/pu/core/ruby/ruby_generator.rb +30 -0
  92. data/lib/generators/pu/core/ruby/templates/.keep +0 -0
  93. data/lib/generators/pu/docker/install/install_generator.rb +35 -0
  94. data/lib/generators/pu/docker/install/templates/.keep +0 -0
  95. data/lib/generators/pu/docker/install/templates/Dockerfile.dev.tt +30 -0
  96. data/lib/generators/pu/docker/install/templates/Dockerfile.tt +75 -0
  97. data/lib/generators/pu/docker/install/templates/bin/console +3 -0
  98. data/lib/generators/pu/docker/install/templates/bin/restart +3 -0
  99. data/lib/generators/pu/docker/install/templates/bin/shell +3 -0
  100. data/lib/generators/pu/docker/install/templates/docker-compose.yml +29 -0
  101. data/lib/generators/pu/gem/dotenv/dotenv_generator.rb +32 -0
  102. data/lib/generators/pu/gem/dotenv/templates/.env +6 -0
  103. data/lib/generators/pu/gem/dotenv/templates/.env.local +5 -0
  104. data/lib/generators/pu/gem/dotenv/templates/.env.local.template +5 -0
  105. data/lib/generators/pu/gem/dotenv/templates/.env.template +6 -0
  106. data/lib/generators/pu/gem/dotenv/templates/.keep +0 -0
  107. data/lib/generators/pu/gem/dotenv/templates/config/initializers/001_ensure_required_env.rb +21 -0
  108. data/lib/generators/pu/gem/redis/redis_generator.rb +22 -0
  109. data/lib/generators/pu/gem/redis/templates/.keep +0 -0
  110. data/lib/generators/pu/gen/component/component_generator.rb +13 -10
  111. data/lib/generators/pu/gen/component/templates/component.html.erb.tt +1 -1
  112. data/lib/generators/pu/gen/component/templates/component.rb.tt +10 -4
  113. data/lib/generators/pu/lib/plutonium_generators/concerns/actions.rb +154 -32
  114. data/lib/generators/pu/lib/plutonium_generators/generator.rb +6 -6
  115. data/lib/generators/pu/lib/plutonium_generators/installer.rb +1 -1
  116. data/lib/generators/pu/pkg/app/app_generator.rb +4 -4
  117. data/lib/generators/pu/pkg/app/templates/app/controllers/concerns/controller.rb.tt +28 -0
  118. data/lib/generators/pu/pkg/app/templates/app/controllers/controller.rb.tt +5 -0
  119. data/lib/generators/pu/pkg/app/templates/app/controllers/dashboard_controller.rb.tt +1 -1
  120. data/lib/generators/pu/res/conn/conn_generator.rb +4 -4
  121. data/lib/generators/pu/res/conn/templates/app/controllers/resource_controller.rb.tt +1 -1
  122. data/lib/generators/pu/res/model/model_generator.rb +3 -3
  123. data/lib/generators/pu/res/scaffold/templates/policy.rb.tt +6 -0
  124. data/lib/generators/pu/rodauth/account_generator.rb +10 -10
  125. data/lib/generators/pu/rodauth/install_generator.rb +9 -2
  126. data/lib/generators/pu/rodauth/migration/sequel/audit_logging.erb +2 -2
  127. data/lib/generators/pu/rodauth/migration_generator.rb +1 -1
  128. data/lib/generators/pu/rodauth/templates/app/{misc → rodauth}/account_rodauth_plugin.rb.tt +2 -2
  129. data/lib/generators/pu/rodauth/templates/app/{misc → rodauth}/rodauth_plugin.rb.tt +0 -3
  130. data/lib/generators/pu/rodauth/templates/db/migrate/install_rodauth.rb.tt +5 -0
  131. data/lib/generators/pu/service/postgres/postgres_generator.rb +61 -0
  132. data/lib/generators/pu/service/postgres/templates/.keep +0 -0
  133. data/lib/generators/pu/service/postgres/templates/bin/initdb.d/create-multiple-postgresql-databases.sh +22 -0
  134. data/lib/generators/pu/service/postgres/templates/database.yml.tt +93 -0
  135. data/lib/generators/pu/service/sidekiq/sidekiq_generator.rb +57 -0
  136. data/lib/generators/pu/service/sidekiq/templates/.keep +0 -0
  137. data/lib/generators/pu/service/sidekiq/templates/app/sidekiq/sidekiq_job.rb +3 -0
  138. data/lib/generators/pu/service/sidekiq/templates/config/initializers/sidekiq.rb +53 -0
  139. data/lib/generators/pu/service/sidekiq/templates/config/sidekiq.yml +6 -0
  140. data/lib/plutonium/config.rb +2 -9
  141. data/lib/plutonium/core/associations/renderers/basic_renderer.rb +28 -0
  142. data/lib/plutonium/core/associations/renderers/factory.rb +36 -0
  143. data/lib/plutonium/core/associations/renderers/has_many_renderer.rb +16 -0
  144. data/lib/plutonium/core/autodiscovery/association_renderer_discoverer.rb +31 -0
  145. data/lib/plutonium/core/controllers/authorizable.rb +13 -17
  146. data/lib/plutonium/core/controllers/base.rb +3 -7
  147. data/lib/plutonium/core/controllers/entity_scoping.rb +3 -3
  148. data/lib/plutonium/core/controllers/presentable.rb +6 -1
  149. data/lib/plutonium/core/definers/association_renderer_definer.rb +33 -0
  150. data/lib/plutonium/core/fields/inputs/checkbox_input.rb +13 -0
  151. data/lib/plutonium/core/fields/inputs/factory.rb +1 -0
  152. data/lib/plutonium/core/fields/inputs/polymorphic_belongs_to_association_input.rb +1 -1
  153. data/lib/plutonium/core/ui/detail.rb +1 -0
  154. data/lib/plutonium/helpers/application_helper.rb +8 -9
  155. data/lib/plutonium/helpers/assets_helper.rb +33 -0
  156. data/lib/plutonium/helpers/display_helper.rb +13 -0
  157. data/lib/plutonium/helpers/form_helper.rb +1 -1
  158. data/lib/plutonium/helpers.rb +1 -0
  159. data/lib/plutonium/icons.rb +12 -5
  160. data/lib/plutonium/pkg/app.rb +10 -0
  161. data/lib/plutonium/pundit/context.rb +18 -0
  162. data/lib/plutonium/pundit/policy_finder.rb +25 -0
  163. data/lib/plutonium/railtie.rb +24 -8
  164. data/lib/plutonium/reloader.rb +18 -7
  165. data/lib/plutonium/resource/controller.rb +5 -0
  166. data/lib/plutonium/resource/policy.rb +69 -47
  167. data/lib/plutonium/resource/presenter.rb +1 -0
  168. data/lib/plutonium/resource/query_object.rb +139 -130
  169. data/lib/plutonium/rodauth/controller_methods.rb +7 -3
  170. data/lib/plutonium/version.rb +1 -1
  171. data/lib/plutonium.rb +10 -54
  172. data/lib/tasks/create_rodauth_admin.rake +16 -0
  173. data/package-lock.json +782 -17
  174. data/package.json +31 -8
  175. data/postcss.config.js +17 -7
  176. data/src/.npmignore +2 -0
  177. data/src/js/controllers/color_mode_controller.js +41 -0
  178. data/src/js/controllers/frame_navigator_controller.js +99 -0
  179. data/src/js/controllers/has_many_panel_controller.js +8 -0
  180. data/src/js/controllers/nav_grid_menu_controller.js +8 -0
  181. data/src/js/controllers/nav_grid_menu_item_controller.js +8 -0
  182. data/{app/views/components/tab_bar/tab_bar_controller.js → src/js/controllers/nav_user_controller.js} +2 -2
  183. data/src/js/controllers/nav_user_link_controller.js +8 -0
  184. data/src/js/controllers/nav_user_section_controller.js +8 -0
  185. data/src/js/controllers/register_controllers.js +45 -0
  186. data/{app/assets/javascripts → src/js}/controllers/resource_dismiss_controller.js +2 -0
  187. data/{app/assets/javascripts → src/js}/controllers/resource_drop_down_controller.js +2 -0
  188. data/src/js/controllers/resource_header_controller.js +8 -0
  189. data/src/js/controllers/resource_layout_controller.js +8 -0
  190. data/src/js/controllers/sidebar_menu_controller.js +8 -0
  191. data/src/js/controllers/sidebar_menu_item_controller.js +8 -0
  192. data/src/js/core.js +4 -0
  193. data/{app/assets/javascripts/plutonium-app.js → src/js/plutonium.js} +1 -1
  194. data/{app/assets/javascripts → src/js}/turbo/turbo_debug.js +2 -4
  195. data/tailwind.config.js +85 -84
  196. metadata +106 -41
  197. data/app/assets/build/plutonium.js +0 -5122
  198. data/app/assets/javascripts/controllers/index.js +0 -34
  199. data/app/assets/javascripts/plutonium.js +0 -1
  200. data/app/views/application/_color_modes.html.erb +0 -57
  201. data/app/views/components/tab_bar/tab_bar_component.html.erb +0 -11
  202. data/app/views/components/tab_bar/tab_bar_component.rb +0 -9
  203. data/app/views/resource/_nav_user.html.erb +0 -4
  204. data/app/views/resource/_tab_menu.html.erb +0 -13
  205. data/css.manifest +0 -3
  206. data/js.manifest +0 -4
  207. data/lib/generators/pu/pkg/app/templates/app/controllers/app_controller.rb.tt +0 -5
  208. data/lib/generators/pu/pkg/app/templates/app/controllers/package_controller.rb.tt +0 -26
  209. data/public/plutonium-assets/application.css +0 -25086
  210. data/public/plutonium-assets/plutonium-app-36KN5FVJ.js +0 -6
  211. data/public/plutonium-assets/plutonium-app-36KN5FVJ.js.map +0 -7
  212. data/public/plutonium-assets/plutonium-app-6WILQCTT.js +0 -39
  213. data/public/plutonium-assets/plutonium-app-6WILQCTT.js.map +0 -7
  214. data/public/plutonium-assets/plutonium.2d4f0c333cd000051d3b.css +0 -3424
  215. data/public/plutonium-assets/plutonium.50232e35b5495f5ad90d.css +0 -3415
  216. /data/{app/assets/build → lib/generators/pu/core/assets/templates}/.keep +0 -0
  217. /data/lib/generators/pu/rodauth/templates/app/{misc → rodauth}/rodauth_app.rb.tt +0 -0
  218. /data/{app/assets/stylesheets → src/css}/plutonium.css +0 -0
  219. /data/{app/views/components/form → src/js/controllers}/form_controller.js +0 -0
  220. /data/{app/views/components/interactive_action_form → src/js/controllers}/interactive_action_form_controller.js +0 -0
  221. /data/{app/views/components/nested_resource_form_fields → src/js/controllers}/nested_resource_form_fields_controller.js +0 -0
  222. /data/{app/views/components/table → src/js/controllers}/table_controller.js +0 -0
  223. /data/{app/views/components/table_search_input → src/js/controllers}/table_search_input_controller.js +0 -0
  224. /data/{app/views/components/table_toolbar → src/js/controllers}/table_toolbar_controller.js +0 -0
  225. /data/{app/views/components/toolbar → src/js/controllers}/toolbar_controller.js +0 -0
  226. /data/{app/assets/javascripts → src/js}/turbo/index.js +0 -0
  227. /data/{app/assets/javascripts → src/js}/turbo/turbo_actions.js +0 -0
  228. /data/{app/assets/javascripts → src/js}/turbo/turbo_frame_monkey_patch.js +0 -0
@@ -5,22 +5,17 @@ module Plutonium
5
5
  module Controllers
6
6
  module Authorizable
7
7
  extend ActiveSupport::Concern
8
- include Pundit::Authorization
8
+ include ::Pundit::Authorization
9
9
 
10
10
  included do
11
11
  after_action :verify_authorized
12
12
  after_action :verify_policy_scoped, except: %i[new create]
13
13
 
14
- helper_method :permitted_attributes
15
- helper_method :current_policy
14
+ helper_method :current_policy, :permitted_attributes
16
15
  end
17
16
 
18
17
  private
19
18
 
20
- def policy_namespace(scope)
21
- [current_package.to_s.underscore.to_sym, scope]
22
- end
23
-
24
19
  def policy_context
25
20
  raise NotImplementedError, "policy_context"
26
21
  end
@@ -29,22 +24,23 @@ module Plutonium
29
24
  policy_context
30
25
  end
31
26
 
32
- def policy(scope)
33
- super(policy_namespace(scope))
34
- end
35
-
36
- def policy_scope(scope)
37
- super(policy_namespace(scope))
38
- end
39
-
40
- def authorize(record, query = nil)
41
- super(policy_namespace(record), query)
27
+ # @return [Plutonium::Pundit::Context] a new instance of {Plutonium::Pundit::Context} with the current user and package
28
+ def pundit
29
+ @pundit ||= Plutonium::Pundit::Context.new(
30
+ package: current_package.to_s.underscore.to_sym,
31
+ user: pundit_user,
32
+ policy_cache: ::Pundit::CacheStore::LegacyStore.new(policies)
33
+ )
42
34
  end
43
35
 
44
36
  def permitted_attributes
45
37
  @permitted_attributes ||= current_policy.send_with_report :"permitted_attributes_for_#{action_name}"
46
38
  end
47
39
 
40
+ def permitted_associations
41
+ @permitted_associations ||= current_policy.permitted_associations
42
+ end
43
+
48
44
  def current_policy
49
45
  @current_policy ||= begin
50
46
  policy_subject = resource_record || resource_class
@@ -18,7 +18,7 @@ module Plutonium
18
18
  end
19
19
 
20
20
  helper Plutonium::Helpers
21
- helper_method :page_title, :resource_url_for, :resource_url_args_for, :root_path, :application_name
21
+ helper_method :make_page_title, :resource_url_for, :resource_url_args_for, :root_path
22
22
 
23
23
  append_view_path File.expand_path("app/views", Plutonium.root)
24
24
  layout -> { turbo_frame_request? ? false : "resource" }
@@ -30,12 +30,8 @@ module Plutonium
30
30
  @page_title = nil
31
31
  end
32
32
 
33
- def page_title(title)
34
- [title.presence, application_name].compact.join(" | ")
35
- end
36
-
37
- def application_name
38
- Rails.application.class.module_parent.name
33
+ def make_page_title(title)
34
+ [title.presence, helpers.application_name].compact.join(" | ")
39
35
  end
40
36
 
41
37
  #
@@ -43,15 +43,15 @@ module Plutonium
43
43
  return unless current_user.present?
44
44
 
45
45
  @current_scoped_entity ||= case scoped_entity_strategy
46
- when :current_user
47
- current_user
48
46
  when :path
49
47
  scoped_entity_class
50
48
  .associated_with(current_user)
51
49
  .from_path_param(request.path_parameters[scoped_entity_param_key])
52
50
  .first! # Raise NotFound if user does not have access to the entity or it does not exist
51
+ when Symbol
52
+ send scoped_entity_strategy
53
53
  else
54
- raise NotImplementedError, "unknown scoped entity strategy: #{scoped_entity_strategy}"
54
+ raise NotImplementedError, "unknown scoped entity strategy: #{scoped_entity_strategy.inspect}"
55
55
  end
56
56
  end
57
57
 
@@ -5,7 +5,7 @@ module Plutonium
5
5
  extend ActiveSupport::Concern
6
6
 
7
7
  included do
8
- helper_method :presentable_attributes
8
+ helper_method :presentable_attributes, :present_associations?
9
9
  end
10
10
 
11
11
  private
@@ -44,6 +44,7 @@ module Plutonium
44
44
  resource_class:,
45
45
  record: resource_record,
46
46
  fields: current_presenter.defined_renderers_for(*presentable_attributes),
47
+ associations: current_presenter.defined_association_renderers_for(*permitted_associations),
47
48
  actions: current_presenter.actions
48
49
  )
49
50
  end
@@ -54,6 +55,10 @@ module Plutonium
54
55
  inputs: current_presenter.defined_inputs_for(*presentable_attributes)
55
56
  )
56
57
  end
58
+
59
+ def present_associations?
60
+ current_parent.nil?
61
+ end
57
62
  end
58
63
  end
59
64
  end
@@ -0,0 +1,33 @@
1
+ module Plutonium
2
+ module Core
3
+ module Definers
4
+ module AssociationRendererDefiner
5
+ extend ActiveSupport::Concern
6
+ include Plutonium::Core::Autodiscovery::AssociationRendererDiscoverer
7
+
8
+ def defined_association_renderers_for(*names)
9
+ (names - association_renderer_definitions.keys).each do |name|
10
+ define_association_renderer(name, renderer: autodiscover_association_renderer(name))
11
+ end
12
+ association_renderer_definitions.slice(*names)
13
+ end
14
+
15
+ private
16
+
17
+ def association_renderer_definitions = @association_renderer_definitions ||= {}
18
+
19
+ def define_association_renderer(name, renderer: nil, **options)
20
+ association_renderer_definitions[name] = if renderer.present?
21
+ renderer
22
+ else
23
+ autodiscover_association_renderer(name)
24
+ end
25
+ end
26
+
27
+ def association_renderer_defined?(name)
28
+ association_renderer_definitions.key? name
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,13 @@
1
+ module Plutonium
2
+ module Core
3
+ module Fields
4
+ module Inputs
5
+ class CheckboxInput < SimpleFormInput
6
+ private
7
+
8
+ def input_options = {wrapper: :resource_checkbox}
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -14,6 +14,7 @@ module Plutonium
14
14
  map_type :attachment, to: Plutonium::Core::Fields::Inputs::AttachmentInput
15
15
  map_type :datetime, :date, :time, to: Plutonium::Core::Fields::Inputs::DateTimeInput
16
16
  map_type :phone, to: Plutonium::Core::Fields::Inputs::PhoneInput
17
+ map_type :boolean, to: Plutonium::Core::Fields::Inputs::CheckboxInput
17
18
  # map_type :text, :string, to: Plutonium::Core::Fields::Inputs::SimpleFormInput
18
19
 
19
20
  def self.build(name, type:, **options)
@@ -27,7 +27,7 @@ module Plutonium
27
27
  end
28
28
 
29
29
  def associated_classes
30
- Rails.application.eager_load! unless Rails.application.config.eager_load
30
+ Plutonium.eager_load_rails!
31
31
 
32
32
  associated_classes = []
33
33
  ActiveRecord::Base.descendants.each do |model|
@@ -7,6 +7,7 @@ module Plutonium
7
7
  option :resource_class
8
8
  option :record, optional: true
9
9
  option :fields, default: proc { {} }
10
+ option :associations, default: proc { {} }
10
11
  option :actions, default: proc { Plutonium::Core::Actions::Collection.new }
11
12
  end
12
13
  end
@@ -1,17 +1,16 @@
1
1
  module Plutonium
2
2
  module Helpers
3
3
  module ApplicationHelper
4
- # def tooltip(text)
5
- # text = sanitize text
6
- # "title=\"#{text}\" data-controller=\"tooltip\" data-bs-title=\"#{text}\"".html_safe
7
- # end
8
-
9
- def resource_name(resource_class, count = 1)
10
- resource_class.model_name.human.pluralize(count)
4
+ def application_name
5
+ Plutonium.application_name
11
6
  end
12
7
 
13
- def resource_name_plural(resource_class)
14
- resource_name resource_class, 2
8
+ # Renders an icon using the Plutonium Icons library.
9
+ #
10
+ # @param icon [Symbol, String] The name or identifier of the icon to render.
11
+ # @return [String] The HTML-safe string for the rendered icon.
12
+ def render_icon(icon, **)
13
+ Plutonium::Icons.render(icon, **)
15
14
  end
16
15
  end
17
16
  end
@@ -0,0 +1,33 @@
1
+ module Plutonium
2
+ module Helpers
3
+ module AssetsHelper
4
+ def plutonium_stylesheet_tag
5
+ url = if Plutonium.development?
6
+ file = JSON.parse(File.read(Plutonium.root.join("src", "build", "css.manifest")))["plutonium.css"]
7
+ "/build/#{file}"
8
+ else
9
+ "plutonium.css"
10
+ end
11
+ stylesheet_link_tag url, "data-turbo-track": "reload"
12
+ end
13
+
14
+ def plutonium_script_tag
15
+ url = if Plutonium.development?
16
+ file = JSON.parse(File.read(Plutonium.root.join("src", "build", "js.manifest")))["plutonium.js"]
17
+ "/build/#{file}"
18
+ else
19
+ "plutonium.min.js"
20
+ end
21
+ javascript_include_tag url, "data-turbo-track": "reload", type: "module"
22
+ end
23
+
24
+ def logo_tag(classname:)
25
+ image_tag logo, class: classname
26
+ end
27
+
28
+ def logo
29
+ Plutonium::Config.logo || "plutonium-logo.png"
30
+ end
31
+ end
32
+ end
33
+ end
@@ -1,6 +1,19 @@
1
1
  module Plutonium
2
2
  module Helpers
3
3
  module DisplayHelper
4
+ # def tooltip(text)
5
+ # text = sanitize text
6
+ # "title=\"#{text}\" data-controller=\"tooltip\" data-bs-title=\"#{text}\"".html_safe
7
+ # end
8
+
9
+ def resource_name(resource_class, count = 1)
10
+ resource_class.model_name.human.pluralize(count)
11
+ end
12
+
13
+ def resource_name_plural(resource_class)
14
+ resource_name resource_class, 2
15
+ end
16
+
4
17
  def display_field(value:, helper: nil, **options)
5
18
  return "-" unless value.present?
6
19
 
@@ -6,7 +6,7 @@ module Plutonium
6
6
  include ActionView::Helpers::FormHelper
7
7
 
8
8
  def resource_form_for(record, options = {}, &block)
9
- options[:builder] ||= Plutonium::Ui::FormBuilder
9
+ options[:builder] ||= PlutoniumUi::FormBuilder
10
10
  options[:wrapper] ||= :default_resource_form
11
11
  options[:html] ||= {}
12
12
  unless options[:html].key?(:novalidate)
@@ -12,6 +12,7 @@ module Plutonium
12
12
  include Plutonium::Helpers::TableHelper
13
13
  include Plutonium::Helpers::TurboHelper
14
14
  include Plutonium::Helpers::TurboStreamActionsHelper
15
+ include Plutonium::Helpers::AssetsHelper
15
16
  end
16
17
  end
17
18
  end
@@ -4,20 +4,27 @@ module Plutonium
4
4
  ICON_SIZES = {
5
5
  sm: "w-3 h-3",
6
6
  md: "w-4 h-4",
7
- lg: "w-6 h-6"
7
+ lg: "w-6 h-6",
8
+ xl: "w-8 h-8"
8
9
  }
9
10
 
10
11
  class << self
11
- def render(name, size: :md)
12
+ def render(name, size: :md, classname: nil)
13
+ size = ICON_SIZES.key?(size) ? size : :sm
14
+ classname = (Array(classname) + [ICON_SIZES[size]]).join(" ")
15
+
16
+ resolve(name).sub("<svg ", "<svg class=\"#{classname}\" ").html_safe
17
+ end
18
+
19
+ def resolve(name)
12
20
  # This is not threadsafe, but should not cause any issues
13
21
  # I believe adding a mutex would be overall more expensive than a few potential
14
22
  # concurrent disk accesses for a brief while after boot.
15
- size = ICON_SIZES.key?(size) ? size : :sm
16
- ICON_CACHE["#{name}:#{size}"] ||= begin
23
+ ICON_CACHE[name] ||= begin
17
24
  path = Plutonium.root.join "app/assets/icons/#{name}.svg"
18
25
  raise "Invalid icon: #{name}" unless File.exist?(path)
19
26
 
20
- File.read(path).sub("<svg ", "<svg class=\"#{ICON_SIZES[size]}\" ")
27
+ File.read(path)
21
28
  end
22
29
  end
23
30
  end
@@ -1,3 +1,5 @@
1
+ require "active_support/notifications"
2
+
1
3
  module Plutonium
2
4
  module Pkg
3
5
  module App
@@ -49,6 +51,14 @@ module Plutonium
49
51
  end
50
52
 
51
53
  def draw_resource_routes
54
+ ActiveSupport::Notifications.instrument("plutonium.app.draw_resource_routes", app: self.class.module_parent.to_s) do
55
+ draw_resource_routes_internal
56
+ end
57
+ end
58
+
59
+ private
60
+
61
+ def draw_resource_routes_internal
52
62
  custom_routes_block = @custom_routes_block
53
63
  registered_resources = resource_register
54
64
  scoped_entity_param_key = self.scoped_entity_param_key if scoped_entity_strategy == :path
@@ -0,0 +1,18 @@
1
+ require "pundit"
2
+
3
+ module Plutonium
4
+ module Pundit
5
+ class Context < ::Pundit::Context
6
+ def initialize(*, package:, **)
7
+ super(*, **)
8
+ @package = package
9
+ end
10
+
11
+ private
12
+
13
+ def policy_finder(record)
14
+ PolicyFinder.new(record, package: @package)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,25 @@
1
+ require "pundit"
2
+
3
+ module Plutonium
4
+ module Pundit
5
+ class PolicyFinder < ::Pundit::PolicyFinder
6
+ def initialize(*, package:)
7
+ super(*)
8
+ @package = package
9
+ end
10
+
11
+ attr_reader :package
12
+
13
+ def policy
14
+ policy_internal([package, object]) || policy_internal(object)
15
+ end
16
+
17
+ private
18
+
19
+ def policy_internal(object)
20
+ klass = find(object)
21
+ klass.is_a?(String) ? klass.safe_constantize : klass
22
+ end
23
+ end
24
+ end
25
+ end
@@ -6,27 +6,39 @@ module Plutonium
6
6
  config.plutonium.cache_discovery = defined?(Rails.env) && !Rails.env.development?
7
7
  config.plutonium.enable_hotreload = defined?(Rails.env) && Rails.env.development?
8
8
 
9
- initializer "plutonium.append_assets_path" do |app|
10
- config.to_prepare do
11
- Rails.application.config.assets.paths << Plutonium.root.join("app/assets/build").to_s
12
- end
9
+ # If you don't want to precompile Plutonium's assets (eg. because you're using webpack),
10
+ # you can do this in an intiailzer:
11
+ #
12
+ # config.after_initialize do
13
+ # config.assets.precompile -= Plutonium::Railtie::PRECOMPILE_ASSETS
14
+ # end
15
+ PRECOMPILE_ASSETS = %w[plutonium.js plutonium.js.map plutonium.min.js plutonium.min.js.map plutonium.css]
16
+
17
+ initializer "plutonium.assets" do
18
+ next unless Rails.application.config.respond_to?(:assets)
19
+
20
+ Rails.application.config.assets.precompile += PRECOMPILE_ASSETS
21
+ Rails.application.config.assets.paths << Plutonium.root.join("app/assets").to_s
13
22
  end
14
23
 
15
- initializer "plutonium.load_view_components" do
24
+ initializer "plutonium.load_components" do
16
25
  load Plutonium.root.join("app", "views", "components", "base.rb")
17
26
  end
18
27
 
19
- initializer "plutonium.load_initializers" do
28
+ initializer "plutonium.initializers" do
20
29
  Dir.glob(Plutonium.root.join("config", "initializers", "**", "*.rb")) { |file| load file }
21
30
  end
22
31
 
23
32
  initializer "plutonium.asset_server" do
33
+ next unless Plutonium.development?
34
+
35
+ puts "=> [plutonium] starting assets server"
24
36
  # setup a middleware to serve our assets
25
37
  config.app_middleware.insert_before(
26
38
  ActionDispatch::Static,
27
39
  Rack::Static,
28
- urls: ["/plutonium-assets"],
29
- root: Plutonium.root.join("public"),
40
+ urls: ["/build"],
41
+ root: Plutonium.root.join("src").to_s,
30
42
  cascade: true,
31
43
  header_rules: [
32
44
  # Cache all static files in public caches (e.g. Rack::Cache) as well as in the browser
@@ -39,6 +51,10 @@ module Plutonium
39
51
  config.view_component.capture_compatibility_patch_enabled = true
40
52
  end
41
53
 
54
+ rake_tasks do
55
+ load "tasks/create_rodauth_admin.rake"
56
+ end
57
+
42
58
  config.after_initialize do
43
59
  Plutonium::Reloader.start! if Rails.application.config.plutonium.enable_hotreload
44
60
  Plutonium::ZEITWERK_LOADER.eager_load if Rails.env.production?
@@ -1,5 +1,6 @@
1
+ require "active_support/notifications"
2
+
1
3
  # Be sure to restart your server when you modify this file.
2
- # This is a glorified initializer
3
4
 
4
5
  module Plutonium
5
6
  class Reloader
@@ -7,8 +8,11 @@ module Plutonium
7
8
  def start!
8
9
  puts "=> [plutonium] starting reloader"
9
10
 
10
- @listener&.stop
11
- @listener = initialize_listener
11
+ ActiveSupport::Notifications.instrument("plutonium.reloader.start") do
12
+ # Task code here
13
+ @listener&.stop
14
+ @listener = initialize_listener
15
+ end
12
16
  end
13
17
 
14
18
  private
@@ -75,16 +79,23 @@ module Plutonium
75
79
  end
76
80
 
77
81
  def reload_engine_and_routes(file)
78
- Plutonium.logger.debug "[plutonium] reloading #{file}"
82
+ Plutonium.logger.debug "[plutonium] reloading: engine+routes"
79
83
  load file
80
84
  Rails.application.reload_routes!
81
85
  end
82
86
 
83
87
  def reload_framework_and_file(file)
84
- Plutonium.logger.debug "[plutonium] reloading framework"
88
+ # # Ensure that the file loads correctly before we do any reloading
89
+ # load file
90
+
91
+ Plutonium.logger.debug "[plutonium] reloading: app+framework"
92
+ Rails.application.reloader.reload!
85
93
  Plutonium::ZEITWERK_LOADER.reload
94
+ # reload components
95
+ Object.send(:remove_const, "PlutoniumUi")
86
96
  load Plutonium.root.join("app", "views", "components", "base.rb")
87
- load file # Ensure files that do not contain constants are loaded
97
+ # # Ensure files that do not contain constants are loaded again e.g. initializers
98
+ # load file
88
99
  end
89
100
 
90
101
  def reload_file(file)
@@ -92,7 +103,7 @@ module Plutonium
92
103
  end
93
104
 
94
105
  def log_reload_failure(file, error)
95
- Plutonium.logger.error "\n[plutonium] reload failed #{file}\n\n#{error}\n"
106
+ Plutonium.logger.error "\n[plutonium] reloading failed\n\n#{error.message}\n"
96
107
  end
97
108
  end
98
109
  end
@@ -49,6 +49,7 @@ module Plutonium
49
49
  # @return [ActiveRecord::Base, nil] The resource record
50
50
  def resource_record
51
51
  @resource_record ||= policy_scope(resource_class).from_path_param(params[:id]).first! if params[:id].present?
52
+ @resource_record
52
53
  end
53
54
 
54
55
  # Returns the submitted resource parameters
@@ -94,6 +95,8 @@ module Plutonium
94
95
  def resource_presenter(resource_class, resource_record)
95
96
  presenter_class = "#{current_package}::#{resource_class}Presenter".constantize
96
97
  presenter_class.new resource_context, resource_record
98
+ rescue NameError
99
+ super(resource_class, resource_record)
97
100
  end
98
101
 
99
102
  # Creates a resource query object
@@ -103,6 +106,8 @@ module Plutonium
103
106
  def resource_query_object(resource_class, params)
104
107
  query_object_class = "#{current_package}::#{resource_class}QueryObject".constantize
105
108
  query_object_class.new resource_context, params
109
+ rescue NameError
110
+ super(resource_class, params)
106
111
  end
107
112
 
108
113
  # Applies submitted resource params if they have been passed