diff --git a/lib/cybele.rb b/lib/cybele.rb index facbb80..78e7489 100644 --- a/lib/cybele.rb +++ b/lib/cybele.rb @@ -7,8 +7,10 @@ require 'cybele/helpers/sidekiq' require 'cybele/helpers/responders' require 'cybele/helpers/simple_form' +require 'cybele/helpers/dotenv' require 'cybele/helpers/show_for' require 'cybele/helpers/recipient_interceptor' +require 'cybele/helpers/haml' require 'cybele/helpers/locale_language' require 'cybele/helpers/paperclip' require 'cybele/app_builder' diff --git a/lib/cybele/app_builder.rb b/lib/cybele/app_builder.rb index 4e8b76a..6cbf44b 100644 --- a/lib/cybele/app_builder.rb +++ b/lib/cybele/app_builder.rb @@ -7,8 +7,10 @@ class AppBuilder < Rails::AppBuilder include Cybele::Helpers::Sidekiq include Cybele::Helpers::Responders include Cybele::Helpers::SimpleForm + include Cybele::Helpers::Dotenv include Cybele::Helpers::RecipientInterceptor include Cybele::Helpers::ShowFor + include Cybele::Helpers::Haml include Cybele::Helpers::LocaleLanguage include Cybele::Helpers::Paperclip @@ -36,6 +38,11 @@ def add_ruby_version copy_file 'ruby-version', '.ruby-version' end + def add_cybele_version + copy_file 'VERSION.txt', 'VERSION.txt' + run 'ln -s ../VERSION.txt public/VERSION.txt' + end + def use_postgres_config_template template 'postgresql_database.yml.erb', 'config/database.yml', diff --git a/lib/cybele/generators/app_generator.rb b/lib/cybele/generators/app_generator.rb index 5bc9516..a7e0deb 100644 --- a/lib/cybele/generators/app_generator.rb +++ b/lib/cybele/generators/app_generator.rb @@ -54,6 +54,12 @@ class AppGenerator < Rails::Generators::AppGenerator default: false, group: :cybele, desc: 'Skip show_for integration. Default: don\'t skip' + class_option :skip_haml, + type: :boolean, + aliases: nil, + default: false, + group: :cybele, + desc: 'Skip haml and haml-rails integration. Default: don\'t skip' def initialize(*args) super @@ -68,6 +74,7 @@ def initialize(*args) option_with_ask_yes(:skip_sidekiq) option_with_ask_yes(:skip_simple_form) option_with_ask_yes(:skip_show_for) + option_with_ask_yes(:skip_haml) @options.freeze end @@ -76,6 +83,7 @@ def customize_gemfile build :add_gems build :add_simple_form_gem unless @options[:skip_simple_form] build :add_show_for_gem unless @options[:skip_show_for] + build :add_haml_gems unless @options[:skip_haml] bundle_command 'install --binstubs=bin/stubs' end @@ -89,6 +97,11 @@ def setup_ruby_version build :add_ruby_version end + def setup_cybele_version + say 'Add .VERSION.txt file', :green + build :add_cybele_version + end + def remove_files_we_dont_need say 'Remove files we don\'t need', :green build :remove_readme_rdoc @@ -99,6 +112,11 @@ def setup_config build :generate_config end + def setup_dotenv + say 'Generate env.sample and .env files', :green + build :configure_dotenv + end + def setup_database if @options[:database] == 'postgresql' say 'Set up postgresql template', :green @@ -153,6 +171,12 @@ def setup_simple_form build :configure_simple_form end + def setup_haml + return if @options[:skip_haml] + say 'Setting up haml and generate haml-rails', :green + build :configure_haml + end + def add_staging_secret_key say 'Add staging secret key to secret.yml file', :green build :add_staging_secret_key_to_secrets_yml 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/lib/cybele/helpers/haml.rb b/lib/cybele/helpers/haml.rb new file mode 100644 index 0000000..5b2dc52 --- /dev/null +++ b/lib/cybele/helpers/haml.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module Cybele + module Helpers + module Haml + def configure_haml + # Add initializers + bundle_command 'exec rails generate haml:application_layout convert' + remove_file 'app/views/layouts/application.html.erb' + end + + def add_haml_gems + # Add Gems + append_file('Gemfile', template_content('haml/haml_Gemfile.erb')) + end + end + end +end diff --git a/lib/cybele/helpers/paperclip.rb b/lib/cybele/helpers/paperclip.rb index 06aae72..3c9ff64 100644 --- a/lib/cybele/helpers/paperclip.rb +++ b/lib/cybele/helpers/paperclip.rb @@ -25,9 +25,13 @@ def create_paperclip_files # Add paperclip env to the all env files append_file('env.sample', template_content('paperclip/paperclip_env_sample.erb')) + gsub_file 'env.sample', /<%= app_name %>/, app_name append_file('.env.local', template_content('paperclip/paperclip_env_local.erb')) + gsub_file '.env.local', /<%= app_name %>/, app_name append_file('.env.staging', template_content('paperclip/paperclip_env_staging.erb')) + gsub_file '.env.staging', /<%= app_name %>/, app_name append_file('.env.production', template_content('paperclip/paperclip_env_production.erb')) + gsub_file '.env.production', /<%= app_name %>/, app_name end end end diff --git a/spec/features/new_default_project_spec.rb b/spec/features/new_default_project_spec.rb index d66b0d7..e528d9f 100644 --- a/spec/features/new_default_project_spec.rb +++ b/spec/features/new_default_project_spec.rb @@ -69,6 +69,11 @@ expect(locale_file).to match('destroy:') end + it 'uses cybele_version' do + expect(File).to exist(file_project_path('VERSION.txt')) + expect(File).to exist(file_project_path('public/VERSION.txt')) + end + it 'uses rollbar' do gemfile_file = content('Gemfile') expect(gemfile_file).to match(/^gem 'rollbar'/) @@ -117,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'/) @@ -212,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 paperclip' do gemfile_file = content('Gemfile') expect(gemfile_file).to match(/^gem "paperclip"/) @@ -241,4 +272,13 @@ expect(env_production_file).to match('AWS_ACCESS_KEY_ID=') expect(env_production_file).to match('AWS_SECRET_ACCESS_KEY=') end + + it 'uses haml' do + gemfile_file = content('Gemfile') + expect(gemfile_file).to match(/^gem 'haml'/) + expect(gemfile_file).to match(/^gem 'haml-rails'/) + + expect(File).not_to exist(file_project_path('app/views/layouts/application.html.erb')) + expect(File).to exist(file_project_path('app/views/layouts/application.html.haml')) + end end diff --git a/spec/features/new_not_default_project_spec.rb b/spec/features/new_not_default_project_spec.rb index 702422e..dd71292 100644 --- a/spec/features/new_not_default_project_spec.rb +++ b/spec/features/new_not_default_project_spec.rb @@ -6,7 +6,8 @@ before(:all) do drop_dummy_database remove_project_directory - run_cybele('--database=sqlite3 --skip-create-database --skip-sidekiq --skip-simple-form --skip-show-for') + run_cybele('--database=sqlite3 --skip-create-database --skip-sidekiq --skip-simple-form --skip-show-for'\ + ' --skip-haml') setup_app_dependencies end @@ -108,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'/) @@ -176,6 +182,11 @@ expect(config_staging_file).to match('RecipientInterceptor.new') end + it 'uses cybele_version' do + expect(File).to exist(file_project_path('VERSION.txt')) + expect(File).to exist(file_project_path('public/VERSION.txt')) + end + it 'do not use simple_form' do gemfile_file = content('Gemfile') expect(gemfile_file).not_to match(/^gem 'simple_form'/) @@ -220,4 +231,34 @@ expect(env_production_file).to match('AWS_ACCESS_KEY_ID=') expect(env_production_file).to match('AWS_SECRET_ACCESS_KEY=') 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'/) + expect(gemfile_file).not_to match(/^gem 'haml-rails'/) + + expect(File).to exist(file_project_path('app/views/layouts/application.html.erb')) + expect(File).not_to exist(file_project_path('app/views/layouts/application.html.haml')) + end end diff --git a/templates/Gemfile.erb b/templates/Gemfile.erb index b733e14..c973621 100644 --- a/templates/Gemfile.erb +++ b/templates/Gemfile.erb @@ -26,4 +26,7 @@ gem 'roo', '~> 2.7', '>= 2.7.1' group :development, :test do gem 'colorize', '~> 0.8.1' gem 'better_errors', '~> 2.4' -end \ No newline at end of file +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/VERSION.txt b/templates/VERSION.txt new file mode 100644 index 0000000..9ff151c --- /dev/null +++ b/templates/VERSION.txt @@ -0,0 +1 @@ +v0.1.0 \ No newline at end of file diff --git a/templates/dotenv/.env.local.erb b/templates/dotenv/.env.local.erb new file mode 100644 index 0000000..5384f34 --- /dev/null +++ b/templates/dotenv/.env.local.erb @@ -0,0 +1,3 @@ +ROOT_PATH=http://localhost:3000 + +ROLLBAR_ACCESS_TOKEN= diff --git a/templates/dotenv/.env.production.erb b/templates/dotenv/.env.production.erb new file mode 100644 index 0000000..a5e7684 --- /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= diff --git a/templates/dotenv/.env.staging.erb b/templates/dotenv/.env.staging.erb new file mode 100644 index 0000000..ec0db9e --- /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= 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..5384f34 --- /dev/null +++ b/templates/dotenv/env.sample.erb @@ -0,0 +1,3 @@ +ROOT_PATH=http://localhost:3000 + +ROLLBAR_ACCESS_TOKEN= diff --git a/templates/haml/haml_Gemfile.erb b/templates/haml/haml_Gemfile.erb new file mode 100644 index 0000000..9effe0b --- /dev/null +++ b/templates/haml/haml_Gemfile.erb @@ -0,0 +1,5 @@ + +# Haml is a templating engine for HTML. +gem 'haml', '~> 5.0', '>= 5.0.4' +# Haml-rails provides Haml generators for Rails. +gem 'haml-rails', '~> 1.0' \ 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