Class: Maglev::InstallGenerator

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

Instance Method Summary collapse

Instance Method Details

#compile_editor_assetsObject



9
10
11
12
# File 'lib/generators/maglev/install_generator.rb', line 9

def compile_editor_assets
  rake 'maglev:vite:install_dependencies'
  rake 'maglev:vite:build_all'
end

#create_initializerObject



19
20
21
22
# File 'lib/generators/maglev/install_generator.rb', line 19

def create_initializer
  directory 'config'
  directory 'public'
end

#generate_blank_themeObject



24
25
26
# File 'lib/generators/maglev/install_generator.rb', line 24

def generate_blank_theme
  generate 'maglev:theme'
end

#instructionsObject



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/generators/maglev/install_generator.rb', line 38

def instructions
  $stdout.puts <<~INFO
    Done! 🎉

    You can now tweak config/initializers/maglev.rb
    You can also modify your theme (in app/theme and app/views/theme)
    and generate new sections with rails g maglev:section.

    👉 The next step is to create a site using `rails maglev:create_site`.

    🚨 Don't forget to do it in production as well!
  INFO
end

#migrationsObject



14
15
16
17
# File 'lib/generators/maglev/install_generator.rb', line 14

def migrations
  rake 'maglev:install:migrations'
  rake 'db:migrate'
end

#mount_engineObject



28
29
30
31
32
33
34
35
36
# File 'lib/generators/maglev/install_generator.rb', line 28

def mount_engine
  inject_into_file 'config/routes.rb', before: /^end/ do
    <<-CODE
  mount Maglev::Engine => '/maglev'
  get '/sitemap', to: 'maglev/sitemap#index', defaults: { format: 'xml' }
  get '(*path)', to: 'maglev/page_preview#index', defaults: { path: 'index' }, constraints: Maglev::PreviewConstraint.new
    CODE
  end
end