Class: SMEditor::Generators::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/smeditor/install_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_paths ⇒ Object

Two source roots: the generator templates, and the packaged boot script. Copying the shipped asset rather than a duplicate template keeps a single source of truth for the JavaScript.



22
23
24
25
26
27
# File 'lib/generators/smeditor/install_generator.rb', line 22

def self.source_paths
  [
    File.expand_path("templates", __dir__),
    File.expand_path("../../../app/assets/javascripts", __dir__),
  ]
end

Instance Method Details

#copy_boot_script ⇒ Object

The boot script imports @smeditor/* by bare specifier, so it has to be compiled by the host app's JavaScript bundler. Sprockets and importmap cannot resolve those imports; jsbundling-rails (esbuild, rollup, webpack) or Vite can.



37
38
39
# File 'lib/generators/smeditor/install_generator.rb', line 37

def copy_boot_script
  copy_file "smeditor.js", "app/javascript/smeditor.js" unless options[:skip_javascript]
end

#copy_initializer ⇒ Object



29
30
31
# File 'lib/generators/smeditor/install_generator.rb', line 29

def copy_initializer
  template "initializer.rb", "config/initializers/smeditor.rb"
end

#show_next_steps ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/generators/smeditor/install_generator.rb', line 41

def show_next_steps
  say ""
  say "SMEditor installed. Next:"
  say "  1. npm install @smeditor/react @smeditor/starter-kit \\"
  say "                 @smeditor/full-kit @smeditor/theme-default react react-dom"
  say "  2. Add `import \"./smeditor\"` to app/javascript/application.js"
  say "  3. For uploads: set config.uploads = :active_storage and mount"
  say "     `mount SMEditor::Rails::Engine => \"/smeditor\"` in config/routes.rb"
  say ""
end