Skip to content

Commit

Permalink
KBP-122 #time 1h 30m - Paperclip integration edited and conflict reso…
Browse files Browse the repository at this point in the history
…lved
  • Loading branch information
esref.viduslu committed Oct 31, 2017
2 parents 8b5a94b + e10314b commit 46a4c8e
Show file tree
Hide file tree
Showing 17 changed files with 195 additions and 3 deletions.
2 changes: 2 additions & 0 deletions lib/cybele.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
7 changes: 7 additions & 0 deletions lib/cybele/app_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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',
Expand Down
24 changes: 24 additions & 0 deletions lib/cybele/generators/app_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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

Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions lib/cybele/helpers/dotenv.rb
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions lib/cybele/helpers/haml.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions lib/cybele/helpers/paperclip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 40 additions & 0 deletions spec/features/new_default_project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'/)
Expand Down Expand Up @@ -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'/)
Expand Down Expand Up @@ -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"/)
Expand Down Expand Up @@ -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
43 changes: 42 additions & 1 deletion spec/features/new_not_default_project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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'/)
Expand Down Expand Up @@ -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'/)
Expand Down Expand Up @@ -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
5 changes: 4 additions & 1 deletion templates/Gemfile.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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
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'
1 change: 1 addition & 0 deletions templates/VERSION.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v0.1.0
3 changes: 3 additions & 0 deletions templates/dotenv/.env.local.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ROOT_PATH=http://localhost:3000

ROLLBAR_ACCESS_TOKEN=
5 changes: 5 additions & 0 deletions templates/dotenv/.env.production.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ROOT_PATH=https://<%= app_name %>.herokuapp.com

ROLLBAR_ACCESS_TOKEN=

SECRET_KEY_BASE=
5 changes: 5 additions & 0 deletions templates/dotenv/.env.staging.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ROOT_PATH=https://staging-<%= app_name %>.herokuapp.com

ROLLBAR_ACCESS_TOKEN=

SECRET_KEY_BASE=
2 changes: 2 additions & 0 deletions templates/dotenv/dotenv_Gemfile.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Dot-Env
gem 'dotenv-rails', require: 'dotenv/rails-now'
3 changes: 3 additions & 0 deletions templates/dotenv/env.sample.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ROOT_PATH=http://localhost:3000

ROLLBAR_ACCESS_TOKEN=
5 changes: 5 additions & 0 deletions templates/haml/haml_Gemfile.erb
Original file line number Diff line number Diff line change
@@ -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'
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Mail.register_interceptor RecipientInterceptor.new(Settings.email.sandbox, subject_prefix: '[STAGING]')

Mail.register_interceptor RecipientInterceptor.new(Settings.email.sandbox, subject_prefix: '[STAGING]')

0 comments on commit 46a4c8e

Please sign in to comment.