Class: ActionText::Generators::InstallGenerator

Inherits:
Rails::Generators::Base show all
Defined in:
actiontext/lib/generators/action_text/install/install_generator.rb

Instance Method Summary collapse

Methods inherited from Rails::Generators::Base

base_root, class_option, default_source_root, desc, exit_on_failure?, hide!, hook_for, inherited, namespace, remove_hook_for, source_root

Methods included from Rails::Generators::Actions

#add_source, #environment, #gem, #gem_group, #generate, #git, #github, #initialize, #initializer, #lib, #rails_command, #rake, #rakefile, #readme, #route, #vendor

Instance Method Details

#append_dependencies_to_package_fileObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'actiontext/lib/generators/action_text/install/install_generator.rb', line 19

def append_dependencies_to_package_file
  if (app_javascript_pack_path = Pathname.new("app/javascript/packs/application.js")).exist?
    js_dependencies.each_key do |dependency|
      line = %[require("#{dependency}")]

      unless app_javascript_pack_path.read.include? line
        say "Adding #{dependency} to #{app_javascript_pack_path}", :green
        append_to_file app_javascript_pack_path, "\n#{line}"
      end
    end
  else
    say <<~WARNING, :red
      WARNING: Action Text can't locate your JavaScript bundle to add its package dependencies.

      Add these lines to any bundles:

      require("trix")
      require("@rails/actiontext")

      Alternatively, install and setup the webpacker gem then rerun `bin/rails action_text:install`
      to have these dependencies added automatically.
    WARNING
  end
end

#create_actiontext_filesObject



44
45
46
47
48
49
# File 'actiontext/lib/generators/action_text/install/install_generator.rb', line 44

def create_actiontext_files
  template "actiontext.scss", "app/assets/stylesheets/actiontext.scss"

  copy_file "#{GEM_ROOT}/app/views/active_storage/blobs/_blob.html.erb",
    "app/views/active_storage/blobs/_blob.html.erb"
end

#create_migrationsObject



51
52
53
# File 'actiontext/lib/generators/action_text/install/install_generator.rb', line 51

def create_migrations
  rails_command "railties:install:migrations FROM=active_storage,action_text"
end

#install_javascript_dependenciesObject



11
12
13
14
15
16
17
# File 'actiontext/lib/generators/action_text/install/install_generator.rb', line 11

def install_javascript_dependencies
  rails_command "app:update:bin"

  say "Installing JavaScript dependencies", :green
  run "yarn add #{js_dependencies.map { |name, version| "#{name}@#{version}" }.join(" ")}",
    abort_on_failure: true, capture: true
end