Class: TamSelect::Generators::InstallGenerator

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

Instance Method Summary collapse

Instance Method Details

#configure_importmapObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/generators/tam_select/install_generator.rb', line 15

def configure_importmap
  importmap = "config/importmap.rb"
  unless File.exist?(destination_path(importmap))
    configure_esbuild
    return
  end

  pin = 'pin "tam_select", to: "tam_select/tam_select.js"'
  contents = File.read(destination_path(importmap))
  existing_pin = /^\s*pin\s+["']tam_select["'].*$/

  if contents.match?(existing_pin)
    gsub_file importmap, existing_pin, pin unless contents.match?(/^#{Regexp.escape(pin)}$/)
  else
    append_to_file importmap, "\n#{pin}\n"
  end
end

#copy_controller_concernObject



41
42
43
44
# File 'lib/generators/tam_select/install_generator.rb', line 41

def copy_controller_concern
  copy_file "lib/generators/tam_select/templates/tam_select_paginatable.rb", "app/controllers/concerns/tam_select_paginatable.rb"
  copy_file "lib/generators/tam_select/templates/tam_select_remote.rb", "app/controllers/concerns/tam_select_remote.rb"
end

#copy_helperObject



50
51
52
# File 'lib/generators/tam_select/install_generator.rb', line 50

def copy_helper
  copy_file "lib/generators/tam_select/templates/tam_select_helper.rb", "app/helpers/tam_select_helper.rb"
end

#copy_javascriptObject



10
11
12
13
# File 'lib/generators/tam_select/install_generator.rb', line 10

def copy_javascript
  copy_file "src/tam-select.js", "app/javascript/tam_select/tam_select.js"
  copy_file "lib/generators/tam_select/templates/tam_select_controller.js", "app/javascript/controllers/tam_select_controller.js"
end

#copy_remote_controllerObject



46
47
48
# File 'lib/generators/tam_select/install_generator.rb', line 46

def copy_remote_controller
  copy_file "lib/generators/tam_select/templates/tam_select_remote_controller.rb", "app/controllers/tam_select_remote_controller.rb"
end

#copy_simple_form_inputObject



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

def copy_simple_form_input
  if simple_form_available?
    copy_file "lib/generators/tam_select/templates/tam_select_input.rb", "app/inputs/tam_select_input.rb"
  else
    say "Simple Form is not installed; skipped app/inputs/tam_select_input.rb. Standard Rails form helpers remain available.", :yellow
  end
end

#show_tailwind_instructionObject



54
55
56
57
58
59
# File 'lib/generators/tam_select/install_generator.rb', line 54

def show_tailwind_instruction
  say "\ntam_select installed.", :green
  say "Tailwind CSS 4 scans app/javascript automatically in most Rails setups."
  say "If your setup uses explicit sources, add:"
  say '@source "../../javascript/tam_select/**/*.js";'
end