diff --git a/lib/cybele.rb b/lib/cybele.rb index a7fb800..6d7a0a3 100644 --- a/lib/cybele.rb +++ b/lib/cybele.rb @@ -11,5 +11,5 @@ require 'cybele/helpers/recipient_interceptor' require 'cybele/helpers/haml' require 'cybele/helpers/locale_language' -require 'cybele/helpers/bullet' +require 'cybele/helpers/dotenv' require 'cybele/app_builder' diff --git a/lib/cybele/app_builder.rb b/lib/cybele/app_builder.rb index b64faad..725b038 100644 --- a/lib/cybele/app_builder.rb +++ b/lib/cybele/app_builder.rb @@ -11,7 +11,7 @@ class AppBuilder < Rails::AppBuilder include Cybele::Helpers::ShowFor include Cybele::Helpers::Haml include Cybele::Helpers::LocaleLanguage - include Cybele::Helpers::Bullet + include Cybele::Helpers::Dotenv def readme template 'README.md.erb', @@ -62,6 +62,10 @@ def generate_rollbar generate 'rollbar' end + def configure_bullet + configure_environment 'development', template_content('bullet/bullet_settings.rb') + end + private def configure_environment(rails_env, config) diff --git a/lib/cybele/generators/app_generator.rb b/lib/cybele/generators/app_generator.rb index c874885..fc496fe 100644 --- a/lib/cybele/generators/app_generator.rb +++ b/lib/cybele/generators/app_generator.rb @@ -182,6 +182,11 @@ def setup_bullet_config build :configure_bullet end + def setup_dotenv + say 'Generate env.sample and .env files', :green + build :configure_dotenv + end + def goodbye say 'Congratulations! That\'s all...', :green end diff --git a/lib/cybele/helpers/bullet.rb b/lib/cybele/helpers/bullet.rb deleted file mode 100644 index f379342..0000000 --- a/lib/cybele/helpers/bullet.rb +++ /dev/null @@ -1,22 +0,0 @@ -# frozen_string_literal: true - -module Cybele - module Helpers - module Bullet - def configure_bullet - config = <<-RUBY - config.after_initialize do - Bullet.enable = true - Bullet.alert = true - Bullet.bullet_logger = true - Bullet.console = true - Bullet.rails_logger = true - Bullet.add_footer = false - end - RUBY - bundle_command 'exec rails generate bullet:install' - configure_environment 'development', config - end - end - end -end diff --git a/lib/cybele/helpers/dotenv.rb b/lib/cybele/helpers/dotenv.rb new file mode 100644 index 0000000..9cc06cd --- /dev/null +++ b/lib/cybele/helpers/dotenv.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +module Cybele + module Helpers + module Dotenv + def configure_dotenv + # Add dotenv gem + inject_into_file 'Gemfile', template_content('dotenv/dotenv_Gemfile.erb'), + before: "# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'" + run_bundle + + # Create dotenv files + template 'dotenv/env.sample.erb', + 'env.sample', + force: true + template 'dotenv/.env.local.erb', + '.env.local', + force: true + template 'dotenv/.env.staging.erb', + '.env.staging', + force: true + template 'dotenv/.env.production.erb', + '.env.production', + force: true + end + end + end +end diff --git a/spec/features/new_default_project_spec.rb b/spec/features/new_default_project_spec.rb index dfe1b58..e77fddc 100644 --- a/spec/features/new_default_project_spec.rb +++ b/spec/features/new_default_project_spec.rb @@ -122,6 +122,11 @@ expect(gemfile_file).to match("gem 'better_errors'") end + it 'uses rails-i18n' do + gemfile_file = content('Gemfile') + expect(gemfile_file).to match(/^gem 'rails-i18n'/) + end + it 'uses show_for' do gemfile_file = content('Gemfile') expect(gemfile_file).to match(/^gem 'show_for'/) @@ -217,6 +222,27 @@ expect(secret_file).to match('staging') end + it 'control env.sample and .env files' do + gemfile_file = content('Gemfile') + expect(gemfile_file).to match(/^gem 'dotenv-rails'/) + + expect(File).to exist(file_project_path('env.sample')) + env_sample_file = content('env.sample') + expect(env_sample_file).to match('ROOT_PATH=http://localhost:3000') + + expect(File).to exist(file_project_path('.env.local')) + env_local_file = content('.env.local') + expect(env_local_file).to match('ROOT_PATH=http://localhost:3000') + + expect(File).to exist(file_project_path('.env.staging')) + env_staging_file = content('.env.staging') + expect(env_staging_file).to match('ROOT_PATH=https://staging-dummy_app.herokuapp.com') + + expect(File).to exist(file_project_path('.env.production')) + env_production_file = content('.env.production') + expect(env_production_file).to match('ROOT_PATH=https://dummy_app.herokuapp.com') + end + it 'uses haml' do gemfile_file = content('Gemfile') expect(gemfile_file).to match(/^gem 'haml'/) @@ -232,8 +258,5 @@ locale_file = content('config/environments/development.rb') expect(locale_file).to match('Bullet') - - locale_file = content('config/environments/test.rb') - expect(locale_file).not_to match('Bullet') end end diff --git a/spec/features/new_not_default_project_spec.rb b/spec/features/new_not_default_project_spec.rb index 6e72984..6fb9ea7 100644 --- a/spec/features/new_not_default_project_spec.rb +++ b/spec/features/new_not_default_project_spec.rb @@ -109,6 +109,11 @@ expect(gemfile_file).to match("gem 'better_errors'") end + it 'uses rails-i18n' do + gemfile_file = content('Gemfile') + expect(gemfile_file).to match(/^gem 'rails-i18n'/) + end + it 'do not use show_for' do gemfile_file = content('Gemfile') expect(gemfile_file).not_to match(/^gem 'show_for'/) @@ -188,9 +193,6 @@ locale_file = content('config/environments/development.rb') expect(locale_file).to match('Bullet') - - locale_file = content('config/environments/test.rb') - expect(locale_file).not_to match('Bullet') end it 'do not use simple_form' do @@ -208,6 +210,27 @@ expect(secret_file).to match('staging') end + it 'control env.sample and .env files' do + gemfile_file = content('Gemfile') + expect(gemfile_file).to match(/^gem 'dotenv-rails'/) + + expect(File).to exist(file_project_path('env.sample')) + env_sample_file = content('env.sample') + expect(env_sample_file).to match('ROOT_PATH=http://localhost:3000') + + expect(File).to exist(file_project_path('.env.local')) + env_local_file = content('.env.local') + expect(env_local_file).to match('ROOT_PATH=http://localhost:3000') + + expect(File).to exist(file_project_path('.env.staging')) + env_staging_file = content('.env.staging') + expect(env_staging_file).to match('ROOT_PATH=https://staging-dummy_app.herokuapp.com') + + expect(File).to exist(file_project_path('.env.production')) + env_production_file = content('.env.production') + expect(env_production_file).to match('ROOT_PATH=https://dummy_app.herokuapp.com') + end + it 'do not use haml' do gemfile_file = content('Gemfile') expect(gemfile_file).not_to match(/^gem 'haml'/) diff --git a/templates/Gemfile.erb b/templates/Gemfile.erb index 4f8cc42..b81ee22 100644 --- a/templates/Gemfile.erb +++ b/templates/Gemfile.erb @@ -28,3 +28,6 @@ group :development, :test do gem 'better_errors', '~> 2.4' gem 'bullet', '~> 5.6', '>= 5.6.1' end + +# A set of common locale data and translations to internationalize and/or localize your Rails applications. +gem 'rails-i18n', '~> 5.0', '>= 5.0.4' diff --git a/templates/bullet/bullet_settings.rb b/templates/bullet/bullet_settings.rb new file mode 100644 index 0000000..9a378a6 --- /dev/null +++ b/templates/bullet/bullet_settings.rb @@ -0,0 +1,8 @@ + config.after_initialize do + Bullet.enable = true + Bullet.alert = true + Bullet.bullet_logger = true + Bullet.console = true + Bullet.rails_logger = true + Bullet.add_footer = false + end diff --git a/templates/dotenv/.env.local.erb b/templates/dotenv/.env.local.erb new file mode 100644 index 0000000..e817432 --- /dev/null +++ b/templates/dotenv/.env.local.erb @@ -0,0 +1,3 @@ +ROOT_PATH=http://localhost:3000 + +ROLLBAR_ACCESS_TOKEN= \ No newline at end of file diff --git a/templates/dotenv/.env.production.erb b/templates/dotenv/.env.production.erb new file mode 100644 index 0000000..7d728f2 --- /dev/null +++ b/templates/dotenv/.env.production.erb @@ -0,0 +1,5 @@ +ROOT_PATH=https://<%= app_name %>.herokuapp.com + +ROLLBAR_ACCESS_TOKEN= + +SECRET_KEY_BASE= \ No newline at end of file diff --git a/templates/dotenv/.env.staging.erb b/templates/dotenv/.env.staging.erb new file mode 100644 index 0000000..a262956 --- /dev/null +++ b/templates/dotenv/.env.staging.erb @@ -0,0 +1,5 @@ +ROOT_PATH=https://staging-<%= app_name %>.herokuapp.com + +ROLLBAR_ACCESS_TOKEN= + +SECRET_KEY_BASE= \ No newline at end of file diff --git a/templates/dotenv/dotenv_Gemfile.erb b/templates/dotenv/dotenv_Gemfile.erb new file mode 100644 index 0000000..0846b3c --- /dev/null +++ b/templates/dotenv/dotenv_Gemfile.erb @@ -0,0 +1,2 @@ +# Dot-Env +gem 'dotenv-rails', require: 'dotenv/rails-now' diff --git a/templates/dotenv/env.sample.erb b/templates/dotenv/env.sample.erb new file mode 100644 index 0000000..e817432 --- /dev/null +++ b/templates/dotenv/env.sample.erb @@ -0,0 +1,3 @@ +ROOT_PATH=http://localhost:3000 + +ROLLBAR_ACCESS_TOKEN= \ No newline at end of file diff --git a/templates/recipient_interceptor/recipient_interceptor_staging.rb.erb b/templates/recipient_interceptor/recipient_interceptor_staging.rb.erb index c54fc8c..583d69e 100644 --- a/templates/recipient_interceptor/recipient_interceptor_staging.rb.erb +++ b/templates/recipient_interceptor/recipient_interceptor_staging.rb.erb @@ -1 +1,2 @@ -Mail.register_interceptor RecipientInterceptor.new(Settings.email.sandbox, subject_prefix: '[STAGING]') \ No newline at end of file + + Mail.register_interceptor RecipientInterceptor.new(Settings.email.sandbox, subject_prefix: '[STAGING]') \ No newline at end of file