Class: Croppable::Generators::InstallGenerator

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

Instance Method Summary collapse

Instance Method Details

#append_css_dependenciesObject



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

def append_css_dependencies
  destination = Pathname(destination_root)

  if (stylesheet = destination.join("app/assets/stylesheets/application.css")).exist?
    insert_into_file stylesheet, %( *= require croppable\n), before: " *= require_self"
  else
    say "      To use the Croppable gem, you must import 'croppable' in your base stylesheet.\n    INSTRUCTIONS\n  end\nend\n", :green

#append_javascript_dependenciesObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/generators/croppable/install/install_generator.rb', line 25

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 "croppable"\n)
  else
    say "      You must import the croppable JavaScript module in your application entrypoint.\n    INSTRUCTIONS\n  end\n\n  if (importmap_path = destination.join(\"config/importmap.rb\")).exist?\n    append_to_file importmap_path.to_s, %(pin \"croppable\"\\n)\n  end\nend\n", :green

#create_migrationsObject



57
58
59
# File 'lib/generators/croppable/install/install_generator.rb', line 57

def create_migrations
  rails_command "croppable:install:migrations", inline: true
end

#install_active_storageObject



53
54
55
# File 'lib/generators/croppable/install/install_generator.rb', line 53

def install_active_storage
  rails_command "active_storage:install", inline: true
end

#install_javascript_dependenciesObject



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/generators/croppable/install/install_generator.rb', line 11

def install_javascript_dependencies
  destination = Pathname(destination_root)

  if Pathname(destination_root).join("package.json").exist?
    say "Installing JavaScript dependencies", :green
    run "yarn add cropperjs@next"
  end

  if (importmap_path = destination.join("config/importmap.rb")).exist?
    say "Installing JavaScript dependencies", :green
    run "bin/importmap pin cropperjs@next"
  end
end