plutonium 0.10.2 → 0.11.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 +4 -4
- data/README.md +1 -0
- data/Rakefile +1 -2
- data/app/assets/application.js.bk +31419 -0
- data/app/assets/plutonium-logo-original.png +0 -0
- data/app/assets/plutonium-logo-white.png +0 -0
- data/app/assets/plutonium-logo.png +0 -0
- data/app/assets/plutonium.css +1 -0
- data/app/assets/plutonium.ico +0 -0
- data/app/assets/plutonium.js +12416 -0
- data/app/assets/plutonium.js.map +7 -0
- data/app/assets/plutonium.min.js +39 -0
- data/app/assets/plutonium.min.js.map +7 -0
- data/app/views/application/_flash_alerts.html.erb +5 -2
- data/app/views/application/_flash_toasts.html.erb +2 -0
- data/app/views/application/_resource_header.html.erb +263 -697
- data/app/views/application/_resource_sidebar.html.erb +14 -12
- data/app/views/components/action_button/action_button_component.rb +3 -3
- data/app/views/components/attributes.rb +184 -0
- data/app/views/components/base.rb +19 -40
- data/app/views/components/block/block_component.html.erb +1 -1
- data/app/views/components/block/block_component.rb +11 -7
- data/app/views/components/breadcrumbs/breadcrumbs_component.rb +3 -3
- data/app/views/components/button/button_component.html.erb +2 -2
- data/app/views/components/button/button_component.rb +10 -5
- data/app/views/components/dyna_frame_content/dyna_frame_content_component.html.erb +1 -0
- data/app/views/components/dyna_frame_content/dyna_frame_content_component.rb +3 -3
- data/app/views/components/dyna_frame_host/dyna_frame_host_component.html.erb +1 -2
- data/app/views/components/dyna_frame_host/dyna_frame_host_component.rb +12 -5
- data/app/views/components/empty_card/empty_card_component.rb +3 -3
- data/app/views/components/form/form_builder.rb +1 -1
- data/app/views/components/form/form_component.rb +3 -3
- data/app/views/components/has_many_panel/has_many_panel_component.html.erb +25 -0
- data/app/views/components/has_many_panel/has_many_panel_component.rb +16 -0
- data/app/views/components/header/header_component.rb +3 -3
- data/app/views/components/interactive_action_form/interactive_action_form_component.rb +3 -3
- data/app/views/components/nav_grid_menu/nav_grid_menu_component.html.erb +24 -0
- data/app/views/components/nav_grid_menu/nav_grid_menu_component.rb +23 -0
- data/app/views/components/nav_grid_menu_item/nav_grid_menu_item_component.html.erb +4 -0
- data/app/views/components/nav_grid_menu_item/nav_grid_menu_item_component.rb +20 -0
- data/app/views/components/nav_user/nav_user_component.html.erb +50 -0
- data/app/views/components/nav_user/nav_user_component.rb +32 -0
- data/app/views/components/nav_user_link/nav_user_link_component.html.erb +7 -0
- data/app/views/components/nav_user_link/nav_user_link_component.rb +23 -0
- data/app/views/components/nav_user_section/nav_user_section_component.html.erb +7 -0
- data/app/views/components/nav_user_section/nav_user_section_component.rb +18 -0
- data/app/views/components/nested_resource_form_fields/nested_resource_form_fields_component.html.erb +1 -3
- data/app/views/components/nested_resource_form_fields/nested_resource_form_fields_component.rb +11 -5
- data/app/views/components/pagination/pagination_component.html.erb +1 -1
- data/app/views/components/pagination/pagination_component.rb +10 -7
- data/app/views/components/panel/panel_component.html.erb +13 -6
- data/app/views/components/panel/panel_component.rb +11 -5
- data/app/views/components/resource_header/resource_header_component.html.erb +81 -0
- data/app/views/components/resource_header/resource_header_component.rb +20 -0
- data/app/views/components/resource_layout/resource_layout_component.html.erb +32 -0
- data/app/views/components/resource_layout/resource_layout_component.rb +39 -0
- data/app/views/components/sidebar/sidebar_component.html.erb +3 -33
- data/app/views/components/sidebar/sidebar_component.rb +3 -3
- data/app/views/components/sidebar_menu/sidebar_menu_component.html.erb +4 -2
- data/app/views/components/sidebar_menu/sidebar_menu_component.rb +10 -6
- data/app/views/components/sidebar_menu_item/sidebar_menu_item_component.html.erb +63 -71
- data/app/views/components/sidebar_menu_item/sidebar_menu_item_component.rb +27 -8
- data/app/views/components/skeleton/table/table_component.html.erb +1 -1
- data/app/views/components/skeleton/table/table_component.rb +3 -3
- data/app/views/components/table/table_component.html.erb +40 -89
- data/app/views/components/table/table_component.rb +124 -28
- data/app/views/components/table_search_input/table_search_input_component.html.erb +1 -1
- data/app/views/components/table_search_input/table_search_input_component.rb +11 -6
- data/app/views/components/table_toolbar/table_toolbar_component.html.erb +1 -1
- data/app/views/components/table_toolbar/table_toolbar_component.rb +11 -3
- data/app/views/components/toolbar/toolbar_component.html.erb +2 -2
- data/app/views/components/toolbar/toolbar_component.rb +16 -8
- data/app/views/layouts/resource.html copy.erb +2 -2
- data/app/views/layouts/resource.html.erb +21 -37
- data/app/views/layouts/rodauth.html.erb +32 -25
- data/app/views/resource/_interactive_resource_action_form.html.erb +1 -1
- data/app/views/resource/_resource_details.html.erb +8 -5
- data/app/views/resource/_resource_table.html.erb +70 -1
- data/app/views/resource/interactive_resource_collection_action.html.erb +1 -0
- data/app/views/resource/interactive_resource_record_action.html.erb +1 -0
- data/app/views/resource/interactive_resource_recordless_action.html.erb +1 -0
- data/app/views/resource/new.html.erb +1 -0
- data/app/views/rodauth/add_recovery_codes.html.erb +8 -7
- data/app/views/rodauth/otp_auth.html.erb +1 -1
- data/app/views/rodauth/otp_setup.html.erb +10 -8
- data/config/initializers/simple_form.rb +22 -2
- data/esbuild.config.js +35 -31
- data/lib/generators/pu/core/assets/assets_generator.rb +41 -0
- data/lib/generators/pu/core/assets/templates/tailwind.config.js +18 -0
- data/lib/generators/pu/core/install/templates/config/initializers/plutonium.rb +3 -0
- data/lib/generators/pu/core/ruby/ruby_generator.rb +30 -0
- data/lib/generators/pu/core/ruby/templates/.keep +0 -0
- data/lib/generators/pu/docker/install/install_generator.rb +35 -0
- data/lib/generators/pu/docker/install/templates/.keep +0 -0
- data/lib/generators/pu/docker/install/templates/Dockerfile.dev.tt +30 -0
- data/lib/generators/pu/docker/install/templates/Dockerfile.tt +75 -0
- data/lib/generators/pu/docker/install/templates/bin/console +3 -0
- data/lib/generators/pu/docker/install/templates/bin/restart +3 -0
- data/lib/generators/pu/docker/install/templates/bin/shell +3 -0
- data/lib/generators/pu/docker/install/templates/docker-compose.yml +29 -0
- data/lib/generators/pu/gem/dotenv/dotenv_generator.rb +32 -0
- data/lib/generators/pu/gem/dotenv/templates/.env +6 -0
- data/lib/generators/pu/gem/dotenv/templates/.env.local +5 -0
- data/lib/generators/pu/gem/dotenv/templates/.env.local.template +5 -0
- data/lib/generators/pu/gem/dotenv/templates/.env.template +6 -0
- data/lib/generators/pu/gem/dotenv/templates/.keep +0 -0
- data/lib/generators/pu/gem/dotenv/templates/config/initializers/001_ensure_required_env.rb +21 -0
- data/lib/generators/pu/gem/redis/redis_generator.rb +22 -0
- data/lib/generators/pu/gem/redis/templates/.keep +0 -0
- data/lib/generators/pu/gen/component/component_generator.rb +13 -10
- data/lib/generators/pu/gen/component/templates/component.html.erb.tt +1 -1
- data/lib/generators/pu/gen/component/templates/component.rb.tt +10 -4
- data/lib/generators/pu/lib/plutonium_generators/concerns/actions.rb +154 -32
- data/lib/generators/pu/lib/plutonium_generators/generator.rb +6 -6
- data/lib/generators/pu/lib/plutonium_generators/installer.rb +1 -1
- data/lib/generators/pu/pkg/app/app_generator.rb +4 -4
- data/lib/generators/pu/pkg/app/templates/app/controllers/concerns/controller.rb.tt +28 -0
- data/lib/generators/pu/pkg/app/templates/app/controllers/controller.rb.tt +5 -0
- data/lib/generators/pu/pkg/app/templates/app/controllers/dashboard_controller.rb.tt +1 -1
- data/lib/generators/pu/res/conn/conn_generator.rb +4 -4
- data/lib/generators/pu/res/conn/templates/app/controllers/resource_controller.rb.tt +1 -1
- data/lib/generators/pu/res/model/model_generator.rb +3 -3
- data/lib/generators/pu/res/scaffold/templates/policy.rb.tt +6 -0
- data/lib/generators/pu/rodauth/account_generator.rb +10 -10
- data/lib/generators/pu/rodauth/install_generator.rb +9 -2
- data/lib/generators/pu/rodauth/migration/sequel/audit_logging.erb +2 -2
- data/lib/generators/pu/rodauth/migration_generator.rb +1 -1
- data/lib/generators/pu/rodauth/templates/app/{misc → rodauth}/account_rodauth_plugin.rb.tt +2 -2
- data/lib/generators/pu/rodauth/templates/app/{misc → rodauth}/rodauth_plugin.rb.tt +0 -3
- data/lib/generators/pu/rodauth/templates/db/migrate/install_rodauth.rb.tt +5 -0
- data/lib/generators/pu/service/postgres/postgres_generator.rb +61 -0
- data/lib/generators/pu/service/postgres/templates/.keep +0 -0
- data/lib/generators/pu/service/postgres/templates/bin/initdb.d/create-multiple-postgresql-databases.sh +22 -0
- data/lib/generators/pu/service/postgres/templates/database.yml.tt +93 -0
- data/lib/generators/pu/service/sidekiq/sidekiq_generator.rb +57 -0
- data/lib/generators/pu/service/sidekiq/templates/.keep +0 -0
- data/lib/generators/pu/service/sidekiq/templates/app/sidekiq/sidekiq_job.rb +3 -0
- data/lib/generators/pu/service/sidekiq/templates/config/initializers/sidekiq.rb +53 -0
- data/lib/generators/pu/service/sidekiq/templates/config/sidekiq.yml +6 -0
- data/lib/plutonium/config.rb +2 -9
- data/lib/plutonium/core/associations/renderers/basic_renderer.rb +28 -0
- data/lib/plutonium/core/associations/renderers/factory.rb +36 -0
- data/lib/plutonium/core/associations/renderers/has_many_renderer.rb +16 -0
- data/lib/plutonium/core/autodiscovery/association_renderer_discoverer.rb +31 -0
- data/lib/plutonium/core/controllers/authorizable.rb +13 -17
- data/lib/plutonium/core/controllers/base.rb +3 -7
- data/lib/plutonium/core/controllers/entity_scoping.rb +3 -3
- data/lib/plutonium/core/controllers/presentable.rb +6 -1
- data/lib/plutonium/core/definers/association_renderer_definer.rb +33 -0
- data/lib/plutonium/core/fields/inputs/checkbox_input.rb +13 -0
- data/lib/plutonium/core/fields/inputs/factory.rb +1 -0
- data/lib/plutonium/core/fields/inputs/polymorphic_belongs_to_association_input.rb +1 -1
- data/lib/plutonium/core/ui/detail.rb +1 -0
- data/lib/plutonium/helpers/application_helper.rb +8 -9
- data/lib/plutonium/helpers/assets_helper.rb +33 -0
- data/lib/plutonium/helpers/display_helper.rb +13 -0
- data/lib/plutonium/helpers/form_helper.rb +1 -1
- data/lib/plutonium/helpers.rb +1 -0
- data/lib/plutonium/icons.rb +12 -5
- data/lib/plutonium/pkg/app.rb +10 -0
- data/lib/plutonium/pundit/context.rb +18 -0
- data/lib/plutonium/pundit/policy_finder.rb +25 -0
- data/lib/plutonium/railtie.rb +24 -8
- data/lib/plutonium/reloader.rb +18 -7
- data/lib/plutonium/resource/controller.rb +5 -0
- data/lib/plutonium/resource/policy.rb +69 -47
- data/lib/plutonium/resource/presenter.rb +1 -0
- data/lib/plutonium/resource/query_object.rb +139 -130
- data/lib/plutonium/rodauth/controller_methods.rb +7 -3
- data/lib/plutonium/version.rb +1 -1
- data/lib/plutonium.rb +10 -54
- data/lib/tasks/create_rodauth_admin.rake +16 -0
- data/package-lock.json +782 -17
- data/package.json +31 -8
- data/postcss.config.js +17 -7
- data/src/.npmignore +2 -0
- data/src/js/controllers/color_mode_controller.js +41 -0
- data/src/js/controllers/frame_navigator_controller.js +99 -0
- data/src/js/controllers/has_many_panel_controller.js +8 -0
- data/src/js/controllers/nav_grid_menu_controller.js +8 -0
- data/src/js/controllers/nav_grid_menu_item_controller.js +8 -0
- data/{app/views/components/tab_bar/tab_bar_controller.js → src/js/controllers/nav_user_controller.js} +2 -2
- data/src/js/controllers/nav_user_link_controller.js +8 -0
- data/src/js/controllers/nav_user_section_controller.js +8 -0
- data/src/js/controllers/register_controllers.js +45 -0
- data/{app/assets/javascripts → src/js}/controllers/resource_dismiss_controller.js +2 -0
- data/{app/assets/javascripts → src/js}/controllers/resource_drop_down_controller.js +2 -0
- data/src/js/controllers/resource_header_controller.js +8 -0
- data/src/js/controllers/resource_layout_controller.js +8 -0
- data/src/js/controllers/sidebar_menu_controller.js +8 -0
- data/src/js/controllers/sidebar_menu_item_controller.js +8 -0
- data/src/js/core.js +4 -0
- data/{app/assets/javascripts/plutonium-app.js → src/js/plutonium.js} +1 -1
- data/{app/assets/javascripts → src/js}/turbo/turbo_debug.js +2 -4
- data/tailwind.config.js +85 -84
- metadata +106 -41
- data/app/assets/build/plutonium.js +0 -5122
- data/app/assets/javascripts/controllers/index.js +0 -34
- data/app/assets/javascripts/plutonium.js +0 -1
- data/app/views/application/_color_modes.html.erb +0 -57
- data/app/views/components/tab_bar/tab_bar_component.html.erb +0 -11
- data/app/views/components/tab_bar/tab_bar_component.rb +0 -9
- data/app/views/resource/_nav_user.html.erb +0 -4
- data/app/views/resource/_tab_menu.html.erb +0 -13
- data/css.manifest +0 -3
- data/js.manifest +0 -4
- data/lib/generators/pu/pkg/app/templates/app/controllers/app_controller.rb.tt +0 -5
- data/lib/generators/pu/pkg/app/templates/app/controllers/package_controller.rb.tt +0 -26
- data/public/plutonium-assets/application.css +0 -25086
- data/public/plutonium-assets/plutonium-app-36KN5FVJ.js +0 -6
- data/public/plutonium-assets/plutonium-app-36KN5FVJ.js.map +0 -7
- data/public/plutonium-assets/plutonium-app-6WILQCTT.js +0 -39
- data/public/plutonium-assets/plutonium-app-6WILQCTT.js.map +0 -7
- data/public/plutonium-assets/plutonium.2d4f0c333cd000051d3b.css +0 -3424
- data/public/plutonium-assets/plutonium.50232e35b5495f5ad90d.css +0 -3415
- /data/{app/assets/build → lib/generators/pu/core/assets/templates}/.keep +0 -0
- /data/lib/generators/pu/rodauth/templates/app/{misc → rodauth}/rodauth_app.rb.tt +0 -0
- /data/{app/assets/stylesheets → src/css}/plutonium.css +0 -0
- /data/{app/views/components/form → src/js/controllers}/form_controller.js +0 -0
- /data/{app/views/components/interactive_action_form → src/js/controllers}/interactive_action_form_controller.js +0 -0
- /data/{app/views/components/nested_resource_form_fields → src/js/controllers}/nested_resource_form_fields_controller.js +0 -0
- /data/{app/views/components/table → src/js/controllers}/table_controller.js +0 -0
- /data/{app/views/components/table_search_input → src/js/controllers}/table_search_input_controller.js +0 -0
- /data/{app/views/components/table_toolbar → src/js/controllers}/table_toolbar_controller.js +0 -0
- /data/{app/views/components/toolbar → src/js/controllers}/toolbar_controller.js +0 -0
- /data/{app/assets/javascripts → src/js}/turbo/index.js +0 -0
- /data/{app/assets/javascripts → src/js}/turbo/turbo_actions.js +0 -0
- /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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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 :
|
|
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
|
|
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
|
|
@@ -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)
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
module Plutonium
|
|
2
2
|
module Helpers
|
|
3
3
|
module ApplicationHelper
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
14
|
-
|
|
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] ||=
|
|
9
|
+
options[:builder] ||= PlutoniumUi::FormBuilder
|
|
10
10
|
options[:wrapper] ||= :default_resource_form
|
|
11
11
|
options[:html] ||= {}
|
|
12
12
|
unless options[:html].key?(:novalidate)
|
data/lib/plutonium/helpers.rb
CHANGED
data/lib/plutonium/icons.rb
CHANGED
|
@@ -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
|
-
|
|
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)
|
|
27
|
+
File.read(path)
|
|
21
28
|
end
|
|
22
29
|
end
|
|
23
30
|
end
|
data/lib/plutonium/pkg/app.rb
CHANGED
|
@@ -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
|
data/lib/plutonium/railtie.rb
CHANGED
|
@@ -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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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.
|
|
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.
|
|
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: ["/
|
|
29
|
-
root: Plutonium.root.join("
|
|
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?
|
data/lib/plutonium/reloader.rb
CHANGED
|
@@ -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
|
-
|
|
11
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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]
|
|
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
|