Class: Preview::Generators::ComponentGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/rails/generators/preview/component_generator.rb

Instance Method Summary collapse

Instance Method Details

#create_preview_fileObject



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/rails/generators/preview/component_generator.rb', line 12

def create_preview_file
  preview_paths = ViewComponent::Base.config.preview_paths
  optional_path = options[:preview_path]
  return if preview_paths.count > 1 && optional_path.blank?

  path_prefix = if optional_path.present?
    optional_path
  else
    preview_paths.one? ? preview_paths.first : "test/components/previews"
  end

  template "component_preview.rb", File.join(path_prefix, class_path, "#{file_name}_component_preview.rb")
end