Class: Spina::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Spina::InstallGenerator
- Defined in:
- lib/generators/spina/install_generator.rb
Instance Method Summary collapse
- #add_route ⇒ Object
- #bootstrap_spina ⇒ Object
- #build_tailwind ⇒ Object
- #copy_migrations ⇒ Object
- #copy_template_files ⇒ Object
- #create_account ⇒ Object
- #create_initializer_file ⇒ Object
- #create_mobility_initializer_file ⇒ Object
- #create_user ⇒ Object
- #feedback ⇒ Object
- #run_migrations ⇒ Object
- #set_theme ⇒ Object
Instance Method Details
#add_route ⇒ Object
18 19 20 21 22 |
# File 'lib/generators/spina/install_generator.rb', line 18 def add_route return if first_deploy? return if Rails.application.routes.routes.detect { |route| route.app.app == Spina::Engine } route "mount Spina::Engine => '/'" end |
#bootstrap_spina ⇒ Object
89 90 91 |
# File 'lib/generators/spina/install_generator.rb', line 89 def bootstrap_spina rake "spina:bootstrap" end |
#build_tailwind ⇒ Object
93 94 95 |
# File 'lib/generators/spina/install_generator.rb', line 93 def build_tailwind rake "spina:tailwind:build" end |
#copy_migrations ⇒ Object
24 25 26 27 |
# File 'lib/generators/spina/install_generator.rb', line 24 def copy_migrations return if first_deploy? rake "spina:install:migrations" end |
#copy_template_files ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/generators/spina/install_generator.rb', line 59 def copy_template_files return if ["first_deploy"] theme = ::Spina::Account.first.theme if theme.in?(["default", "demo"]) template "config/initializers/themes/#{theme}.rb" directory "app/views/#{theme}" directory "app/views/layouts/#{theme}" end Spina::THEMES.clear Dir[Rails.root.join("config", "initializers", "themes", "*.rb")].each { |file| load file } end |
#create_account ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/generators/spina/install_generator.rb', line 34 def create_account return if ::Spina::Account.exists? && (silent_install? || !no?("An account already exists. Skip? [Yn]")) name = ::Spina::Account.first&.name || "MySite" if talkative_install? name = ask("What would you like to name your website?", default: name) end ::Spina::Account.first_or_create.update(name: name) end |
#create_initializer_file ⇒ Object
8 9 10 11 |
# File 'lib/generators/spina/install_generator.rb', line 8 def create_initializer_file return if first_deploy? template "config/initializers/spina.rb" end |
#create_mobility_initializer_file ⇒ Object
13 14 15 16 |
# File 'lib/generators/spina/install_generator.rb', line 13 def create_mobility_initializer_file return if first_deploy? template "config/initializers/mobility.rb" end |
#create_user ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/generators/spina/install_generator.rb', line 72 def create_user return if ::Spina::User.exists? && (silent_install? || !no?("A user already exists. Skip? [Yn]")) email = "[email protected]" if talkative_install? email = ask("Please enter an email address for your first user:", default: email) end password = "password" if talkative_install? password = ask("Create a temporary password:", default: password) end @temporary_password = password ::Spina::User.create name: "admin", email: email, password: password, admin: true end |
#feedback ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/generators/spina/install_generator.rb', line 97 def feedback return if silent_install? puts puts " Your Spina site has been succesfully installed! " puts puts " Restart your server and visit http://localhost:3000 in your browser!" puts " The admin backend is located at http://localhost:3000/#{Spina.config.backend_path}." puts puts " Site name : #{::Spina::Account.first.name}" puts " Active theme : #{::Spina::Account.first.theme}" puts " User email : #{::Spina::User.first.email}" puts " User password : #{@temporary_password}" puts end |
#run_migrations ⇒ Object
29 30 31 32 |
# File 'lib/generators/spina/install_generator.rb', line 29 def run_migrations return if first_deploy? rake "db:migrate" end |
#set_theme ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/generators/spina/install_generator.rb', line 45 def set_theme account = ::Spina::Account.first return if account.theme.present? && (silent_install? || !no?("Theme '#{account.theme}' is set. Skip? [Yn]")) default_theme = account.theme || themes.first theme = if talkative_install? ask("What theme do you want to use?", limited_to: themes, default: default_theme) else default_theme end account.update(theme: theme) end |