lib/rails/generators/component/component_generator.rb in view_component-2.34.0 vs lib/rails/generators/component/component_generator.rb in view_component-2.35.0
- old
+ new
@@ -1,18 +1,22 @@
# frozen_string_literal: true
+require "rails/generators/abstract_generator"
+
module Rails
module Generators
class ComponentGenerator < Rails::Generators::NamedBase
+ include ViewComponent::AbstractGenerator
+
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
def create_component_file
- template "component.rb", File.join("app/components", class_path, "#{file_name}_component.rb")
+ template "component.rb", File.join(component_path, class_path, "#{file_name}_component.rb")
end
hook_for :test_framework
hook_for :preview, type: :boolean
@@ -20,13 +24,9 @@
hook_for :template_engine do |instance, template_engine|
instance.invoke template_engine, [instance.name]
end
private
-
- def file_name
- @_file_name ||= super.sub(/_component\z/i, "")
- end
def parent_class
defined?(ApplicationComponent) ? "ApplicationComponent" : "ViewComponent::Base"
end