Class: Spina::InstallGenerator

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

Instance Method Summary collapse

Instance Method Details

#add_routeObject



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_spinaObject



89
90
91
# File 'lib/generators/spina/install_generator.rb', line 89

def bootstrap_spina
  rake "spina:bootstrap"
end

#build_tailwindObject



93
94
95
# File 'lib/generators/spina/install_generator.rb', line 93

def build_tailwind
  rake "spina:tailwind:build"
end

#copy_migrationsObject



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_filesObject



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 options["first_deploy"]

  theme = ::Spina::.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_accountObject



34
35
36
37
38
39
40
41
42
43
# File 'lib/generators/spina/install_generator.rb', line 34

def 
  return if ::Spina::.exists? && (silent_install? || !no?("An account already exists. Skip? [Yn]"))

  name = ::Spina::.first&.name || "MySite"
  if talkative_install?
    name = ask("What would you like to name your website?", default: name)
  end

  ::Spina::.first_or_create.update(name: name)
end

#create_initializer_fileObject



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_fileObject



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_userObject



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

#feedbackObject



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_migrationsObject



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_themeObject



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
   = ::Spina::.first
  return if .theme.present? && (silent_install? || !no?("Theme '#{account.theme}' is set. Skip? [Yn]"))

  default_theme = .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

  .update(theme: theme)
end