Sha256: 69cf66c077d46432f42b3e694f63e2f822833590601a86cb8085fb5aa4213348

Contents?: true

Size: 721 Bytes

Versions: 4

Compression:

Stored size: 721 Bytes

Contents

# frozen_string_literal: true

module Stimulus
  module Generators
    class ComponentGenerator < ::Rails::Generators::NamedBase
      include ViewComponent::AbstractGenerator

      source_root File.expand_path("templates", __dir__)
      class_option :sidecar, type: :boolean, default: false

      def create_stimulus_controller
        template "component_controller.js", destination
      end

      private

      def destination
        if options["sidecar"]
          File.join(component_path, class_path, "#{file_name}_component", "#{file_name}_component_controller.js")
        else
          File.join(component_path, class_path, "#{file_name}_component_controller.js")
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
view_component-2.41.0 lib/rails/generators/stimulus/component_generator.rb
view_component-2.40.0 lib/rails/generators/stimulus/component_generator.rb
view_component-2.39.0 lib/rails/generators/stimulus/component_generator.rb
view_component-2.38.0 lib/rails/generators/stimulus/component_generator.rb