plutonium 0.12.9 → 0.12.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/# Plutonium: The pre-alpha demo.md +218 -0
  3. data/app/views/components/form/form_component.html.erb +1 -3
  4. data/app/views/components/interactive_action_form/interactive_action_form_component.html.erb +5 -7
  5. data/app/views/components/nested_resource_form_fields/nested_resource_form_fields_component.html.erb +2 -2
  6. data/app/views/components/table_search_input/table_search_input_component.html.erb +8 -2
  7. data/app/views/resource/_interactive_resource_action_form.html.erb +1 -1
  8. data/app/views/resource/_resource_details.html.erb +9 -2
  9. data/app/views/resource/_resource_table.html.erb +9 -1
  10. data/lib/generators/pu/core/assets/templates/tailwind.config.js +2 -0
  11. data/lib/generators/pu/core/install/install_generator.rb +1 -1
  12. data/lib/generators/pu/core/install/templates/config/initializers/plutonium.rb +4 -0
  13. data/lib/generators/pu/eject/layout/layout_generator.rb +3 -2
  14. data/lib/generators/pu/eject/shell/shell_generator.rb +3 -2
  15. data/lib/generators/pu/field/input/input_generator.rb +32 -0
  16. data/lib/generators/pu/field/input/templates/.keep +0 -0
  17. data/lib/generators/pu/field/input/templates/input.rb.tt +15 -0
  18. data/lib/generators/pu/field/renderer/renderer_generator.rb +32 -0
  19. data/lib/generators/pu/field/renderer/templates/.keep +0 -0
  20. data/lib/generators/pu/field/renderer/templates/renderer.rb.tt +9 -0
  21. data/lib/generators/pu/gem/annotate/annotate_generator.rb +22 -0
  22. data/lib/generators/pu/gem/annotate/templates/.keep +0 -0
  23. data/lib/generators/pu/gem/annotate/templates/lib/tasks/auto_annotate_models.rake +59 -0
  24. data/lib/plutonium/core/actions/interactive_action.rb +2 -2
  25. data/lib/plutonium/core/associations/renderers/base.rb +77 -0
  26. data/lib/plutonium/core/associations/renderers/factory.rb +0 -2
  27. data/lib/plutonium/core/associations/renderers/has_many_renderer.rb +6 -4
  28. data/lib/plutonium/core/controllers/crud_actions.rb +1 -1
  29. data/lib/plutonium/core/controllers/presentable.rb +3 -3
  30. data/lib/plutonium/core/definers/field_definer.rb +4 -4
  31. data/lib/plutonium/core/definers/{input_definer.rb → field_input_definer.rb} +4 -4
  32. data/lib/plutonium/core/definers/{renderer_definer.rb → field_renderer_definer.rb} +10 -10
  33. data/lib/plutonium/core/fields/inputs/attachment_input.rb +2 -2
  34. data/lib/plutonium/core/fields/inputs/base.rb +76 -10
  35. data/lib/plutonium/core/fields/inputs/checkbox_input.rb +3 -1
  36. data/lib/plutonium/core/fields/inputs/date_time_input.rb +3 -1
  37. data/lib/plutonium/core/fields/inputs/nested_input.rb +36 -21
  38. data/lib/plutonium/core/fields/inputs/noop_input.rb +1 -4
  39. data/lib/plutonium/core/fields/inputs/polymorphic_belongs_to_association_input.rb +8 -7
  40. data/lib/plutonium/core/fields/inputs/simple_form_association_input.rb +4 -5
  41. data/lib/plutonium/core/fields/inputs/simple_form_input.rb +2 -3
  42. data/lib/plutonium/core/fields/renderers/association_renderer.rb +11 -5
  43. data/lib/plutonium/core/fields/renderers/attachment_renderer.rb +3 -10
  44. data/lib/plutonium/core/fields/renderers/base.rb +83 -0
  45. data/lib/plutonium/core/fields/renderers/basic_renderer.rb +3 -17
  46. data/lib/plutonium/core/fields/renderers/factory.rb +0 -1
  47. data/lib/plutonium/core/renderable.rb +20 -0
  48. data/lib/plutonium/helpers/display_helper.rb +1 -1
  49. data/lib/plutonium/resource/controller.rb +1 -1
  50. data/lib/plutonium/resource/policy.rb +1 -1
  51. data/lib/plutonium/resource/presenter.rb +3 -3
  52. data/lib/plutonium/resource/query_object.rb +4 -4
  53. data/lib/plutonium/resource/record.rb +1 -1
  54. data/lib/plutonium/simple_form/attachment_component.rb +1 -1
  55. data/lib/plutonium/version.rb +1 -1
  56. data/package.json +1 -1
  57. metadata +17 -5
  58. data/lib/plutonium/core/associations/renderers/basic_renderer.rb +0 -28
@@ -0,0 +1,83 @@
1
+ module Plutonium
2
+ module Core
3
+ module Fields
4
+ module Renderers
5
+ class Base
6
+ include Plutonium::Core::Renderable
7
+
8
+ attr_reader :name
9
+
10
+ # Initializes the Base renderer class with a name and user-defined options.
11
+ #
12
+ # @param name [String] the name of the renderer.
13
+ # @param user_options [Hash] user-defined options for the renderer.
14
+ def initialize(name, **user_options)
15
+ @name = name
16
+ @user_options = user_options
17
+ end
18
+
19
+ # Sets the record object on the renderer and merges render options.
20
+ #
21
+ # @param record [Object] the record object.
22
+ # @param render_options [Hash] additional options for rendering.
23
+ # @return [self] the renderer instance.
24
+ def with(record:, **render_options)
25
+ @record = record
26
+ @render_options = render_options
27
+ @options = build_options(render_options)
28
+
29
+ self
30
+ end
31
+
32
+ def label
33
+ options[:label] || record.class.human_attribute_name(name)
34
+ end
35
+
36
+ private
37
+
38
+ # Returns the merged options for rendering.
39
+ #
40
+ # @raise [RuntimeError] if accessed before rendering.
41
+ # @return [Hash] the merged options.
42
+ def options
43
+ raise "cannot access #options before calling #with" unless defined?(@options)
44
+
45
+ @options
46
+ end
47
+
48
+ # Returns the record object.
49
+ #
50
+ # @raise [RuntimeError] if accessed before rendering.
51
+ # @return [Object] the record object.
52
+ def record
53
+ raise "cannot access #record before calling #with" unless defined?(@record)
54
+
55
+ @record
56
+ end
57
+
58
+ # Returns the value of the record's attribute corresponding to the renderer's name.
59
+ #
60
+ # @return [Object] the value of the attribute.
61
+ def value
62
+ record.public_send(name)
63
+ end
64
+
65
+ # Returns renderer-specific options, can be overridden by subclasses.
66
+ #
67
+ # @return [Hash] the renderer-specific options.
68
+ def renderer_options
69
+ {}
70
+ end
71
+
72
+ # Builds the options for rendering by merging renderer options, user options, and render options.
73
+ #
74
+ # @param render_options [Hash] additional options for rendering.
75
+ # @return [Hash] the merged options.
76
+ def build_options(render_options)
77
+ renderer_options.deep_merge(@user_options).deep_merge(render_options)
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
@@ -2,24 +2,10 @@ module Plutonium
2
2
  module Core
3
3
  module Fields
4
4
  module Renderers
5
- class BasicRenderer
6
- attr_reader :name, :label, :user_options
7
-
8
- def initialize(name, label:, **user_options)
9
- @name = name
10
- @label = label
11
- @user_options = user_options
5
+ class BasicRenderer < Base
6
+ def render
7
+ display_field value:, **options
12
8
  end
13
-
14
- def render(view_context, record)
15
- view_context.display_field value: record.send(name), **options
16
- end
17
-
18
- def options = @options ||= renderer_options.deep_merge(@user_options)
19
-
20
- private
21
-
22
- def renderer_options = {}
23
9
  end
24
10
  end
25
11
  end
@@ -17,7 +17,6 @@ module Plutonium
17
17
 
18
18
  def self.for_resource_attribute(resource_class, attr_name, **options)
19
19
  type = nil
20
- options[:label] ||= resource_class.human_attribute_name(attr_name)
21
20
 
22
21
  if (attachment = resource_class.try(:reflect_on_attachment, attr_name))
23
22
  type = :attachment
@@ -0,0 +1,20 @@
1
+ module Plutonium
2
+ module Core
3
+ module Renderable
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ delegate_missing_to :@view_context
8
+ end
9
+
10
+ def render_in(view_context)
11
+ @view_context = view_context
12
+ render
13
+ end
14
+
15
+ def render
16
+ raise NotImplementedError, "#{self.class}#render"
17
+ end
18
+ end
19
+ end
20
+ end
@@ -73,7 +73,7 @@ module Plutonium
73
73
 
74
74
  # Fallback to retrieving the value from a predefined list
75
75
  %i[to_label name title].each do |method|
76
- name = obj.send(method) if obj.respond_to?(method)
76
+ name = obj.public_send(method) if obj.respond_to?(method)
77
77
  return name if name.present?
78
78
  end
79
79
 
@@ -69,7 +69,7 @@ module Plutonium
69
69
  override_entity_scoping_params(input_params)
70
70
  override_parent_params(input_params)
71
71
 
72
- current_presenter.defined_inputs_for(*permitted_attributes).collect_all(input_params)
72
+ current_presenter.defined_field_inputs_for(*permitted_attributes).collect_all(input_params)
73
73
  end
74
74
 
75
75
  # Returns the resource parameter key
@@ -18,7 +18,7 @@ module Plutonium
18
18
  raise NotImplementedError, "#{self.class.name} does not implement the required #{method}"
19
19
  end
20
20
 
21
- send(method)
21
+ public_send(method)
22
22
  end
23
23
 
24
24
  # Core actions
@@ -63,7 +63,7 @@ module Plutonium
63
63
 
64
64
  nested_attribute_options_class = nested_attribute_options&.[](:class)
65
65
  if nested_attribute_options_class.nil? && model_class.nil?
66
- raise ArgumentError, "model_class is required if your field is not an association or is polymorphic"
66
+ raise ArgumentError, "model_class is required if your field is not an association or is polymorphic. also ensure you have called `accepts_nested_attributes_for :#{name}`"
67
67
  end
68
68
  model_class ||= nested_attribute_options_class
69
69
 
@@ -83,7 +83,7 @@ module Plutonium
83
83
  )
84
84
  yield input if block_given?
85
85
 
86
- define_input name, input:
86
+ define_field_input name, input:
87
87
  end
88
88
 
89
89
  # Determines the limit for a nested input
@@ -92,7 +92,7 @@ module Plutonium
92
92
  # @param [Integer, nil] nested_attribute_limit The limit from nested attributes
93
93
  # @return [Integer, nil] The determined limit
94
94
  def determine_nested_input_limit(macro, option_limit, nested_attribute_limit)
95
- if macro == :has_one
95
+ if %i[belongs_to has_one].include? macro
96
96
  1
97
97
  elsif option_limit
98
98
  option_limit
@@ -5,7 +5,7 @@ module Plutonium
5
5
  end
6
6
 
7
7
  class Query
8
- include Plutonium::Core::Definers::InputDefiner
8
+ include Plutonium::Core::Definers::FieldInputDefiner
9
9
 
10
10
  # Applies the query to the given scope using the provided parameters.
11
11
  #
@@ -65,7 +65,7 @@ module Plutonium
65
65
  # @param params [Hash] The parameters for the query.
66
66
  # @return [Object] The modified scope.
67
67
  def apply_internal(scope, params)
68
- scope.send(name, **params)
68
+ scope.public_send(name, **params)
69
69
  end
70
70
  end
71
71
 
@@ -215,7 +215,7 @@ module Plutonium
215
215
  end
216
216
 
217
217
  sort_definitions[name] = build_query(body) do |query|
218
- query.define_input :direction
218
+ query.define_field_input :direction
219
219
  end
220
220
  end
221
221
 
@@ -224,7 +224,7 @@ module Plutonium
224
224
  # @param body [Proc, Symbol] The body of the search filter.
225
225
  def define_search(body)
226
226
  @search_filter = build_query(body) do |query|
227
- query.define_input :search
227
+ query.define_field_input :search
228
228
  end
229
229
  end
230
230
 
@@ -22,7 +22,7 @@ module Plutonium
22
22
  record_association = klass.find_association_to_self(record)
23
23
  if record_association
24
24
  # TODO: add a warning here about a potentially poor performing query
25
- return where(id: record.send(record_association.name))
25
+ return where(id: record.public_send(record_association.name))
26
26
  end
27
27
 
28
28
  klass.raise_association_error(record, named_scope)
@@ -40,7 +40,7 @@ module Plutonium
40
40
  private
41
41
 
42
42
  def value
43
- @value ||= object.send(attribute_name) if object&.respond_to?(attribute_name)
43
+ @value ||= object.public_send(attribute_name) if object&.respond_to?(attribute_name)
44
44
  end
45
45
 
46
46
  def multiple?
@@ -1,3 +1,3 @@
1
1
  module Plutonium
2
- VERSION = "0.12.9"
2
+ VERSION = "0.12.11"
3
3
  end
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@radioactive-labs/plutonium",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Core assets for the Plutonium gem",
5
5
  "type": "module",
6
6
  "main": "src/js/core.js",
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plutonium
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.9
4
+ version: 0.12.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Froelich
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-06-10 00:00:00.000000000 Z
11
+ date: 2024-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zeitwerk
@@ -208,6 +208,7 @@ executables:
208
208
  extensions: []
209
209
  extra_rdoc_files: []
210
210
  files:
211
+ - "# Plutonium: The pre-alpha demo.md"
211
212
  - ".node-version"
212
213
  - ".rspec"
213
214
  - ".ruby-version"
@@ -877,6 +878,15 @@ files:
877
878
  - lib/generators/pu/docker/install/templates/docker-compose.yml
878
879
  - lib/generators/pu/eject/layout/layout_generator.rb
879
880
  - lib/generators/pu/eject/shell/shell_generator.rb
881
+ - lib/generators/pu/field/input/input_generator.rb
882
+ - lib/generators/pu/field/input/templates/.keep
883
+ - lib/generators/pu/field/input/templates/input.rb.tt
884
+ - lib/generators/pu/field/renderer/renderer_generator.rb
885
+ - lib/generators/pu/field/renderer/templates/.keep
886
+ - lib/generators/pu/field/renderer/templates/renderer.rb.tt
887
+ - lib/generators/pu/gem/annotate/annotate_generator.rb
888
+ - lib/generators/pu/gem/annotate/templates/.keep
889
+ - lib/generators/pu/gem/annotate/templates/lib/tasks/auto_annotate_models.rake
880
890
  - lib/generators/pu/gem/dotenv/dotenv_generator.rb
881
891
  - lib/generators/pu/gem/dotenv/templates/.env
882
892
  - lib/generators/pu/gem/dotenv/templates/.env.local
@@ -1029,7 +1039,7 @@ files:
1029
1039
  - lib/plutonium/core/actions/interactive_action.rb
1030
1040
  - lib/plutonium/core/actions/new_action.rb
1031
1041
  - lib/plutonium/core/actions/show_action.rb
1032
- - lib/plutonium/core/associations/renderers/basic_renderer.rb
1042
+ - lib/plutonium/core/associations/renderers/base.rb
1033
1043
  - lib/plutonium/core/associations/renderers/factory.rb
1034
1044
  - lib/plutonium/core/associations/renderers/has_many_renderer.rb
1035
1045
  - lib/plutonium/core/autodiscovery/association_renderer_discoverer.rb
@@ -1047,8 +1057,8 @@ files:
1047
1057
  - lib/plutonium/core/definers/action_definer.rb
1048
1058
  - lib/plutonium/core/definers/association_renderer_definer.rb
1049
1059
  - lib/plutonium/core/definers/field_definer.rb
1050
- - lib/plutonium/core/definers/input_definer.rb
1051
- - lib/plutonium/core/definers/renderer_definer.rb
1060
+ - lib/plutonium/core/definers/field_input_definer.rb
1061
+ - lib/plutonium/core/definers/field_renderer_definer.rb
1052
1062
  - lib/plutonium/core/fields/inputs/attachment_input.rb
1053
1063
  - lib/plutonium/core/fields/inputs/base.rb
1054
1064
  - lib/plutonium/core/fields/inputs/belongs_to_association_input.rb
@@ -1064,8 +1074,10 @@ files:
1064
1074
  - lib/plutonium/core/fields/inputs/simple_form_input.rb
1065
1075
  - lib/plutonium/core/fields/renderers/association_renderer.rb
1066
1076
  - lib/plutonium/core/fields/renderers/attachment_renderer.rb
1077
+ - lib/plutonium/core/fields/renderers/base.rb
1067
1078
  - lib/plutonium/core/fields/renderers/basic_renderer.rb
1068
1079
  - lib/plutonium/core/fields/renderers/factory.rb
1080
+ - lib/plutonium/core/renderable.rb
1069
1081
  - lib/plutonium/core/ui/collection.rb
1070
1082
  - lib/plutonium/core/ui/detail.rb
1071
1083
  - lib/plutonium/core/ui/form.rb
@@ -1,28 +0,0 @@
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