Class: RicherText::Generators::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- RicherText::Generators::InstallGenerator
- Defined in:
- lib/generators/richer_text/install/install_generator.rb
Instance Method Summary collapse
- #copy_files ⇒ Object
- #create_migrations ⇒ Object
- #install_javascript_dependencies ⇒ Object
- #install_stylesheet_dependencies ⇒ Object
Instance Method Details
#copy_files ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/generators/richer_text/install/install_generator.rb', line 12 def copy_files copy_file( "app/views/richer_text/contents/_content.html.erb", "app/views/richer_text/contents/_content.html.erb" ) copy_file( "app/assets/stylesheets/richer_text/richer-text.css", "app/assets/stylesheets/richer-text.css" ) end |
#create_migrations ⇒ Object
8 9 10 |
# File 'lib/generators/richer_text/install/install_generator.rb', line 8 def create_migrations rails_command "railties:install:migrations FROM=active_storage,richer_text", inline: true end |
#install_javascript_dependencies ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/generators/richer_text/install/install_generator.rb', line 24 def install_javascript_dependencies destination = Pathname(destination_root) if destination.join("package.json").exist? say "Adding dependencies to package.json", :green run "npm install highlight.js @afomera/richer-text" if destination.join("package-lock.json").exist? run "bun add highlight.js @afomera/richer-text" if destination.join("bun.lockb").exist? run "yarn add highlight.js @afomera/richer-text" if destination.join("yarn.lock").exist? run "pnpm add highlight.js @afomera/richer-text" if destination.join("pnpm-lock.yaml").exist? end say "Adding import to application.js", :green append_to_file "app/javascript/application.js", %(import "@afomera/richer-text"\n) end |
#install_stylesheet_dependencies ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/generators/richer_text/install/install_generator.rb', line 40 def install_stylesheet_dependencies destination = Pathname(destination_root) if destination.join("app/assets/stylesheets/application.tailwind.css").exist? say "Adding import to application.tailwind.css", :green prepend_to_file "app/assets/stylesheets/application.tailwind.css", %(@import "@afomera/richer-text/dist/css/richer-text.css";\n@import "highlight.js/styles/github-dark.css";\n@import "richer-text.css";\n) elsif (stylesheets = Dir.glob "#{destination_root}/app/assets/stylesheets/application.*.{scss}").length > 0 say "Adding import to #{stylesheets.first}", :green prepend_to_file stylesheets.first, %(@import "@afomera/richer-text/dist/css/richer-text";\n@import "highlight.js/styles/github-dark";\n@import "richer-text";\n) end end |