Skip to content

Commit

Permalink
Single install generator
Browse files Browse the repository at this point in the history
  • Loading branch information
Bramjetten committed Apr 12, 2016
1 parent 3d7dc41 commit 9ced460
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 292 deletions.
41 changes: 0 additions & 41 deletions lib/generators/spina/deploy_generator.rb

This file was deleted.

24 changes: 17 additions & 7 deletions lib/generators/spina/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,23 @@ class InstallGenerator < Rails::Generators::Base
source_root File.expand_path("../templates", __FILE__)

def create_initializer_file
return if Rails.env.production?
template 'config/initializers/spina.rb'
end

def create_carrierwave_initializer_file
return if Rails.env.production?
template 'config/initializers/carrierwave.rb'
end

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

def copy_migrations
return if Rails.env.production?
rake 'spina:install:migrations'
end

Expand All @@ -35,19 +39,22 @@ def set_theme
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']
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

def copy_template_files
return if Rails.env.production?
theme = Account.first.theme
template "config/initializers/themes/#{theme}.rb"
directory "app/assets/stylesheets/#{theme}"
directory "app/views/#{theme}"
directory "app/views/layouts/#{theme}"
end


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:')
Expand All @@ -74,9 +81,6 @@ def seed_demo_content
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
Expand All @@ -85,5 +89,11 @@ def seed_demo_content
end
end

private

def themes
Rails.env.production? ? Spina::Theme.all.map(&:name) : ['default', 'demo']
end

end
end
24 changes: 0 additions & 24 deletions test/dummy/config/database.yml

This file was deleted.

220 changes: 0 additions & 220 deletions test/dummy/db/schema.rb

This file was deleted.

0 comments on commit 9ced460

Please sign in to comment.