Class: Swage::Generators::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Swage::Generators::InstallGenerator
- Defined in:
- lib/generators/swage/install/install_generator.rb
Instance Method Summary collapse
- #add_dependencies ⇒ Object
- #check_for_engine ⇒ Object
- #check_for_js ⇒ Object
- #check_for_override ⇒ Object
- #create_application_view ⇒ Object
- #create_base_component ⇒ Object
- #create_base_form ⇒ Object
- #create_base_view ⇒ Object
- #create_flash_component ⇒ Object
- #create_initializer ⇒ Object
- #insatll_ruby_ui ⇒ Object
- #install_phlex ⇒ Object
- #install_superform ⇒ Object
- #install_tailwind ⇒ Object
-
#install_tw_animate_css ⇒ Object
because this file is usually missing while installing ruby_ui.
- #modify_application_controller ⇒ Object
- #modify_engine ⇒ Object
Instance Method Details
#add_dependencies ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/generators/swage/install/install_generator.rb', line 40 def add_dependencies deps = %W[ tailwindcss-rails phlex-rails phlexible superform ruby_ui ] missing = [] deps.each do |d| unless Gem.loaded_specs.has_key?(d) say "missing #{d} in gemfile" missing << d end end if missing.any? return if @engine && missing.length == 1 && missing[0] == "ruby_ui" if yes?("would you like to automatically install the missing dependencies?") add_source "https://rubygems.org" do deps.each do |d| gem d end end else exit 1 end end # because rails is silly and won't let you do stuff unless you have everything as a gem already return if @engine && !@override add_source "https://rubygems.org" do gem "tailwindcss-rails" gem "phlex" gem "superform" # gem "rogue" end end |
#check_for_engine ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/generators/swage/install/install_generator.rb', line 12 def check_for_engine @engine = ["engine"] # set use instance variables because they look nicer if probably_engine? && !@engine if yes?("This appears to be an engine. do you wish to insatll swage as such?") say "Installing in engine mode. Hint: use `rails g swage:install --engine`" @engine = true end end end |
#check_for_js ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/generators/swage/install/install_generator.rb', line 31 def check_for_js return if @engine # engines don't have their own js ecosystem unless using_importmap? || using_bun? || using_yarn? || using_npm? || using_pnpm? if yes?("No javascript package manager was detected. Do you wish to exit now, or continue and install missing requirements manually?") exit 0 end end end |
#check_for_override ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/generators/swage/install/install_generator.rb', line 23 def check_for_override if @engine @override = ["override"] else @override = true end end |
#create_application_view ⇒ Object
129 130 131 132 |
# File 'lib/generators/swage/install/install_generator.rb', line 129 def create_application_view remove_file File.join(destination_root, "app/views/layouts/application.html.erb") template "application_view.rb.tt", File.join(destination_root, "app/views/layouts/application.rb") if @override end |
#create_base_component ⇒ Object
109 110 111 |
# File 'lib/generators/swage/install/install_generator.rb', line 109 def create_base_component template "base_component.rb.tt", File.join(destination_root, "app/components/base.rb"), force: true if @override end |
#create_base_form ⇒ Object
121 122 123 |
# File 'lib/generators/swage/install/install_generator.rb', line 121 def create_base_form template "form.rb.tt", File.join(destination_root, "app/components/form.rb"), force: true if @override end |
#create_base_view ⇒ Object
117 118 119 |
# File 'lib/generators/swage/install/install_generator.rb', line 117 def create_base_view template "base_view.rb.tt", File.join(destination_root, "app/views/base.rb"), force: true if @override end |
#create_flash_component ⇒ Object
113 114 115 |
# File 'lib/generators/swage/install/install_generator.rb', line 113 def create_flash_component template "flash.rb.tt", File.join(destination_root, "app/components/flash.rb"), force: true if @override end |
#create_initializer ⇒ Object
104 105 106 107 |
# File 'lib/generators/swage/install/install_generator.rb', line 104 def create_initializer say "install swage" template "swage.rb.tt", File.join(destination_root, "config/initializers/swage.rb"), force: true end |
#insatll_ruby_ui ⇒ Object
92 93 94 95 96 97 98 |
# File 'lib/generators/swage/install/install_generator.rb', line 92 def insatll_ruby_ui if !@engine || (@engine && @override) say "install rubyui" generate "ruby_ui:install" generate "ruby_ui:component:all" end end |
#install_phlex ⇒ Object
80 81 82 83 84 |
# File 'lib/generators/swage/install/install_generator.rb', line 80 def install_phlex return if @engine say "install phlex" generate "phlex:install" end |
#install_superform ⇒ Object
86 87 88 89 90 |
# File 'lib/generators/swage/install/install_generator.rb', line 86 def install_superform return if @engine say "install superform" generate "superform:install" end |
#install_tailwind ⇒ Object
73 74 75 76 77 78 |
# File 'lib/generators/swage/install/install_generator.rb', line 73 def install_tailwind if !@engine || (@engine && @override) say "install tailwind" execute_command "rake", "tailwindcss:install" end end |
#install_tw_animate_css ⇒ Object
because this file is usually missing while installing ruby_ui
100 101 102 |
# File 'lib/generators/swage/install/install_generator.rb', line 100 def install_tw_animate_css # because this file is usually missing while installing ruby_ui template "tw-animate-css.js.tt", File.join(destination_root, "vendor/javascript/tw-animate-css.js") unless @engine end |
#modify_application_controller ⇒ Object
125 126 127 |
# File 'lib/generators/swage/install/install_generator.rb', line 125 def modify_application_controller template "application_controller.rb.tt", File.join(destination_root, "app/controllers/application_controller.rb") if @override end |
#modify_engine ⇒ Object
134 135 136 137 138 |
# File 'lib/generators/swage/install/install_generator.rb', line 134 def modify_engine return unless @engine @name ||= get_name template "engine.rb.tt", File.join(destination_root, "lib", get_name, "engine.rb") end |