plutonium 0.10.3 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- 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 +2 -2
- 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.erb +21 -37
- data/app/views/layouts/rodauth.html.erb +32 -30
- 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/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/gem/dotenv/templates/config/initializers/001_ensure_required_env.rb +6 -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/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/service/sidekiq/sidekiq_generator.rb +0 -5
- data/lib/generators/pu/service/sidekiq/templates/app/sidekiq/sidekiq_job.rb +0 -2
- data/lib/plutonium/config.rb +2 -14
- 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/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 +20 -8
- data/lib/plutonium/reloader.rb +18 -7
- data/lib/plutonium/resource/controller.rb +4 -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 +9 -57
- 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 +73 -39
- 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/public/plutonium-assets/plutonium.8bee7a8482988b0360e3.css +0 -3420
- /data/{app/assets/build → lib/generators/pu/core/assets/templates}/.keep +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
@@ -17,7 +17,7 @@ module Pu
|
|
17
17
|
source_feature = select_feature
|
18
18
|
source_module = (source_feature == "main_app") ? "ResourceRecord" : "#{source_feature.classify}::ResourceRecord"
|
19
19
|
|
20
|
-
|
20
|
+
Plutonium.eager_load_rails!
|
21
21
|
available_resources = source_module.constantize.descendants.map(&:to_s)
|
22
22
|
selected_resources = prompt.multi_select("Select resources", available_resources)
|
23
23
|
|
@@ -27,9 +27,9 @@ module Pu
|
|
27
27
|
@resource_class = resource
|
28
28
|
|
29
29
|
template "app/controllers/resource_controller.rb", "packages/#{package_namespace}/app/controllers/#{package_namespace}/#{resource.pluralize.underscore}_controller.rb"
|
30
|
-
template "app/policies/resource_policy.rb", "packages/#{package_namespace}/app/policies/#{package_namespace}/#{resource.underscore}_policy.rb"
|
31
|
-
template "app/presenters/resource_presenter.rb", "packages/#{package_namespace}/app/presenters/#{package_namespace}/#{resource.underscore}_presenter.rb"
|
32
|
-
template "app/query_objects/resource_query_object.rb", "packages/#{package_namespace}/app/query_objects/#{package_namespace}/#{resource.underscore}_query_object.rb"
|
30
|
+
# template "app/policies/resource_policy.rb", "packages/#{package_namespace}/app/policies/#{package_namespace}/#{resource.underscore}_policy.rb"
|
31
|
+
# template "app/presenters/resource_presenter.rb", "packages/#{package_namespace}/app/presenters/#{package_namespace}/#{resource.underscore}_presenter.rb"
|
32
|
+
# template "app/query_objects/resource_query_object.rb", "packages/#{package_namespace}/app/query_objects/#{package_namespace}/#{resource.underscore}_query_object.rb"
|
33
33
|
|
34
34
|
insert_into_file "packages/#{package_namespace}/lib/engine.rb",
|
35
35
|
indent("register_resource ::#{resource}\n", 6),
|
@@ -14,9 +14,9 @@ module Pu
|
|
14
14
|
def run_create_model
|
15
15
|
model_class = class_name.safe_constantize
|
16
16
|
if model_class.present? && !model_class.include?(Plutonium::Resource::Record)
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
gsub_file File.join("app/models", class_path, "#{file_name}.rb"),
|
18
|
+
"< ApplicationRecord",
|
19
|
+
"< ResourceRecord"
|
20
20
|
end
|
21
21
|
|
22
22
|
create_model_file if create_files?
|
@@ -19,5 +19,11 @@ class <%= class_name %>Policy < <%= [feature_package_name, "ResourcePolicy"].joi
|
|
19
19
|
def permitted_attributes_for_read
|
20
20
|
<%= attributes.select{ |a| !a.rich_text? && !a.password_digest? && !a.token? }.map(&:name).map(&:to_sym).inspect %>
|
21
21
|
end
|
22
|
+
|
23
|
+
# Associations
|
24
|
+
|
25
|
+
def permitted_associations
|
26
|
+
%i[]
|
27
|
+
end
|
22
28
|
end
|
23
29
|
<% end -%>
|
@@ -13,14 +13,9 @@ module Pu
|
|
13
13
|
|
14
14
|
def start
|
15
15
|
bundle "sidekiq"
|
16
|
-
bundle "sidekiq-failures"
|
17
16
|
directory "app"
|
18
17
|
directory "config"
|
19
18
|
|
20
|
-
in_root do
|
21
|
-
insert_into_file "app/jobs/application_job.rb", "\n sidekiq_options failures: :exhausted\n", before: /^end/
|
22
|
-
end
|
23
|
-
|
24
19
|
add_compose_env :REDIS_QUEUE_URL, "redis://redis-queue/0"
|
25
20
|
add_required_env_vars :REDIS_QUEUE_URL
|
26
21
|
add_compose_dependency redis_service
|
data/lib/plutonium/config.rb
CHANGED
@@ -3,19 +3,7 @@ require "active_model"
|
|
3
3
|
|
4
4
|
module Plutonium
|
5
5
|
module Config
|
6
|
-
mattr_accessor :
|
7
|
-
@@
|
8
|
-
"<link rel=\"stylesheet\" href=\"#{Plutonium.stylesheet_link}\" data-turbo-track=\"reload\" />".html_safe
|
9
|
-
}
|
10
|
-
|
11
|
-
mattr_accessor :script_tag
|
12
|
-
@@script_tag = ->(view_context) {
|
13
|
-
"<script src=\"#{Plutonium.script_link}\" data-turbo-track=\"reload\"></script>".html_safe
|
14
|
-
}
|
15
|
-
|
16
|
-
mattr_accessor :favicon_tag
|
17
|
-
@@favicon_tag = ->(view_context) {
|
18
|
-
"<link rel=\"icon\" type=\"image/x-icon\" href=\"#{Plutonium.favicon_link}\">".html_safe
|
19
|
-
}
|
6
|
+
mattr_accessor :logo
|
7
|
+
@@logo = "plutonium-logo.png"
|
20
8
|
end
|
21
9
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Plutonium
|
2
|
+
module Core
|
3
|
+
module Associations
|
4
|
+
module Renderers
|
5
|
+
class BasicRenderer
|
6
|
+
attr_reader :name, :label, :reflection, :user_options
|
7
|
+
|
8
|
+
def initialize(name, label:, reflection:, **user_options)
|
9
|
+
@name = name
|
10
|
+
@label = label
|
11
|
+
@reflection = reflection
|
12
|
+
@user_options = user_options
|
13
|
+
end
|
14
|
+
|
15
|
+
def render(view_context, record)
|
16
|
+
raise NotImplementedError
|
17
|
+
end
|
18
|
+
|
19
|
+
def options = @options ||= renderer_options.deep_merge(@user_options)
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def renderer_options = {}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require "simple_form/map_type"
|
2
|
+
|
3
|
+
module Plutonium
|
4
|
+
module Core
|
5
|
+
module Associations
|
6
|
+
module Renderers
|
7
|
+
class Factory
|
8
|
+
extend ::SimpleForm::MapType
|
9
|
+
|
10
|
+
map_type :has_many, to: Plutonium::Core::Associations::Renderers::HasManyRenderer
|
11
|
+
|
12
|
+
def self.build(name, type:, **)
|
13
|
+
mapping = mappings[type]
|
14
|
+
raise ArgumentError, "Unknown association renderer type #{type}" unless mapping.present?
|
15
|
+
|
16
|
+
mapping.new(name, **)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.for_resource_association(resource_class, attr_name, **options)
|
20
|
+
options[:label] ||= resource_class.human_attribute_name(attr_name)
|
21
|
+
|
22
|
+
association = resource_class.try(:reflect_on_association, attr_name)
|
23
|
+
raise ArgumentError, "#{attr_name} is not a valid association of #{resource_class}" unless association.present?
|
24
|
+
raise ArgumentError, "#{association.klass} does is not a resource record" unless association.klass.include?(Plutonium::Resource::Record)
|
25
|
+
|
26
|
+
type = association.macro
|
27
|
+
raise NotImplementedError, "#{macro} associations are currently not supported." unless type == :has_many
|
28
|
+
|
29
|
+
options[:reflection] = association
|
30
|
+
build(attr_name, type:, **options)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Plutonium
|
2
|
+
module Core
|
3
|
+
module Associations
|
4
|
+
module Renderers
|
5
|
+
class HasManyRenderer < BasicRenderer
|
6
|
+
def render(view_context, record)
|
7
|
+
view_context.render_component :has_many_panel,
|
8
|
+
title: label,
|
9
|
+
src: view_context.resource_url_for(reflection.klass, parent: record),
|
10
|
+
**options
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Plutonium
|
2
|
+
module Core
|
3
|
+
module Autodiscovery
|
4
|
+
module AssociationRendererDiscoverer
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
include Discoverer
|
7
|
+
|
8
|
+
class_methods do
|
9
|
+
def autodiscovery_association_renderer_cache = @autodiscovery_association_renderer_cache ||= {}
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
# If cache_discovery is enabled, use the class level cache that persists
|
15
|
+
# between requests, otherwise use the instance one.
|
16
|
+
def autodiscovery_association_renderer_cache
|
17
|
+
if Rails.application.config.plutonium.cache_discovery
|
18
|
+
self.class.autodiscovery_association_renderer_cache
|
19
|
+
else
|
20
|
+
@autodiscovery_association_renderer_cache ||= {}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def autodiscover_association_renderer(name)
|
25
|
+
autodiscovery_association_renderer_cache[name] ||=
|
26
|
+
Plutonium::Core::Associations::Renderers::Factory.for_resource_association(resource_class, name)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -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
|
-
Plutonium.application_name
|
33
|
+
def make_page_title(title)
|
34
|
+
[title.presence, helpers.application_name].compact.join(" | ")
|
39
35
|
end
|
40
36
|
|
41
37
|
#
|
@@ -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
|