module RailsloveSuspenders class AppBuilder < Rails::AppBuilder include RailsloveSuspenders::Actions def readme template 'README.md.erb', 'README.md' end def remove_public_index remove_file 'public/index.html' end def remove_rails_logo_image remove_file 'app/assets/images/rails.png' end def raise_on_delivery_errors replace_in_file 'config/environments/development.rb', 'raise_delivery_errors = false', 'raise_delivery_errors = true' end def raise_on_unpermitted_parameters configure_environment 'development', 'config.action_controller.action_on_unpermitted_parameters = :raise' end def provide_setup_script copy_file 'bin_setup', 'bin/setup' run 'chmod a+x bin/setup' end def enable_factory_girl_syntax copy_file 'factory_girl_syntax_rspec.rb', 'spec/support/factory_girl.rb' end def test_factories_first copy_file 'factories_spec.rb', 'spec/models/factories_spec.rb' # append_file 'Rakefile', factories_spec_rake_task end def configure_smtp copy_file 'smtp.rb', 'config/initializers/smtp.rb' prepend_file 'config/environments/production.rb', "require Rails.root.join('config/initializers/smtp')\n" config = <<-RUBY config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = SMTP_SETTINGS RUBY inject_into_file 'config/environments/production.rb', config, :after => 'config.action_mailer.raise_delivery_errors = false' end def setup_staging_environment run 'cp config/environments/production.rb config/environments/staging.rb' # prepend_file 'config/environments/staging.rb', # "Mail.register_interceptor RecipientInterceptor.new(ENV['EMAIL_RECIPIENTS'])\n" end def create_partials_directory empty_directory 'app/assets/stylesheets/base' empty_directory 'app/assets/stylesheets/modules' empty_directory 'app/assets/stylesheets/layout' empty_directory 'app/assets/stylesheets/controllers' end def add_default_stylesheets copy_file 'stylesheets/application.css.sass', 'app/assets/stylesheets/application.css.sass' copy_file 'stylesheets/_shame.css.sass', 'app/assets/stylesheets/_shame.css.sass' copy_file 'stylesheets/base/_colors.css.sass', 'app/assets/stylesheets/base/_colors.css.sass' copy_file 'stylesheets/base/_dimension.css.sass', 'app/assets/stylesheets/base/_dimensions.css.sass' copy_file 'stylesheets/base/_element_defaults.css.sass', 'app/assets/stylesheets/base/_element_defaults.css.sass' copy_file 'stylesheets/base/_icon_font.css.sass', 'app/assets/stylesheets/base/_icon_font.css.sass' copy_file 'stylesheets/base/_sprites.css.sass', 'app/assets/stylesheets/base/_sprites.css.sass' copy_file 'stylesheets/base/_typography.css.sass', 'app/assets/stylesheets/base/_typography.css.sass' copy_file 'stylesheets/base/_global_mixins.css.sass', 'app/assets/stylesheets/base/_global_mixins.css.sass' end def create_shared_flashes copy_file '_flashes.html.haml', 'app/views/layouts/_flashes.html.haml' end def create_shared_javascripts copy_file '_javascript.html.haml', 'app/views/layouts/_javascript.html.haml' end def create_application_layout remove_file 'app/views/layouts/application.html.erb' template 'suspenders_layout.html.haml', 'app/views/layouts/application.html.haml', :force => true end def create_common_javascripts directory 'javascripts', 'app/assets/javascripts' end def use_postgres_config_template template 'postgresql_database.yml.erb', 'config/database.yml', :force => true end def create_database bundle_command 'exec rake db:create' end def replace_gemfile remove_file 'Gemfile' copy_file 'Gemfile_clean', 'Gemfile' end def set_ruby_to_version_being_used inject_into_file 'Gemfile', "\n\nruby '#{RUBY_VERSION}'", after: /source 'https:\/\/rubygems.org'/ end def enable_database_cleaner replace_in_file 'spec/spec_helper.rb', 'config.use_transactional_fixtures = true', 'config.use_transactional_fixtures = false' copy_file 'database_cleaner_rspec.rb', 'spec/support/database_cleaner.rb' end def enable_strong_parameter_matcher copy_file 'strong_parameter_matcher.rb', 'spec/support/matchers/strong_parameter_matcher.rb' end def configure_rspec remove_file '.rspec' copy_file 'rspec', '.rspec' rspec_expect_syntax = <<-RUBY config.expect_with :rspec do |c| c.syntax = :expect end RUBY config = <<-RUBY config.generators do |generate| generate.test_framework :rspec generate.helper false generate.stylesheets false generate.javascript_engine false generate.view_specs false end RUBY inject_into_file 'spec/spec_helper.rb', rspec_expect_syntax, :after => 'RSpec.configure do |config|' inject_into_class 'config/application.rb', 'Application', config end def configure_background_jobs_for_rspec copy_file 'background_jobs_rspec.rb', 'spec/support/background_jobs.rb' run 'rails g delayed_job:active_record' end def configure_time_zone config = <<-RUBY config.active_record.default_timezone = :utc RUBY inject_into_class 'config/application.rb', 'Application', config end def configure_time_formats remove_file 'config/locales/en.yml' copy_file 'config_locales_en.yml', 'config/locales/en.yml' end def configure_rack_timeout copy_file 'rack_timeout.rb', 'config/initializers/rack_timeout.rb' end def configure_action_mailer action_mailer_host 'development', "#{app_name}.local" action_mailer_host 'test', 'www.example.com' action_mailer_host 'staging', "staging.#{app_name}.com" action_mailer_host 'production', "#{app_name}.com" end def generate_rspec generate 'rspec:install' end def configure_capybara_webkit append_file 'spec/spec_helper.rb' do "\nCapybara.javascript_driver = :webkit\n" end end def generate_clearance generate 'clearance:install' end def configure_unicorn copy_file 'unicorn.rb', 'config/unicorn.rb' end def setup_foreman copy_file 'sample.env', '.sample.env' copy_file 'Procfile', 'Procfile' end def setup_stylesheets remove_file 'app/assets/stylesheets/application.css' # concat_file 'import_scss_styles', 'app/assets/stylesheets/application.css.scss' # create_file 'app/assets/stylesheets/_screen.scss' end def gitignore_files concat_file 'suspenders_gitignore', '.gitignore' [ 'spec/lib', 'spec/controllers', 'spec/helpers', 'spec/support/matchers', 'spec/support/mixins', 'spec/support/shared_examples' ].each do |dir| run "mkdir #{dir}" run "touch #{dir}/.keep" end end def init_git run 'git init' end def create_heroku_apps path_addition = override_path_for_tests run "#{path_addition} heroku create #{app_name}-production --remote=production" run "#{path_addition} heroku create #{app_name}-staging --remote=staging" run "#{path_addition} heroku config:add RACK_ENV=staging RAILS_ENV=staging --remote=staging" end def create_github_repo(repo_name) path_addition = override_path_for_tests run "#{path_addition} hub create #{repo_name}" end def copy_miscellaneous_files copy_file 'errors.rb', 'config/initializers/errors.rb' end def customize_error_pages meta_tags =<<-EOS EOS style_tags =<<-EOS EOS %w(500 404 422).each do |page| inject_into_file "public/#{page}.html", meta_tags, :after => "
\n" replace_in_file "public/#{page}.html", /