Class: TurboOverlay::Generators::EjectGenerator

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

Overview

Copies gem-owned plumbing into the host app for full control. Once ejected, gem upgrades to that subset don’t flow through. (Chrome partials are copied by the install generator and live in the app from day one, so they’re not part of eject.)

bin/rails g turbo_overlay:eject --js
bin/rails g turbo_overlay:eject --css
bin/rails g turbo_overlay:eject --layouts

Constant Summary collapse

GEM_ROOT =
File.expand_path("../../..", __dir__)

Instance Method Summary collapse

Instance Method Details

#eject_javascriptObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/generators/turbo_overlay/eject_generator.rb', line 49

def eject_javascript
  return unless options[:js]

  copy_gem_file "app/javascript/turbo_overlay/index.js",
    "app/javascript/turbo_overlay/index.js"
  copy_gem_file "app/javascript/turbo_overlay/setup.js",
    "app/javascript/turbo_overlay/setup.js"
  copy_gem_file "app/javascript/turbo_overlay/stack_controller.js",
    "app/javascript/turbo_overlay/stack_controller.js"
  copy_gem_file "app/javascript/turbo_overlay/overlay_controller.js",
    "app/javascript/turbo_overlay/overlay_controller.js"
  copy_gem_file "app/javascript/turbo_overlay/hint.js",
    "app/javascript/turbo_overlay/hint.js"
  copy_gem_file "app/javascript/turbo_overlay/popover_position.js",
    "app/javascript/turbo_overlay/popover_position.js"
  copy_gem_file "app/javascript/turbo_overlay/submit_close.js",
    "app/javascript/turbo_overlay/submit_close.js"

  say <<~MSG, :yellow

    JS ejected. Update your Stimulus entry to import locally:

      import { register as registerTurboOverlay } from "./turbo_overlay/index"
      registerTurboOverlay(application, { confirm: true })

    And remove the gem's importmap pin if you had one.

  MSG
end

#eject_layoutsObject



86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/generators/turbo_overlay/eject_generator.rb', line 86

def eject_layouts
  return unless options[:layouts]

  copy_gem_file "app/views/layouts/turbo_overlay/modal.html.erb",
    "app/views/layouts/turbo_overlay/modal.html.erb"
  copy_gem_file "app/views/layouts/turbo_overlay/drawer.html.erb",
    "app/views/layouts/turbo_overlay/drawer.html.erb"
  copy_gem_file "app/views/layouts/turbo_overlay/popover.html.erb",
    "app/views/layouts/turbo_overlay/popover.html.erb"
  copy_gem_file "app/views/layouts/turbo_overlay/hint.html.erb",
    "app/views/layouts/turbo_overlay/hint.html.erb"
end

#eject_stylesheetObject



79
80
81
82
83
84
# File 'lib/generators/turbo_overlay/eject_generator.rb', line 79

def eject_stylesheet
  return unless options[:css]

  copy_gem_file "app/assets/stylesheets/turbo_overlay.css",
    "app/assets/stylesheets/turbo_overlay.css"
end


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/generators/turbo_overlay/eject_generator.rb', line 31

def print_help_if_no_flags
  return if any_flag_given?

  say <<~MSG

    Nothing to eject. Pass one or more flags:

      --js        Copy Stimulus controllers to app/javascript/turbo_overlay/
      --css       Copy the stylesheet to app/assets/stylesheets/turbo_overlay.css
      --layouts   Copy modal/drawer/popover layouts to app/views/layouts/

    Ejected files become app-owned — gem upgrades to those files no
    longer apply. (Chrome partials are copied by `turbo_overlay:install`
    and already live in your app.)

  MSG
end