Sha256: 4f630676d4f65fa05ca990631b31b499642d69cc312e55159b5f5b49636e8277

Contents?: true

Size: 854 Bytes

Versions: 15

Compression:

Stored size: 854 Bytes

Contents

# frozen_string_literal: true

require "rails/generators"

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

  def initialize_reflexes
    copy_reflex_files
  end

  def initialize_controllers
    copy_controller_files
  end

  private

  CONTROLLER_BASE_PATH = "app/javascript/controllers"
  REFLEX_BASE_PATH = "app/reflexes"

  def copy_reflex_files
    template "application_reflex.rb", File.join(REFLEX_BASE_PATH, "application_reflex.rb")
    template "custom_reflex.rb", File.join(REFLEX_BASE_PATH, "#{name.underscore}_reflex.rb")
  end

  def copy_controller_files
    template "application_controller.js", File.join(CONTROLLER_BASE_PATH, "application_controller.js")
    template "custom_controller.js", File.join(CONTROLLER_BASE_PATH, "#{name.underscore}_controller.js")
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
stimulus_reflex-3.1.4 lib/generators/stimulus_reflex_generator.rb
stimulus_reflex-3.1.3 lib/generators/stimulus_reflex_generator.rb
stimulus_reflex-3.1.2 lib/generators/stimulus_reflex_generator.rb
stimulus_reflex-3.0.0 lib/generators/stimulus_reflex_generator.rb
stimulus_reflex-2.2.3 lib/generators/stimulus_reflex_generator.rb
stimulus_reflex-2.2.2 lib/generators/stimulus_reflex_generator.rb
stimulus_reflex-2.2.1 lib/generators/stimulus_reflex_generator.rb
stimulus_reflex-2.2.0 lib/generators/stimulus_reflex_generator.rb
stimulus_reflex-2.1.9 lib/generators/stimulus_reflex_generator.rb
stimulus_reflex-2.1.8 lib/generators/stimulus_reflex_generator.rb
stimulus_reflex-2.1.7 lib/generators/stimulus_reflex_generator.rb
stimulus_reflex-2.1.6 lib/generators/stimulus_reflex_generator.rb
stimulus_reflex-2.1.5 lib/generators/stimulus_reflex_generator.rb
stimulus_reflex-2.1.4 lib/generators/stimulus_reflex_generator.rb
stimulus_reflex-2.1.3 lib/generators/stimulus_reflex_generator.rb