Class: RubyUIAdmin::Generators::AssetsGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/ruby_ui_admin/assets/assets_generator.rb

Overview

Wires the admin's Stimulus controllers into the host app, tailored to its JS setup. The gem ships them flat (e.g. rua--bulk-select_controller.js) plus an index.js that imports and registers every one under the identifier its markup expects (rua--bulk-select, ruby-ui--toaster, …).

rails g ruby_ui_admin:assets
  • Bundler (esbuild/jsbundling/vite): copies the whole directory verbatim into app/javascript/ruby_ui_admin/ (a sibling of controllers/, so the host's eagerLoadControllersFrom("controllers", …) doesn't re-register them under bogus names). The bundler inlines index.js's relative imports, so you just import "./ruby_ui_admin".
  • Importmap + Propshaft: does NOT copy. Copied files get content-digested, and index.js's relative ./x.js imports resolve to the undigested URLs Propshaft won't serve → 404. Instead it pins the copy the engine already serves undigested via Rack::Static at <ASSETS_MOUNT_PATH>/controllers/index.js, where relative imports work and @hotwired/stimulus / @hotwired/turbo resolve through the host's own import map.

Either way, no stimulus:manifest:update — the shipped index.js does the registration.

Constant Summary collapse

DEST =
"app/javascript/ruby_ui_admin"
SERVED_INDEX =

The engine serves its controllers undigested here (see Engine's Rack::Static mount).

"#{RubyUIAdmin::ASSETS_MOUNT_PATH}/controllers/index.js"

Instance Method Summary collapse

Instance Method Details

#installObject



36
37
38
39
40
41
42
43
# File 'lib/generators/ruby_ui_admin/assets/assets_generator.rb', line 36

def install
  if importmap?
    print_importmap_wiring
  else
    directory "public/ruby-ui-admin-assets/controllers", DEST
    print_bundler_wiring
  end
end