Class: ActionText::Generators::InstallGenerator
  
  
  
  
    
      Instance Method Summary
      collapse
    
    
  
  
  
  
  
  
  
  
  
  
  base_root, class_option, default_source_root, desc, exit_on_failure?, hide!, hook_for, inherited, namespace, remove_hook_for, source_root
  
  
  
  
  
  
  
  
  
  #add_source, #environment, #gem, #gem_group, #generate, #git, #github, #initialize, #initializer, #lib, #rails_command, #rake, #rakefile, #readme, #route, #vendor
  
  
  
    Instance Method Details
    
      
  
  
    #append_javascript_dependencies  ⇒ Object 
  
  
  
  
    
      
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36 
     | 
    
      # File 'actiontext/lib/generators/action_text/install/install_generator.rb', line 22
def append_javascript_dependencies
  destination = Pathname(destination_root)
  if (application_javascript_path = destination.join("app/javascript/application.js")).exist?
    insert_into_file application_javascript_path.to_s, %(\nimport "trix"\nimport "@rails/actiontext"\n)
  else
    say <<~INSTRUCTIONS, :green
      You must import the @rails/actiontext and trix JavaScript modules in your application entrypoint.
    INSTRUCTIONS
  end
  if (importmap_path = destination.join("config/importmap.rb")).exist?
    append_to_file importmap_path.to_s, %(pin "trix"\npin "@rails/actiontext", to: "actiontext.esm.js"\n)
  end
end
     | 
  
 
    
      
  
  
    #create_actiontext_files  ⇒ Object 
  
  
  
  
    
      
38
39
40
41
42
43
44
45
46
47
48 
     | 
    
      # File 'actiontext/lib/generators/action_text/install/install_generator.rb', line 38
def create_actiontext_files
  template "actiontext.css", "app/assets/stylesheets/actiontext.css"
  gem_root = "#{__dir__}/../../../.."
  copy_file "#{gem_root}/app/views/active_storage/blobs/_blob.html.erb",
    "app/views/active_storage/blobs/_blob.html.erb"
  copy_file "#{gem_root}/app/views/layouts/action_text/contents/_content.html.erb",
    "app/views/layouts/action_text/contents/_content.html.erb"
end
     | 
  
 
    
      
  
  
    #create_migrations  ⇒ Object 
  
  
  
  
    
      
62
63
64 
     | 
    
      # File 'actiontext/lib/generators/action_text/install/install_generator.rb', line 62
def create_migrations
  rails_command "railties:install:migrations FROM=active_storage,action_text", inline: true
end 
     | 
  
 
    
      
  
  
    #enable_image_processing_gem  ⇒ Object 
  
  
  
  
    
      
50
51
52
53
54
55
56
57
58
59
60 
     | 
    
      # File 'actiontext/lib/generators/action_text/install/install_generator.rb', line 50
def enable_image_processing_gem
  if (gemfile_path = Pathname(destination_root).join("Gemfile")).exist?
    say "Ensure image_processing gem has been enabled so image uploads will work (remember to bundle!)"
    image_processing_regex = /gem ["']image_processing["']/
    if File.readlines(gemfile_path).grep(image_processing_regex).any?
       gemfile_path, image_processing_regex
    else
      run "bundle add --skip-install image_processing"
    end
  end
end
     | 
  
 
    
      
  
  
    #install_javascript_dependencies  ⇒ Object 
  
  
  
  
    
      
13
14
15
16
17
18
19
20 
     | 
    
      # File 'actiontext/lib/generators/action_text/install/install_generator.rb', line 13
def install_javascript_dependencies
  say "Installing JavaScript dependencies", :green
  if using_bun?
    run "bun add @rails/actiontext trix"
  elsif using_node?
    run "yarn add @rails/actiontext trix"
  end
end
     | 
  
 
    
      
  
  
    #using_bun?  ⇒ Boolean 
  
  
  
  
    
      
70
71
72
73
74 
     | 
    
      # File 'actiontext/lib/generators/action_text/install/install_generator.rb', line 70
def using_bun?
      @using_bun ||= using_js_runtime? && Pathname(destination_root).join("bun.config.js").exist?
end
     | 
  
 
    
      
  
  
    #using_js_runtime?  ⇒ Boolean 
  
  
  
  
    
      
66
67
68 
     | 
    
      # File 'actiontext/lib/generators/action_text/install/install_generator.rb', line 66
def using_js_runtime?
  @using_js_runtime ||= Pathname(destination_root).join("package.json").exist?
end
     | 
  
 
    
      
  
  
    #using_node?  ⇒ Boolean 
  
  
  
  
    
      
76
77
78
79 
     | 
    
      # File 'actiontext/lib/generators/action_text/install/install_generator.rb', line 76
def using_node?
    @using_node ||= using_js_runtime? && !Pathname(destination_root).join("bun.config.js").exist?
end
     |