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
- #create_account ⇒ Object
- #create_initializer_file ⇒ Object
- #create_user ⇒ Object
- #run_migrations ⇒ Object
- #seed_demo_content ⇒ Object
- #set_theme ⇒ Object
Instance Method Details
#add_route ⇒ Object
10 11 12 13 |
# File 'lib/generators/spina/install_generator.rb', line 10 def add_route return if Rails.application.routes.routes.detect { |route| route.app.app == Spina::Engine } route "mount Spina::Engine => '/'" end |
#bootstrap_spina ⇒ Object
55 56 57 |
# File 'lib/generators/spina/install_generator.rb', line 55 def bootstrap_spina rake 'spina:bootstrap' end |
#copy_migrations ⇒ Object
15 16 17 |
# File 'lib/generators/spina/install_generator.rb', line 15 def copy_migrations rake 'spina:install:migrations' end |
#create_account ⇒ Object
23 24 25 26 27 |
# File 'lib/generators/spina/install_generator.rb', line 23 def create_account return if Account.exists? && !no?('An account already exists. Skip? [Yn]') name = ask('What would you like to name your website?') account = Account.first_or_create.update_attribute(:name, name) end |
#create_initializer_file ⇒ Object
6 7 8 |
# File 'lib/generators/spina/install_generator.rb', line 6 def create_initializer_file template 'config/initializers/spina.rb' end |
#create_user ⇒ Object
48 49 50 51 52 53 |
# File 'lib/generators/spina/install_generator.rb', line 48 def create_user return if User.exists? && !no?('A user already exists. Skip? [Yn]') email = ask('Please enter an email address for your first user:') password = ask('Create a temporary password:', echo: false) User.create name: 'admin', email: email, password: password, admin: true end |
#run_migrations ⇒ Object
19 20 21 |
# File 'lib/generators/spina/install_generator.rb', line 19 def run_migrations rake 'db:migrate' end |
#seed_demo_content ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/generators/spina/install_generator.rb', line 59 def seed_demo_content theme_name = Account.first.theme if theme_name == 'demo' && !no?('Seed example content? [Yn]') current_theme = ::Spina.themes.find { |theme| theme.name == theme_name } if (page = Spina::Page.find_by(name: 'demo')) page.page_parts.clear parts = current_theme.config.page_parts.map { |page_part| page.page_part(page_part) } parts.each do |part| case part.partable_type when 'Spina::Line' then part.partable.content = 'This is a single line' when 'Spina::Text' then part.partable.content = '<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>' when 'Spina::Photo' then part.partable.remote_file_url = 'https://unsplash.it/300/200?random' when 'Spina::PhotoCollection' 5.times { part.partable.photos.build(remote_file_url: 'https://unsplash.it/300/200?random') } # when 'Spina::Structure' # part.partable.structure_items.build({ name: 'title', title: 'Title', structure_partable_type: 'Spina::Line' }) # part.partable.structure_items.build({ name: 'description', title: 'Description', structure_partable_type: 'Spina::Text' }) when 'Spina::Color' then part.partable.content = '#6865b4' end end page.save end end end |
#set_theme ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/generators/spina/install_generator.rb', line 29 def set_theme account = Account.first return if account.theme.present? && !no?("Theme '#{account.theme} is set. Skip? [Yn]") theme = begin theme = account.theme || 'default' theme = ask("What theme do you want to use? (default/demo) [#{theme}]").presence || theme end until theme.in? ['default', 'demo'] account.update_attribute(:theme, theme) template "config/initializers/themes/#{theme}.rb" directory "app/assets/stylesheets/#{theme}" directory "app/views/#{theme}" directory "app/views/layouts/#{theme}" directory "app/views/layouts/#{theme}" end |