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 =
ModalStack::Configuration::CSS_PROVIDERS.map(&:to_s).freeze

Instance Method Summary collapse

Instance Method Details

#configure_javascriptObject



32
33
34
35
36
37
38
39
40
# File 'lib/generators/modal_stack/install/install_generator.rb', line 32

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



26
27
28
29
30
# File 'lib/generators/modal_stack/install/install_generator.rb', line 26

def copy_initializer
  return if options[:skip_initializer]

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

#inject_into_layoutObject



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

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



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/modal_stack/install/install_generator.rb', line 52

def show_readme
  say <<~TXT, :green

    modal_stack installed.

    Mode:          #{resolved_mode}
    CSS provider:  #{options[: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