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
- #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
15 16 17 18 19 |
# File 'lib/generators/spina/install_generator.rb', line 15 def add_route return if Rails.env.production? return if Rails.application.routes.routes.detect { |route| route.app.app == Spina::Engine } route "mount Spina::Engine => '/'" end |
#bootstrap_spina ⇒ Object
71 72 73 |
# File 'lib/generators/spina/install_generator.rb', line 71 def bootstrap_spina rake 'spina:bootstrap' end |
#copy_migrations ⇒ Object
21 22 23 24 |
# File 'lib/generators/spina/install_generator.rb', line 21 def copy_migrations return if Rails.env.production? rake 'spina:install:migrations' end |
#copy_template_files ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/generators/spina/install_generator.rb', line 49 def copy_template_files theme = ::Spina::Account.first.theme if theme.in? ['default', 'demo'] template "config/initializers/themes/#{theme}.rb" directory "app/assets/stylesheets/#{theme}" 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
30 31 32 33 34 35 |
# File 'lib/generators/spina/install_generator.rb', line 30 def create_account return if ::Spina::Account.exists? && !no?('An account already exists. Skip? [Yn]') name = ::Spina::Account.first.try(:name) || 'MySite' name = ask("What would you like to name your website? [#{name}]").presence || name account = ::Spina::Account.first_or_create.update_attribute(:name, name) end |
#create_initializer_file ⇒ Object
5 6 7 8 |
# File 'lib/generators/spina/install_generator.rb', line 5 def create_initializer_file return if Rails.env.production? template 'config/initializers/spina.rb' end |
#create_mobility_initializer_file ⇒ Object
10 11 12 13 |
# File 'lib/generators/spina/install_generator.rb', line 10 def create_mobility_initializer_file return if Rails.env.production? template 'config/initializers/mobility.rb' end |
#create_user ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/generators/spina/install_generator.rb', line 61 def create_user return if ::Spina::User.exists? && !no?('A user already exists. Skip? [Yn]') email = '[email protected]' email = ask("Please enter an email address for your first user: [#{email}]").presence || email password = 'password' password = ask("Create a temporary password: [#{password}]").presence || password @temporary_password = password ::Spina::User.create name: 'admin', email: email, password: password, admin: true end |
#feedback ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/generators/spina/install_generator.rb', line 75 def feedback 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
26 27 28 |
# File 'lib/generators/spina/install_generator.rb', line 26 def run_migrations rake 'db:migrate' end |
#set_theme ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/generators/spina/install_generator.rb', line 37 def set_theme account = ::Spina::Account.first return if account.theme.present? && !no?("Theme '#{account.theme} is set. Skip? [Yn]") theme = begin theme = account.theme || themes.first theme = ask("What theme do you want to use? (#{themes.join('/')}) [#{theme}]").presence || theme end until theme.in? themes account.update_attribute(:theme, theme) end |