Class: ModalStack::Generators::InstallGenerator

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

Constant Summary collapse

ASSETS_MODES =
ModalStack::Configuration::ASSETS_MODES.map(&:to_s).freeze
CSS_PROVIDERS =

The CLI accepts the canonical providers plus the legacy ‘tailwind` alias (normalized to `tailwind_v3` by Configuration). New installs default to `tailwind_v4` — Tailwind v4 is the modern default and the preset’s fallbacks make it safe even without v4 installed.

(ModalStack::Configuration::CSS_PROVIDERS +
ModalStack::Configuration::CSS_PROVIDER_ALIASES.keys).map(&:to_s).freeze

Instance Method Summary collapse

Instance Method Details

#configure_javascriptObject



37
38
39
40
41
42
43
44
45
# File 'lib/generators/modal_stack/install/install_generator.rb', line 37

def configure_javascript
  return if options[:skip_js]

  case resolved_mode
  when "importmap" then install_importmap
  when "jsbundling" then install_jsbundling
  when "sprockets" then install_sprockets
  end
end

#copy_initializerObject



31
32
33
34
35
# File 'lib/generators/modal_stack/install/install_generator.rb', line 31

def copy_initializer
  return if options[:skip_initializer]

  template "initializer.rb", "config/initializers/modal_stack.rb"
end

#inject_into_layoutObject



47
48
49
50
51
52
53
54
55
# File 'lib/generators/modal_stack/install/install_generator.rb', line 47

def inject_into_layout
  return if options[:skip_layout]

  layout = "app/views/layouts/application.html.erb"
  return say_status(:skip, "#{layout} not found", :yellow) unless file_exists?(layout)

  inject_stylesheet_helper(layout)
  inject_dialog_helper(layout)
end

#show_readmeObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/generators/modal_stack/install/install_generator.rb', line 57

def show_readme
  say <<~TXT, :green

    modal_stack installed.

    Mode:          #{resolved_mode}
    CSS provider:  #{resolved_css_provider}

    Next steps:
      1. Confirm config/initializers/modal_stack.rb matches your needs.
      2. Confirm <%= modal_stack_stylesheet_link_tag %> is in your <head>
         and <%= modal_stack_dialog_tag %> is right before </body>.
      3. Add a modal_link_to in any view:

           <%= modal_link_to "Edit", edit_thing_path(@thing) %>

      4. Use the modal layout in the controller behind that link:

           class ThingsController < ApplicationController
             modal_stack_layout
             def edit; ...; end
           end

    Docs: https://github.com/Metalzoid/modal_stack
  TXT
end