lib/generators/katapult/basics/basics_generator.rb in katapult-0.1.2 vs lib/generators/katapult/basics/basics_generator.rb in katapult-0.2.0

- old
+ new

@@ -2,18 +2,18 @@ module Katapult module Generators class BasicsGenerator < Rails::Generators::Base - SKIP_GEMS = %w(sass-rails coffee-rails turbolinks sdoc uglifier mysql2) + SKIP_GEMS = %w(sass-rails coffee-rails turbolinks sdoc uglifier) desc 'Generate basics like test directories and gems' source_root File.expand_path('../templates', __FILE__) - class_option :db_user, type: :string, + class_option :db_user, type: :string, default: 'root', description: 'The user to set in config/database.yml' - class_option :db_password, type: :string, + class_option :db_password, type: :string, default: '', description: 'The password to set in config/database.yml' def add_gitignore template '.gitignore', force: true @@ -22,12 +22,12 @@ def write_ruby_version template '.ruby-version' end def write_database_ymls - @db_user = options.db_user || 'root' - @db_password = options.db_password || '' + @db_user = options.db_user + @db_password = options.db_password template 'config/database.yml', force: true template 'config/database.sample.yml' end @@ -43,49 +43,83 @@ end def bundle_install run 'bundle install' - # There is a bug in the current version of Compass, so we use an older - # one in our Gemfile template. Since its dependencies "sprockets" and - # "sass-rails" are already in the Gemfile.lock (from installing Rails), - # we need to explicitly update them. - run 'bundle update sprockets sass-rails' + # This is relevant for the server, so it may happen after bundling here. + # By having Nokogiri use system libraries, it will get automatic updates + # of the frequently broken libxml (i.e. when the system libxml updates). + run 'bundle config --local build.nokogiri --use-system-libraries' end def remove_turbolinks_js gsub_file 'app/assets/javascripts/application.js', "//= require turbolinks\n", '' + gsub_file 'app/views/layouts/application.html.erb', ", 'data-turbolinks-track' => true", '' end def setup_spring # run 'spring binstub --all' # # remove_file 'bin/bundle' # Won't play together with parallel_tests # template 'config/spring.rb' # template 'bin/rake' run 'spring stop' # Reload (just in case) end + def setup_guard + template 'Guardfile' + environment 'config.middleware.use Rack::LiveReload', env: :development + end + + def setup_staging + FileUtils.copy 'config/environments/production.rb', 'config/environments/staging.rb' + secret = `rake secret`.chomp + # Cheating in the "staging" secret between "test" and "production" + insert_into_file 'config/secrets.yml', <<~SECRET, after: "test:\n" + secret_key_base: #{ secret } + + staging: + SECRET + end + def create_databases - run 'rake db:create:all parallel:create' + run 'rake db:drop:all db:create:all parallel:create' end + def configure_action_mailer + app_con = 'app/controllers/application_controller.rb' + inject_into_file app_con, <<-CONFIG, before: /end\n\z/ + before_filter :make_action_mailer_use_request_host_and_protocol + + private + + def make_action_mailer_use_request_host_and_protocol + ActionMailer::Base.default_url_options[:protocol] = request.protocol + ActionMailer::Base.default_url_options[:host] = request.host_with_port + end + CONFIG + end + def set_timezone gsub_file 'config/application.rb', /# config\.time_zone =.*$/, "config.time_zone = 'Berlin'" end - def make_assets_debuggable - gsub_file 'config/application.rb', + def disable_asset_debugging # Faster + gsub_file 'config/environments/development.rb', /config\.assets\.debug =.*$/, 'config.assets.debug = false' end def install_initializers directory 'config/initializers' end + def install_ext + directory 'lib/ext' + end + def add_modularity_load_paths # This results in correct indentation :) application <<-'LOAD_PATHS' config.autoload_paths << "#{Rails.root}/app/controllers/shared" config.autoload_paths << "#{Rails.root}/app/models/shared" @@ -107,20 +141,32 @@ generate 'rspec:install' gsub_file '.rspec', "--warnings\n", '' # Don't show Ruby warnings uncomment_lines 'spec/rails_helper.rb', /Dir.Rails.root.join.+spec.support/ template 'spec/support/shoulda_matchers.rb' + template 'spec/support/factory_girl.rb' + directory 'spec/factories' end + def install_capistrano + # Create Capfile *before* installing Capistrano to prevent annoying + # Harrow.io ad + template 'Capfile', force: true + run 'cap install' + + template 'config/deploy.rb', force: true + template 'config/deploy/staging.rb', force: true + template 'config/deploy/production.rb', force: true + + directory 'lib/capistrano/tasks' + template 'lib/tasks/pending_migrations.rake' + end + def install_styles remove_file 'app/assets/stylesheets/application.css' directory 'app/assets/stylesheets', force: true end - # def install_capistrano - # capify! - # template 'config/deploy.rb' - # end private def app_name File.basename(Dir.pwd)