lib/rails/generators/component/component_generator.rb in view_component-2.40.0 vs lib/rails/generators/component/component_generator.rb in view_component-2.41.0
- old
+ new
@@ -10,10 +10,11 @@
source_root File.expand_path("templates", __dir__)
argument :attributes, type: :array, default: [], banner: "attribute"
check_class_collision suffix: "Component"
class_option :inline, type: :boolean, default: false
+ class_option :parent, type: :string, desc: "The parent class for the generated component"
class_option :stimulus, type: :boolean, default: ViewComponent::Base.generate_stimulus_controller
class_option :sidecar, type: :boolean, default: false
def create_component_file
template "component.rb", File.join(component_path, class_path, "#{file_name}_component.rb")
@@ -30,11 +31,13 @@
end
private
def parent_class
- defined?(ApplicationComponent) ? "ApplicationComponent" : "ViewComponent::Base"
+ return options[:parent] if options[:parent]
+
+ ViewComponent::Base.component_parent_class || default_parent_class
end
def initialize_signature
return if attributes.blank?
@@ -45,9 +48,13 @@
attributes.map { |attr| "@#{attr.name} = #{attr.name}" }.join("\n ")
end
def initialize_call_method_for_inline?
options["inline"]
+ end
+
+ def default_parent_class
+ defined?(ApplicationComponent) ? ApplicationComponent : ViewComponent::Base
end
end
end
end