require 'securerandom' # ============================================================================= # template for generating an orats base project for rails 4.2.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 task(message, color = :blue) puts say_status 'task', set_color(message, :bold), color end def 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 orats_to_local(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_commit task __method__ git :init commit 'Initial git commit' end def update_gitignore 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 commit 'Add common OS files, editor files and other paths' end def copy_gemfile task __method__ orats_to_local 'Gemfile' commit 'Add Gemfile' end def copy_base_favicon task __method__ orats_to_local 'app/assets/favicon/favicon_base.png' commit 'Add a 256x256 base favicon' end def add_dotenv task 'add_dotenv' orats_to_local '.env', '.env' gsub_file '.env', 'generate_token', generate_token gsub_file '.env', 'app_name', app_name commit 'Add development environment file' end def add_procfile task __method__ orats_to_local 'Procfile' commit 'Add Procfile' end def add_markdown_readme task __method__ orats_to_local 'README.md' commit 'Add markdown readme' end def add_license task __method__ author_name = git_config 'name' author_email = git_config 'email' orats_to_local '../../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 commit 'Add MIT license' end def update_app_secrets task __method__ orats_to_local 'config/secrets.yml' commit 'DRY out the yaml' end def update_app_config 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'] } config.cache_store = :redis_store, ENV['CACHE_URL'], { namespace: '#{app_name}::cache' } # 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' # Log everything to a single file. config.paths['log'] = ENV['LOG_FILE'] # Rotate logs daily. This gets overwritten in staging/production by writing # to syslog instead of a log file. Rotating in development prevents your # log file from getting out of control in size. config.logger = Logger.new(config.paths['log'].first, 'daily') S end append_file 'config/application.rb' do <<-'S' ActionView::Base.field_error_proc = Proc.new do |html_tag, instance| if html_tag =~ /\