Sha256: d698bbbb0d9cf89e2fabd9cfe3d55d2159859dd012e8a517d37ed7e20fbc8f32
Contents?: true
Size: 1.33 KB
Versions: 8
Compression:
Stored size: 1.33 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", "#{file_name}_component.rb") end def create_template_file template "component.html.erb", File.join("app/components", "#{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
8 entries across 8 versions & 1 rubygems