Class: AdvancedSelect::Generators::InstallGenerator

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

Constant Summary collapse

VALID_SETUPS =
%w[importmap jsbundling].freeze

Instance Method Summary collapse

Instance Method Details

#import_stylesheetObject



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

def import_stylesheet
  case setup
  when "importmap"
    import_application_stylesheet
  when "jsbundling"
    append_postcss_import
  end
end

#install_stimulus_controllerObject



18
19
20
21
22
23
24
25
# File 'lib/generators/advanced_select/install/install_generator.rb', line 18

def install_stimulus_controller
  case setup
  when "importmap"
    pin_importmap_controller
  when "jsbundling"
    copy_file "advanced_select_controller.js", "app/javascript/controllers/advanced_select_controller.js"
  end
end

#install_stylesheetObject



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

def install_stylesheet
  if setup == "jsbundling"
    copy_file "advanced_select.css", "app/assets/stylesheets/advanced_select.css"
  end
end

#register_stimulus_controllerObject



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

def register_stimulus_controller
  case setup
  when "importmap"
    register_importmap_controller
  when "jsbundling"
    register_manifest_controller
  end
end

#show_next_stepsObject



51
52
53
54
55
# File 'lib/generators/advanced_select/install/install_generator.rb', line 51

def show_next_steps
  say "AdvancedSelect installed.", :green
  say "Setup: #{setup}"
  say "Host apps still own routes, controllers, queries, and Turbo Stream option endpoints."
end

#validate_optionsObject

Raises:

  • (Thor::Error)


12
13
14
15
16
# File 'lib/generators/advanced_select/install/install_generator.rb', line 12

def validate_options
  return if VALID_SETUPS.include?(setup)

  raise Thor::Error, "Invalid --setup=#{setup.inspect}. Expected one of: #{VALID_SETUPS.join(', ')}."
end