plutonium 0.12.9 → 0.12.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/views/components/form/form_component.html.erb +1 -3
- data/app/views/components/interactive_action_form/interactive_action_form_component.html.erb +5 -7
- data/app/views/components/nested_resource_form_fields/nested_resource_form_fields_component.html.erb +2 -2
- data/app/views/components/table_search_input/table_search_input_component.html.erb +8 -2
- data/app/views/resource/_interactive_resource_action_form.html.erb +1 -1
- data/app/views/resource/_resource_details.html.erb +9 -2
- data/app/views/resource/_resource_table.html.erb +9 -1
- data/lib/generators/pu/core/assets/templates/tailwind.config.js +2 -0
- data/lib/generators/pu/core/install/install_generator.rb +1 -1
- data/lib/generators/pu/core/install/templates/config/initializers/plutonium.rb +4 -0
- data/lib/generators/pu/eject/layout/layout_generator.rb +3 -2
- data/lib/generators/pu/eject/shell/shell_generator.rb +3 -2
- data/lib/generators/pu/field/input/input_generator.rb +32 -0
- data/lib/generators/pu/field/input/templates/.keep +0 -0
- data/lib/generators/pu/field/input/templates/input.rb.tt +15 -0
- data/lib/generators/pu/field/renderer/renderer_generator.rb +32 -0
- data/lib/generators/pu/field/renderer/templates/.keep +0 -0
- data/lib/generators/pu/field/renderer/templates/renderer.rb.tt +9 -0
- data/lib/plutonium/core/actions/interactive_action.rb +2 -2
- data/lib/plutonium/core/associations/renderers/base.rb +77 -0
- data/lib/plutonium/core/associations/renderers/factory.rb +0 -2
- data/lib/plutonium/core/associations/renderers/has_many_renderer.rb +6 -4
- data/lib/plutonium/core/controllers/crud_actions.rb +1 -1
- data/lib/plutonium/core/controllers/presentable.rb +3 -3
- data/lib/plutonium/core/definers/field_definer.rb +4 -4
- data/lib/plutonium/core/definers/{input_definer.rb → field_input_definer.rb} +4 -4
- data/lib/plutonium/core/definers/{renderer_definer.rb → field_renderer_definer.rb} +10 -10
- data/lib/plutonium/core/fields/inputs/attachment_input.rb +2 -2
- data/lib/plutonium/core/fields/inputs/base.rb +76 -10
- data/lib/plutonium/core/fields/inputs/checkbox_input.rb +3 -1
- data/lib/plutonium/core/fields/inputs/date_time_input.rb +3 -1
- data/lib/plutonium/core/fields/inputs/nested_input.rb +36 -21
- data/lib/plutonium/core/fields/inputs/noop_input.rb +1 -4
- data/lib/plutonium/core/fields/inputs/polymorphic_belongs_to_association_input.rb +8 -7
- data/lib/plutonium/core/fields/inputs/simple_form_association_input.rb +4 -5
- data/lib/plutonium/core/fields/inputs/simple_form_input.rb +2 -3
- data/lib/plutonium/core/fields/renderers/association_renderer.rb +11 -5
- data/lib/plutonium/core/fields/renderers/attachment_renderer.rb +3 -10
- data/lib/plutonium/core/fields/renderers/base.rb +83 -0
- data/lib/plutonium/core/fields/renderers/basic_renderer.rb +3 -17
- data/lib/plutonium/core/fields/renderers/factory.rb +0 -1
- data/lib/plutonium/core/renderable.rb +20 -0
- data/lib/plutonium/helpers/display_helper.rb +1 -1
- data/lib/plutonium/resource/controller.rb +1 -1
- data/lib/plutonium/resource/policy.rb +1 -1
- data/lib/plutonium/resource/presenter.rb +3 -3
- data/lib/plutonium/resource/query_object.rb +4 -4
- data/lib/plutonium/resource/record.rb +1 -1
- data/lib/plutonium/simple_form/attachment_component.rb +1 -1
- data/lib/plutonium/version.rb +1 -1
- data/package.json +1 -1
- metadata +13 -5
- data/lib/plutonium/core/associations/renderers/basic_renderer.rb +0 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 053e7c4ed94242099eed9ecf819521ccb175ab5e8649a6b771ffe86b743cff64
|
4
|
+
data.tar.gz: 83a54d5ded5d6ed7fcf68179cc0ecd99d92975f1965edefb029731b749c1963c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bdeb350835e78ff12d69789507bb3be8ac9b36dfb174e56d0e85ec85b97a47a41d32080ba626fb19cfaa46b3bc31913f209c58a3a4484dc40c8588398c83ada9
|
7
|
+
data.tar.gz: cd0601de7a8d83add613e97695abad65639bdf988c609c3e587ca41d152aa21dfdb7384e602110dc87ac75d6007d583c52879c8311d4ae83f83022275a202a99
|
@@ -8,20 +8,18 @@
|
|
8
8
|
</svg>
|
9
9
|
<div>
|
10
10
|
<span class="font-medium"><%= f.error_notification %></span>
|
11
|
-
<!--
|
12
11
|
<ul class="mt-1.5 list-disc list-inside">
|
13
12
|
<% f.object.errors.full_messages.each do |message| %>
|
14
13
|
<li><%= f.error_notification message: message %></li>
|
15
14
|
<% end %>
|
16
15
|
</ul>
|
17
|
-
-->
|
18
16
|
</div>
|
19
17
|
</div>
|
20
18
|
<% end %>
|
21
19
|
|
22
20
|
<div>
|
23
21
|
<% form.inputs.values.each do |input| %>
|
24
|
-
<%= input.
|
22
|
+
<%= render input.with(form: f, record: form.record) %>
|
25
23
|
<% end %>
|
26
24
|
</div>
|
27
25
|
|
data/app/views/components/interactive_action_form/interactive_action_form_component.html.erb
CHANGED
@@ -8,20 +8,18 @@
|
|
8
8
|
</svg>
|
9
9
|
<div>
|
10
10
|
<span class="font-medium"><%= f.error_notification %></span>
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
<% end %>
|
11
|
+
<ul class="mt-1.5 list-disc list-inside">
|
12
|
+
<% f.object.errors.full_messages.each do |message| %>
|
13
|
+
<li><%= f.error_notification message: message %></li>
|
14
|
+
<% end %>
|
16
15
|
</ul>
|
17
|
-
-->
|
18
16
|
</div>
|
19
17
|
</div>
|
20
18
|
<% end %>
|
21
19
|
|
22
20
|
<div>
|
23
21
|
<% interactive_action.inputs.values.each do |input| %>
|
24
|
-
<%= input.
|
22
|
+
<%= render input.with(form: f, record: interaction) %>
|
25
23
|
<% end %>
|
26
24
|
</div>
|
27
25
|
|
data/app/views/components/nested_resource_form_fields/nested_resource_form_fields_component.html.erb
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
<%= form.simple_fields_for name, new_record, child_index: 'NEW_RECORD' do |nested| %>
|
12
12
|
<fieldset class="border-t mt-4 pt-4 first:border-t-0 first:pt-0 nested-resource-form-fields" data-new-record="<%= nested.object.new_record? %>">
|
13
13
|
<% inputs.values.each do |input| %>
|
14
|
-
<%= input.
|
14
|
+
<%= render input.with(form: nested, record: new_record) %>
|
15
15
|
<% end %>
|
16
16
|
|
17
17
|
<div class="text-right">
|
@@ -34,7 +34,7 @@
|
|
34
34
|
<%= form.simple_fields_for name do |nested| %>
|
35
35
|
<fieldset class="border-t mt-4 pt-4 first:border-t-0 first:pt-0 nested-resource-form-fields" data-new-record="<%= nested.object.new_record? %>">
|
36
36
|
<% inputs.values.each do |input| %>
|
37
|
-
<%= input.
|
37
|
+
<%= render input.with(form: nested, record: new_record) %>
|
38
38
|
<% end %>
|
39
39
|
|
40
40
|
<div>
|
@@ -7,7 +7,11 @@
|
|
7
7
|
<path fill-rule="evenodd" d="M8 4a4 4 0 100 8 4 4 0 000-8zM2 8a6 6 0 1110.89 3.476l4.817 4.817a1 1 0 01-1.414 1.414l-4.816-4.816A6 6 0 012 8z" clip-rule="evenodd" />
|
8
8
|
</svg>
|
9
9
|
</div>
|
10
|
-
|
10
|
+
|
11
|
+
<%=
|
12
|
+
render search_object.search_filter.input_definitions[:search].with(
|
13
|
+
form: f,
|
14
|
+
record:nil,
|
11
15
|
wrapper: false, label: false,
|
12
16
|
as: :string, # force string for search
|
13
17
|
placeholder: "search...",
|
@@ -21,7 +25,9 @@
|
|
21
25
|
# form_target: "focus",
|
22
26
|
turbo_permanent: true
|
23
27
|
}
|
24
|
-
|
28
|
+
}
|
29
|
+
)
|
30
|
+
%>
|
25
31
|
</div>
|
26
32
|
|
27
33
|
|
@@ -9,12 +9,19 @@
|
|
9
9
|
<div class="p-4">
|
10
10
|
<dl class="divide-y divide-gray-100">
|
11
11
|
<% details.fields.each do |name, renderer| %>
|
12
|
+
<%#
|
13
|
+
TODO:
|
14
|
+
For now, we are hacking around the need to call #with before #label
|
15
|
+
This proves there's an issue with the rendering api.
|
16
|
+
While I think of an elegant solution, this works for now.
|
17
|
+
%>
|
18
|
+
<% renderer.with(record: details.record) %>
|
12
19
|
<div class="py-6 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0">
|
13
20
|
<dt class="text-sm font-medium leading-6 text-gray-900 dark:text-gray-300">
|
14
21
|
<%= renderer.label %>
|
15
22
|
</dt>
|
16
23
|
<dd class="mt-1 text-sm leading-6 text-gray-700 dark:text-gray-200 sm:col-span-2 sm:mt-0">
|
17
|
-
<%=
|
24
|
+
<%= render renderer %>
|
18
25
|
</dd>
|
19
26
|
</div>
|
20
27
|
<% end %>
|
@@ -24,6 +31,6 @@
|
|
24
31
|
|
25
32
|
<% if present_associations? %>
|
26
33
|
<% details.associations.each do |name, renderer| %>
|
27
|
-
<%= renderer.
|
34
|
+
<%= render renderer.with(record: details.record) %>
|
28
35
|
<% end %>
|
29
36
|
<% end %>
|
@@ -71,8 +71,16 @@
|
|
71
71
|
<% end %>
|
72
72
|
|
73
73
|
<% fields.each do |name, field| %>
|
74
|
+
<%#
|
75
|
+
TODO:
|
76
|
+
For now, we are hacking around the need to call #with before #label
|
77
|
+
This proves there's an issue with the rendering api.
|
78
|
+
While I think of an elegant solution, this works for now.
|
79
|
+
%>
|
80
|
+
<% field.with(record: resources[0]) %>
|
74
81
|
<% table.column(name:, label: field.label, search_object: search_object) do |resource| %>
|
75
|
-
|
82
|
+
<% field.with(record: resource) %>
|
83
|
+
<%= render field %>
|
76
84
|
<% end %>
|
77
85
|
<% end %>
|
78
86
|
<% end %>
|
@@ -13,6 +13,8 @@ module.exports = {
|
|
13
13
|
`${__dirname}/app/helpers/**/*.rb`,
|
14
14
|
`${__dirname}/app/assets/stylesheets/**/*.css`,
|
15
15
|
`${__dirname}/app/javascript/**/*.js`,
|
16
|
+
`${__dirname}/app/plutonium/**/*.rb`,
|
17
|
+
`${__dirname}/packages/**/app/plutonium/**/*.rb`,
|
16
18
|
`${__dirname}/packages/**/app/views/**/*.html.erb`,
|
17
19
|
].concat(plutoniumTailwindConfig.content),
|
18
20
|
}
|
@@ -15,11 +15,11 @@ module Pu
|
|
15
15
|
class_option :rodauth, type: :boolean
|
16
16
|
|
17
17
|
def start
|
18
|
-
destination_dir = (destination_app == "main_app") ? "app/views/" : "packages/#{destination_app}/app/views
|
18
|
+
destination_dir = (destination_app == "main_app") ? "app/views/" : "packages/#{destination_app}/app/views/"
|
19
19
|
[
|
20
20
|
"layouts/resource.html.erb"
|
21
21
|
].each do |file|
|
22
|
-
copy_file Plutonium.root.join("app", "views", file), Rails.root.join(destination_dir)
|
22
|
+
copy_file Plutonium.root.join("app", "views", file), Rails.root.join(destination_dir, file)
|
23
23
|
end
|
24
24
|
rescue => e
|
25
25
|
exception "#{self.class} failed:", e
|
@@ -33,6 +33,7 @@ module Pu
|
|
33
33
|
|
34
34
|
def copy_file(source_path, destination_path)
|
35
35
|
if File.exist?(source_path)
|
36
|
+
FileUtils.mkdir_p(File.dirname(destination_path))
|
36
37
|
FileUtils.cp(source_path, destination_path)
|
37
38
|
say_status("info", "Copied #{source_path} to #{destination_path}", :green)
|
38
39
|
else
|
@@ -14,12 +14,12 @@ module Pu
|
|
14
14
|
class_option :dest, type: :string
|
15
15
|
|
16
16
|
def start
|
17
|
-
destination_dir = (destination_app == "main_app") ? "app/views/" : "packages/#{destination_app}/app/views
|
17
|
+
destination_dir = (destination_app == "main_app") ? "app/views/" : "packages/#{destination_app}/app/views"
|
18
18
|
[
|
19
19
|
"application/_resource_header.html.erb",
|
20
20
|
"application/_resource_sidebar.html.erb"
|
21
21
|
].each do |file|
|
22
|
-
copy_file Plutonium.root.join("app", "views", file), Rails.root.join(destination_dir)
|
22
|
+
copy_file Plutonium.root.join("app", "views", file), Rails.root.join(destination_dir, file)
|
23
23
|
end
|
24
24
|
rescue => e
|
25
25
|
exception "#{self.class} failed:", e
|
@@ -33,6 +33,7 @@ module Pu
|
|
33
33
|
|
34
34
|
def copy_file(source_path, destination_path)
|
35
35
|
if File.exist?(source_path)
|
36
|
+
FileUtils.mkdir_p(File.dirname(destination_path))
|
36
37
|
FileUtils.cp(source_path, destination_path)
|
37
38
|
say_status("info", "Copied #{source_path} to #{destination_path}", :green)
|
38
39
|
else
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../../lib/plutonium_generators"
|
4
|
+
|
5
|
+
module Pu
|
6
|
+
module Field
|
7
|
+
class InputGenerator < Rails::Generators::Base
|
8
|
+
include PlutoniumGenerators::Generator
|
9
|
+
|
10
|
+
source_root File.expand_path("templates", __dir__)
|
11
|
+
|
12
|
+
desc "Generates a field input"
|
13
|
+
|
14
|
+
argument :name
|
15
|
+
|
16
|
+
def start
|
17
|
+
in_root do
|
18
|
+
template "input.rb", "app/plutonium/fields/inputs/#{name.underscore}_input.rb"
|
19
|
+
insert_into_file "config/initializers/plutonium.rb", registration_statement, after: /.*# Register components here.*\n/
|
20
|
+
end
|
21
|
+
rescue => e
|
22
|
+
exception "#{self.class} failed:", e
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def registration_statement
|
28
|
+
indent "Plutonium::Core::Fields::Inputs::Factory.map_type :#{name.underscore}, to: Fields::Inputs::#{name.camelize}Input\n", 2
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
File without changes
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../../lib/plutonium_generators"
|
4
|
+
|
5
|
+
module Pu
|
6
|
+
module Field
|
7
|
+
class RendererGenerator < Rails::Generators::Base
|
8
|
+
include PlutoniumGenerators::Generator
|
9
|
+
|
10
|
+
source_root File.expand_path("templates", __dir__)
|
11
|
+
|
12
|
+
desc "Generates a field renderer"
|
13
|
+
|
14
|
+
argument :name
|
15
|
+
|
16
|
+
def start
|
17
|
+
in_root do
|
18
|
+
template "renderer.rb", "app/plutonium/fields/renderers/#{name.underscore}_renderer.rb"
|
19
|
+
insert_into_file "config/initializers/plutonium.rb", registration_statement, after: /.*# Register components here.*\n/
|
20
|
+
end
|
21
|
+
rescue => e
|
22
|
+
exception "#{self.class} failed:", e
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def registration_statement
|
28
|
+
indent "Plutonium::Core::Fields::Renderers::Factory.map_type :#{name.underscore}, to: Fields::Renderers::#{name.camelize}Renderer\n", 2
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
File without changes
|
@@ -2,7 +2,7 @@ module Plutonium
|
|
2
2
|
module Core
|
3
3
|
module Actions
|
4
4
|
class InteractiveAction < Plutonium::Core::Action
|
5
|
-
include Plutonium::Core::Definers::
|
5
|
+
include Plutonium::Core::Definers::FieldInputDefiner
|
6
6
|
|
7
7
|
Context = Data.define :resource_class
|
8
8
|
|
@@ -37,7 +37,7 @@ module Plutonium
|
|
37
37
|
|
38
38
|
def set_interaction(interaction)
|
39
39
|
@interaction = interaction
|
40
|
-
@inputs =
|
40
|
+
@inputs = defined_field_inputs_for(*(interaction.filters.keys - [:resource, :resources]))
|
41
41
|
@inline = @inputs.blank? unless inline == false
|
42
42
|
end
|
43
43
|
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module Plutonium
|
2
|
+
module Core
|
3
|
+
module Associations
|
4
|
+
module Renderers
|
5
|
+
class Base
|
6
|
+
include Plutonium::Core::Renderable
|
7
|
+
|
8
|
+
attr_reader :name, :reflection
|
9
|
+
|
10
|
+
def initialize(name, reflection:, **user_options)
|
11
|
+
@name = name
|
12
|
+
@reflection = reflection
|
13
|
+
@user_options = user_options
|
14
|
+
end
|
15
|
+
|
16
|
+
# Sets the record object on the renderer and merges render options.
|
17
|
+
#
|
18
|
+
# @param record [Object] the record object.
|
19
|
+
# @param render_options [Hash] additional options for rendering.
|
20
|
+
# @return [self] the renderer instance.
|
21
|
+
def with(record:, **render_options)
|
22
|
+
@record = record
|
23
|
+
@render_options = render_options
|
24
|
+
@options = build_options(render_options)
|
25
|
+
|
26
|
+
self
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
# Returns the merged options for rendering.
|
32
|
+
#
|
33
|
+
# @raise [RuntimeError] if accessed before rendering.
|
34
|
+
# @return [Hash] the merged options.
|
35
|
+
def options
|
36
|
+
raise "cannot access #options before calling #with" unless defined?(@options)
|
37
|
+
|
38
|
+
@options
|
39
|
+
end
|
40
|
+
|
41
|
+
# Returns the record object.
|
42
|
+
#
|
43
|
+
# @raise [RuntimeError] if accessed before rendering.
|
44
|
+
# @return [Object] the record object.
|
45
|
+
def record
|
46
|
+
raise "cannot access #record before calling #with" unless defined?(@record)
|
47
|
+
|
48
|
+
@record
|
49
|
+
end
|
50
|
+
|
51
|
+
def renderer_options
|
52
|
+
{}
|
53
|
+
end
|
54
|
+
|
55
|
+
def label
|
56
|
+
options[:label] || record.class.human_attribute_name(name)
|
57
|
+
end
|
58
|
+
|
59
|
+
# Returns the value of the record's attribute corresponding to the renderer's name.
|
60
|
+
#
|
61
|
+
# @return [Object] the value of the attribute.
|
62
|
+
def value
|
63
|
+
record.public_send(name)
|
64
|
+
end
|
65
|
+
|
66
|
+
# Builds the options for rendering by merging renderer options, user options, and render options.
|
67
|
+
#
|
68
|
+
# @param render_options [Hash] additional options for rendering.
|
69
|
+
# @return [Hash] the merged options.
|
70
|
+
def build_options(render_options)
|
71
|
+
renderer_options.deep_merge(@user_options).deep_merge(render_options)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -17,8 +17,6 @@ module Plutonium
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def self.for_resource_association(resource_class, attr_name, **options)
|
20
|
-
options[:label] ||= resource_class.human_attribute_name(attr_name)
|
21
|
-
|
22
20
|
association = resource_class.try(:reflect_on_association, attr_name)
|
23
21
|
raise ArgumentError, "#{attr_name} is not a valid association of #{resource_class}" unless association.present?
|
24
22
|
raise ArgumentError, "#{association.klass} does is not a resource record" unless association.klass.include?(Plutonium::Resource::Record)
|
@@ -2,12 +2,14 @@ module Plutonium
|
|
2
2
|
module Core
|
3
3
|
module Associations
|
4
4
|
module Renderers
|
5
|
-
class HasManyRenderer <
|
6
|
-
def render
|
7
|
-
|
5
|
+
class HasManyRenderer < Base
|
6
|
+
def render
|
7
|
+
render_component(
|
8
|
+
:has_many_panel,
|
8
9
|
title: label,
|
9
|
-
src:
|
10
|
+
src: resource_url_for(reflection.klass, parent: record),
|
10
11
|
**options
|
12
|
+
)
|
11
13
|
end
|
12
14
|
end
|
13
15
|
end
|
@@ -15,7 +15,7 @@ module Plutonium
|
|
15
15
|
@search_object = current_query_object
|
16
16
|
base_query = policy_scope(resource_class)
|
17
17
|
base_query = @search_object.apply(base_query)
|
18
|
-
base_query = base_query.
|
18
|
+
base_query = base_query.public_send(params[:scope].to_sym) if params[:scope].present?
|
19
19
|
@pagy, @resource_records = pagy base_query
|
20
20
|
@collection = build_collection
|
21
21
|
|
@@ -32,7 +32,7 @@ module Plutonium
|
|
32
32
|
Plutonium::Core::Ui::Collection.new(
|
33
33
|
resource_class:,
|
34
34
|
records: @resource_records,
|
35
|
-
fields: current_presenter.
|
35
|
+
fields: current_presenter.defined_field_renderers_for(*presentable_attributes),
|
36
36
|
actions: current_presenter.actions,
|
37
37
|
pager: @pagy,
|
38
38
|
search_object: @search_object
|
@@ -43,7 +43,7 @@ module Plutonium
|
|
43
43
|
Plutonium::Core::Ui::Detail.new(
|
44
44
|
resource_class:,
|
45
45
|
record: resource_record,
|
46
|
-
fields: current_presenter.
|
46
|
+
fields: current_presenter.defined_field_renderers_for(*presentable_attributes),
|
47
47
|
associations: current_presenter.defined_association_renderers_for(*permitted_associations),
|
48
48
|
actions: current_presenter.actions
|
49
49
|
)
|
@@ -52,7 +52,7 @@ module Plutonium
|
|
52
52
|
def build_form
|
53
53
|
Plutonium::Core::Ui::Form.new(
|
54
54
|
record: resource_record,
|
55
|
-
inputs: current_presenter.
|
55
|
+
inputs: current_presenter.defined_field_inputs_for(*presentable_attributes)
|
56
56
|
)
|
57
57
|
end
|
58
58
|
|
@@ -4,14 +4,14 @@ module Plutonium
|
|
4
4
|
module FieldDefiner
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
|
7
|
-
include
|
8
|
-
include
|
7
|
+
include FieldInputDefiner
|
8
|
+
include FieldRendererDefiner
|
9
9
|
|
10
10
|
private
|
11
11
|
|
12
12
|
def define_field(name, type: nil, input: nil, renderer: nil, input_options: {}, renderer_options: {})
|
13
|
-
|
14
|
-
|
13
|
+
define_field_input(name, type:, input:, **input_options)
|
14
|
+
define_field_renderer(name, type:, renderer:, **renderer_options)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Plutonium
|
2
2
|
module Core
|
3
3
|
module Definers
|
4
|
-
module
|
4
|
+
module FieldInputDefiner
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
include Plutonium::Core::Autodiscovery::InputDiscoverer
|
7
7
|
|
@@ -47,14 +47,14 @@ module Plutonium
|
|
47
47
|
attr_reader :hash
|
48
48
|
end
|
49
49
|
|
50
|
-
def
|
50
|
+
def defined_field_inputs_for(*names)
|
51
51
|
(names - input_definitions.keys).each do |name|
|
52
|
-
|
52
|
+
define_field_input(name, input: autodiscover_input(name))
|
53
53
|
end
|
54
54
|
input_definitions.slice(*names)
|
55
55
|
end
|
56
56
|
|
57
|
-
def
|
57
|
+
def define_field_input(name, input: nil, type: nil, **options)
|
58
58
|
input_definitions[name] = if input.present?
|
59
59
|
input
|
60
60
|
elsif type.present?
|
@@ -1,23 +1,23 @@
|
|
1
1
|
module Plutonium
|
2
2
|
module Core
|
3
3
|
module Definers
|
4
|
-
module
|
4
|
+
module FieldRendererDefiner
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
include Plutonium::Core::Autodiscovery::RendererDiscoverer
|
7
7
|
|
8
|
-
def
|
9
|
-
(names -
|
10
|
-
|
8
|
+
def defined_field_renderers_for(*names)
|
9
|
+
(names - field_renderer_definitions.keys).each do |name|
|
10
|
+
define_field_renderer(name, renderer: autodiscover_renderer(name))
|
11
11
|
end
|
12
|
-
|
12
|
+
field_renderer_definitions.slice(*names)
|
13
13
|
end
|
14
14
|
|
15
15
|
private
|
16
16
|
|
17
|
-
def
|
17
|
+
def field_renderer_definitions = @field_renderer_definitions ||= {}
|
18
18
|
|
19
|
-
def
|
20
|
-
|
19
|
+
def define_field_renderer(name, renderer: nil, type: nil, **options)
|
20
|
+
field_renderer_definitions[name] = if renderer.present?
|
21
21
|
renderer
|
22
22
|
elsif type.present?
|
23
23
|
Plutonium::Core::Fields::Renderers::Factory.build(name, type:, **options)
|
@@ -28,8 +28,8 @@ module Plutonium
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
def
|
32
|
-
|
31
|
+
def field_renderer_defined?(name)
|
32
|
+
field_renderer_definitions.key? name
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
@@ -5,9 +5,9 @@ module Plutonium
|
|
5
5
|
class AttachmentInput < SimpleFormInput
|
6
6
|
attr_reader :reflection
|
7
7
|
|
8
|
-
def initialize(name, reflection:, **
|
8
|
+
def initialize(name, reflection:, **options)
|
9
9
|
@reflection = reflection
|
10
|
-
super(name, **
|
10
|
+
super(name, **options)
|
11
11
|
end
|
12
12
|
|
13
13
|
private
|