From 9ced460b0877b430de4413f2d25a21e1b4eb9ba6 Mon Sep 17 00:00:00 2001 From: Bram Jetten Date: Tue, 12 Apr 2016 14:22:00 +0200 Subject: [PATCH] Single install generator --- lib/generators/spina/deploy_generator.rb | 41 ---- lib/generators/spina/install_generator.rb | 24 ++- test/dummy/config/database.yml | 24 --- test/dummy/db/schema.rb | 220 ---------------------- 4 files changed, 17 insertions(+), 292 deletions(-) delete mode 100644 lib/generators/spina/deploy_generator.rb delete mode 100644 test/dummy/config/database.yml delete mode 100644 test/dummy/db/schema.rb diff --git a/lib/generators/spina/deploy_generator.rb b/lib/generators/spina/deploy_generator.rb deleted file mode 100644 index 2e94f768c..000000000 --- a/lib/generators/spina/deploy_generator.rb +++ /dev/null @@ -1,41 +0,0 @@ -module Spina - class DeployGenerator < Rails::Generators::Base - - def run_migrations - rake 'db:migrate' - end - - 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 - - def set_theme - account = Account.first - return if account.theme.present? && !no?("Theme '#{account.theme} is set. Skip? [Yn]") - - themes = Spina::Theme.all.map(&:name) - - 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 - - - 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 - - def bootstrap_spina - rake 'spina:bootstrap' - end - - end -end diff --git a/lib/generators/spina/install_generator.rb b/lib/generators/spina/install_generator.rb index 35883cc83..9583304d1 100644 --- a/lib/generators/spina/install_generator.rb +++ b/lib/generators/spina/install_generator.rb @@ -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 @@ -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:') @@ -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 @@ -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 diff --git a/test/dummy/config/database.yml b/test/dummy/config/database.yml deleted file mode 100644 index c60d8601f..000000000 --- a/test/dummy/config/database.yml +++ /dev/null @@ -1,24 +0,0 @@ -# SQLite version 3.x -# gem install sqlite3 -# -# Ensure the SQLite 3 gem is defined in your Gemfile -# gem 'sqlite3' -development: - adapter: postgresql - encoding: unicode - database: spina_development - pool: 5 - host: localhost - -test: - adapter: postgresql - encoding: unicode - database: spina_test - pool: 5 - host: localhost - -# production: -# adapter: sqlite3 -# database: db/production.sqlite3 -# pool: 5 -# timeout: 5000 diff --git a/test/dummy/db/schema.rb b/test/dummy/db/schema.rb deleted file mode 100644 index e9bb6e444..000000000 --- a/test/dummy/db/schema.rb +++ /dev/null @@ -1,220 +0,0 @@ -# encoding: UTF-8 -# This file is auto-generated from the current state of the database. Instead -# of editing this file, please use the migrations feature of Active Record to -# incrementally modify your database, and then regenerate this schema definition. -# -# Note that this schema.rb definition is the authoritative source for your -# database schema. If you need to create the application database on another -# system, you should be using db:schema:load, not running all the migrations -# from scratch. The latter is a flawed and unsustainable approach (the more migrations -# you'll amass, the slower it'll run and the greater likelihood for issues). -# -# It's strongly recommended that you check this file into your version control system. - -ActiveRecord::Schema.define(version: 20160324153108) do - - # These are extensions that must be enabled in order to support this database - enable_extension "plpgsql" - - create_table "spina_accounts", force: :cascade do |t| - t.string "name" - t.string "address" - t.string "postal_code" - t.string "city" - t.string "phone" - t.string "email" - t.text "preferences" - t.string "logo" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "kvk_identifier" - t.string "vat_identifier" - t.boolean "robots_allowed", default: false - end - - create_table "spina_attachment_collections", force: :cascade do |t| - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - end - - create_table "spina_attachment_collections_attachments", force: :cascade do |t| - t.integer "attachment_collection_id" - t.integer "attachment_id" - end - - create_table "spina_attachments", force: :cascade do |t| - t.string "file" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - end - - create_table "spina_colors", force: :cascade do |t| - t.text "content" - t.datetime "created_at" - t.datetime "updated_at" - end - - create_table "spina_inquiries", force: :cascade do |t| - t.string "name" - t.string "email" - t.string "phone" - t.text "message" - t.boolean "archived", default: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.boolean "spam" - end - - create_table "spina_layout_parts", force: :cascade do |t| - t.string "title" - t.string "name" - t.integer "layout_partable_id" - t.string "layout_partable_type" - t.datetime "created_at" - t.datetime "updated_at" - t.integer "account_id" - end - - create_table "spina_line_translations", force: :cascade do |t| - t.integer "spina_line_id", null: false - t.string "locale", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "content" - end - - add_index "spina_line_translations", ["locale"], name: "index_spina_line_translations_on_locale", using: :btree - add_index "spina_line_translations", ["spina_line_id"], name: "index_spina_line_translations_on_spina_line_id", using: :btree - - create_table "spina_lines", force: :cascade do |t| - t.string "content" - t.datetime "created_at" - t.datetime "updated_at" - end - - create_table "spina_page_parts", force: :cascade do |t| - t.string "title" - t.string "name" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.integer "page_id" - t.integer "page_partable_id" - t.string "page_partable_type" - end - - create_table "spina_page_translations", force: :cascade do |t| - t.integer "spina_page_id", null: false - t.string "locale", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "title" - t.string "menu_title" - t.string "description" - t.string "seo_title" - t.string "materialized_path" - end - - add_index "spina_page_translations", ["locale"], name: "index_spina_page_translations_on_locale", using: :btree - add_index "spina_page_translations", ["spina_page_id"], name: "index_spina_page_translations_on_spina_page_id", using: :btree - - create_table "spina_pages", force: :cascade do |t| - t.string "title" - t.string "menu_title" - t.string "description" - t.boolean "show_in_menu", default: true - t.string "slug" - t.boolean "deletable", default: true - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "name" - t.string "seo_title" - t.boolean "skip_to_first_child", default: false - t.string "view_template" - t.string "layout_template" - t.boolean "draft", default: false - t.string "link_url" - t.string "ancestry" - t.integer "position" - t.string "materialized_path" - t.boolean "active", default: true - end - - create_table "spina_photo_collections", force: :cascade do |t| - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - end - - create_table "spina_photo_collections_photos", force: :cascade do |t| - t.integer "photo_collection_id" - t.integer "photo_id" - t.integer "position" - end - - create_table "spina_photos", force: :cascade do |t| - t.string "file" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - end - - create_table "spina_rewrite_rules", force: :cascade do |t| - t.string "old_path" - t.string "new_path" - t.datetime "created_at" - t.datetime "updated_at" - end - - create_table "spina_structure_items", force: :cascade do |t| - t.integer "structure_id" - t.integer "position" - t.datetime "created_at" - t.datetime "updated_at" - end - - add_index "spina_structure_items", ["structure_id"], name: "index_spina_structure_items_on_structure_id", using: :btree - - create_table "spina_structure_parts", force: :cascade do |t| - t.integer "structure_item_id" - t.integer "structure_partable_id" - t.string "structure_partable_type" - t.string "name" - t.string "title" - t.datetime "created_at" - t.datetime "updated_at" - end - - add_index "spina_structure_parts", ["structure_item_id"], name: "index_spina_structure_parts_on_structure_item_id", using: :btree - add_index "spina_structure_parts", ["structure_partable_id"], name: "index_spina_structure_parts_on_structure_partable_id", using: :btree - - create_table "spina_structures", force: :cascade do |t| - t.datetime "created_at" - t.datetime "updated_at" - end - - create_table "spina_text_translations", force: :cascade do |t| - t.integer "spina_text_id", null: false - t.string "locale", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.text "content" - end - - add_index "spina_text_translations", ["locale"], name: "index_spina_text_translations_on_locale", using: :btree - add_index "spina_text_translations", ["spina_text_id"], name: "index_spina_text_translations_on_spina_text_id", using: :btree - - create_table "spina_texts", force: :cascade do |t| - t.text "content" - t.datetime "created_at" - t.datetime "updated_at" - end - - create_table "spina_users", force: :cascade do |t| - t.string "name" - t.string "email" - t.string "password_digest" - t.boolean "admin", default: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.datetime "last_logged_in" - end - -end