require 'securerandom' # ============================================================================= # template for generating an orats base project for rails 4.1.x # ============================================================================= # view the task list at the bottom of the file # ----------------------------------------------------------------------------- # ----------------------------------------------------------------------------- # private functions # ----------------------------------------------------------------------------- def generate_token SecureRandom.hex(64) end def method_to_sentence(method) method.tr!('_', ' ') method[0] = method[0].upcase method end def log_task(message) puts say_status 'task', "#{method_to_sentence(message.to_s)}:", :yellow puts '-'*80, ''; sleep 0.25 end def git_commit(message) git add: '-A' git commit: "-m '#{message}'" end def git_config(field) command = "git config --global user.#{field}" git_field_value = run(command, capture: true).gsub("\n", '') default_value = "YOUR_#{field.upcase}" git_field_value.to_s.empty? ? default_value : git_field_value end def copy_from_local_gem(source, dest = '') dest = source if dest.empty? base_path = "#{File.expand_path File.dirname(__FILE__)}/includes/new/rails" run "mkdir -p #{File.dirname(dest)}" unless Dir.exist?(File.dirname(dest)) run "cp -f #{base_path}/#{source} #{dest}" end # --- def initial_git_commit log_task __method__ git :init git_commit 'Initial git commit' end def update_gitignore log_task __method__ append_to_file '.gitignore' do <<-S # OS and editor files .DS_Store */**.DS_Store ._* .*.sw* *~ .idea/ # the dotenv file .env # app specific folders /vendor/bundle /public/assets/* S end git_commit 'Add common OS files, editor files and other paths' end def copy_gemfile log_task __method__ copy_from_local_gem 'Gemfile' git_commit 'Add Gemfile' end def copy_base_favicon log_task __method__ copy_from_local_gem 'app/assets/favicon/favicon_base.png' git_commit 'Add a 256x256 base favicon' end def add_dotenv log_task 'add_dotenv' copy_from_local_gem '.env', '.env' gsub_file '.env', 'generate_token', generate_token gsub_file '.env', 'app_name', app_name git_commit 'Add development environment file' end def add_procfile log_task __method__ copy_from_local_gem 'Procfile' git_commit 'Add Procfile' end def add_markdown_readme log_task __method__ copy_from_local_gem 'README.md' git_commit 'Add markdown readme' end def add_license log_task __method__ author_name = git_config 'name' author_email = git_config 'email' copy_from_local_gem '../../common/LICENSE', 'LICENSE' gsub_file 'LICENSE', 'Time.now.year', Time.now.year.to_s gsub_file 'LICENSE', 'author_name', author_name gsub_file 'LICENSE', 'author_email', author_email git_commit 'Add MIT license' end def update_app_secrets log_task __method__ copy_from_local_gem 'config/secrets.yml' git_commit 'DRY out the yaml' end def update_app_config log_task __method__ inject_into_file 'config/application.rb', after: "automatically loaded.\n" do <<-S config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { :address => ENV['SMTP_ADDRESS'], :port => ENV['SMTP_PORT'].to_i, :domain => ENV['SMTP_DOMAIN'], :user_name => ENV['SMTP_USERNAME'], :password => ENV['SMTP_PASSWORD'], :authentication => ENV['SMTP_AUTH'] } config.action_mailer.smtp_settings[:enable_starttls_auto] = true if ENV['SMTP_ENCRYPTION'] == 'starttls' config.action_mailer.smtp_settings[:ssl] = true if ENV['SMTP_ENCRYPTION'] == 'ssl' config.action_mailer.default_options = { from: ENV['ACTION_MAILER_DEFAULT_FROM'] } config.action_mailer.default_url_options = { host: ENV['ACTION_MAILER_HOST'] } redis_store_options = { host: ENV['CACHE_HOST'], port: ENV['CACHE_PORT'].to_i, db: ENV['CACHE_DATABASE'].to_i, namespace: '#{app_name}::cache' } redis_store_options[:password] = ENV['CACHE_PASSWORD'] if ENV['CACHE_PASSWORD'].present? config.cache_store = :redis_store, redis_store_options # run `bundle exec rake time:zones:all` to get a complete list of valid time zone names config.time_zone = ENV['TIME_ZONE'] unless ENV['TIME_ZONE'] == 'UTC' # http://www.loc.gov/standards/iso639-2/php/English_list.php config.i18n.default_locale = ENV['DEFAULT_LOCALE'] unless ENV['DEFAULT_LOCALE'] == 'en' S end append_file 'config/application.rb' do <<-'S' ActionView::Base.field_error_proc = Proc.new do |html_tag, instance| if html_tag =~ /\