Sha256: 9e8bc668ec8b51244dde3f5aed581f03c8a732fac8ce6c1fa2aa294bdf254848

Contents?: true

Size: 776 Bytes

Versions: 7

Compression:

Stored size: 776 Bytes

Contents

require "rails/generators/named_base"

class StimulusGenerator < Rails::Generators::NamedBase # :nodoc:
  source_root File.expand_path("templates", __dir__)

  class_option :skip_manifest, type: :boolean, default: false, desc: "Don't update the stimulus manifest"

  def copy_view_files
    @attribute = stimulus_attribute_value(controller_name)
    template "controller.js", "app/javascript/controllers/#{controller_name}_controller.js"
    rails_command "stimulus:manifest:update" unless Rails.root.join("config/importmap.rb").exist? || options[:skip_manifest]
  end

  private
    def controller_name
      name.underscore.gsub(/_controller$/, "")
    end

    def stimulus_attribute_value(controller_name)
      controller_name.gsub(/\//, "--").gsub("_", "-")
    end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
stimulus-rails-1.3.4 lib/generators/stimulus/stimulus_generator.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/stimulus-rails-1.3.3/lib/generators/stimulus/stimulus_generator.rb
stimulus-rails-1.3.3 lib/generators/stimulus/stimulus_generator.rb
stimulus-rails-1.3.2 lib/generators/stimulus/stimulus_generator.rb
stimulus-rails-1.3.1 lib/generators/stimulus/stimulus_generator.rb
stimulus-rails-1.3.0 lib/generators/stimulus/stimulus_generator.rb
stimulus-rails-1.2.2 lib/generators/stimulus/stimulus_generator.rb