Sha256: 09198e9ad2aa6a34ee6e0a8dc3d2485b64e60bb321bb4694e7902e3ab09c7b29
Contents?: true
Size: 1.36 KB
Versions: 4
Compression:
Stored size: 1.36 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" hook_for :test_framework check_class_collision suffix: "Component" def create_component_file template "component.rb", File.join("app/components", class_path, "#{file_name}_component.rb") end def create_template_file template "component.html.erb", File.join("app/components", class_path, "#{file_name}_component.html.erb") end private def file_name @_file_name ||= super.sub(/_component\z/i, "") end def requires_content? return @requires_content if @asked @asked = true @requires_content = ask("Would you like #{class_name} to require content? (Y/n)").downcase == "y" end def parent_class defined?(ApplicationComponent) ? "ApplicationComponent" : "ActionView::Component::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
4 entries across 4 versions & 1 rubygems