Sha256: 6827df9113f1df15b251862533bcf1fa1f41796b948e9bcef21b4e887c86574f
Contents?: true
Size: 1.12 KB
Versions: 5
Compression:
Stored size: 1.12 KB
Contents
# frozen_string_literal: true module Rails module Generators class ComponentGenerator < Rails::Generators::NamedBase source_root File.expand_path("templates", __dir__) argument :attributes, type: :array, default: [], banner: "attribute" check_class_collision suffix: "Component" def create_component_file template "component.rb", File.join("app/components", class_path, "#{file_name}_component.rb") end hook_for :test_framework 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 def initialize_signature if attributes.present? attributes.map { |attr| "#{attr.name}:" }.join(", ") else "*" end end def initialize_body attributes.map { |attr| "@#{attr.name} = #{attr.name}" }.join("\n ") end end end end
Version data entries
5 entries across 5 versions & 2 rubygems