From 0239a0a2c1e60b40f66e86743298d93e3b9d5c08 Mon Sep 17 00:00:00 2001 From: "esref.viduslu" Date: Fri, 27 Oct 2017 19:32:08 +0300 Subject: [PATCH 1/3] KBP-124 #time 4h - Haml and haml-rails gem integrate cybele gem. --- lib/cybele.rb | 1 + lib/cybele/app_builder.rb | 1 + lib/cybele/generators/app_generator.rb | 14 ++++++++++++++ lib/cybele/helpers/haml_and_haml_rails.rb | 18 ++++++++++++++++++ spec/features/new_default_project_spec.rb | 9 +++++++++ spec/features/new_not_default_project_spec.rb | 12 +++++++++++- templates/haml_and_haml_rails/haml_Gemfile.erb | 5 +++++ 7 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 lib/cybele/helpers/haml_and_haml_rails.rb create mode 100644 templates/haml_and_haml_rails/haml_Gemfile.erb diff --git a/lib/cybele.rb b/lib/cybele.rb index e4fe635..75a4a2f 100644 --- a/lib/cybele.rb +++ b/lib/cybele.rb @@ -9,4 +9,5 @@ require 'cybele/helpers/simple_form' require 'cybele/helpers/show_for' require 'cybele/helpers/recipient_interceptor' +require 'cybele/helpers/haml_and_haml_rails' require 'cybele/app_builder' diff --git a/lib/cybele/app_builder.rb b/lib/cybele/app_builder.rb index 4190cc5..265f71c 100644 --- a/lib/cybele/app_builder.rb +++ b/lib/cybele/app_builder.rb @@ -9,6 +9,7 @@ class AppBuilder < Rails::AppBuilder include Cybele::Helpers::SimpleForm include Cybele::Helpers::RecipientInterceptor include Cybele::Helpers::ShowFor + include Cybele::Helpers::HamlAndHamlRails def readme template 'README.md.erb', diff --git a/lib/cybele/generators/app_generator.rb b/lib/cybele/generators/app_generator.rb index d558233..0d0f8ab 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_and_haml_rails, + 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_and_haml_rails) @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_and_haml_rails_gems unless @options[:skip_haml_and_haml_rails] bundle_command 'install --binstubs=bin/stubs' end @@ -148,6 +156,12 @@ def setup_simple_form build :configure_simple_form end + def setup_haml_and_haml_rails + return if @options[:skip_haml_and_haml_rails] + say 'Setting up haml and generate haml-rails', :green + build :configure_haml_and_haml_rails + 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/haml_and_haml_rails.rb b/lib/cybele/helpers/haml_and_haml_rails.rb new file mode 100644 index 0000000..c258767 --- /dev/null +++ b/lib/cybele/helpers/haml_and_haml_rails.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module Cybele + module Helpers + module HamlAndHamlRails + def configure_haml_and_haml_rails + # Add initializers + bundle_command 'exec rails generate haml:application_layout convert' + remove_file 'app/views/layouts/application.html.erb' + end + + def add_haml_and_haml_rails_gems + # Add Gems + append_file('Gemfile', template_content('haml_and_haml_rails/haml_Gemfile.erb')) + end + end + end +end diff --git a/spec/features/new_default_project_spec.rb b/spec/features/new_default_project_spec.rb index 7122adf..1f39623 100644 --- a/spec/features/new_default_project_spec.rb +++ b/spec/features/new_default_project_spec.rb @@ -169,4 +169,13 @@ secret_file = content('config/secrets.yml') expect(secret_file).to match('staging') end + + it 'uses haml and haml_rails' 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 4d2ba8e..838ec04 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') + # TODO rubocop metrics/linelength problem + run_cybele('--database=sqlite3 --skip-create-database --skip-sidekiq --skip-simple-form --skip-show-for --skip-haml-and-haml-rails') setup_app_dependencies end @@ -152,4 +153,13 @@ secret_file = content('config/secrets.yml') expect(secret_file).to match('staging') end + + it 'uses haml and haml_rails' 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/haml_and_haml_rails/haml_Gemfile.erb b/templates/haml_and_haml_rails/haml_Gemfile.erb new file mode 100644 index 0000000..9effe0b --- /dev/null +++ b/templates/haml_and_haml_rails/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 From 6264cf3b4da51691554fc808a5c775e62d262ea0 Mon Sep 17 00:00:00 2001 From: "esref.viduslu" Date: Mon, 30 Oct 2017 11:14:55 +0300 Subject: [PATCH 2/3] KBP-124 #time 15m - New not default projectc spec edited --- spec/features/new_not_default_project_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/features/new_not_default_project_spec.rb b/spec/features/new_not_default_project_spec.rb index 838ec04..d272610 100644 --- a/spec/features/new_not_default_project_spec.rb +++ b/spec/features/new_not_default_project_spec.rb @@ -6,8 +6,8 @@ before(:all) do drop_dummy_database remove_project_directory - # TODO rubocop metrics/linelength problem - run_cybele('--database=sqlite3 --skip-create-database --skip-sidekiq --skip-simple-form --skip-show-for --skip-haml-and-haml-rails') + run_cybele('--database=sqlite3 --skip-create-database --skip-sidekiq --skip-simple-form --skip-show-for'\ + ' --skip-haml-and-haml-rails') setup_app_dependencies end @@ -154,7 +154,7 @@ expect(secret_file).to match('staging') end - it 'uses haml and haml_rails' do + it 'do not use haml and haml_rails' do gemfile_file = content('Gemfile') expect(gemfile_file).not_to match(/^gem 'haml'/) expect(gemfile_file).not_to match(/^gem 'haml-rails'/) From 98e36cde4aa607e0855415ca5beedda79237c2e8 Mon Sep 17 00:00:00 2001 From: "esref.viduslu" Date: Mon, 30 Oct 2017 12:20:33 +0300 Subject: [PATCH 3/3] KBP-124 #time 15m - File and folder naming changed --- lib/cybele.rb | 2 +- lib/cybele/app_builder.rb | 2 +- lib/cybele/generators/app_generator.rb | 12 ++++++------ .../helpers/{haml_and_haml_rails.rb => haml.rb} | 8 ++++---- spec/features/new_default_project_spec.rb | 2 +- spec/features/new_not_default_project_spec.rb | 4 ++-- .../{haml_and_haml_rails => haml}/haml_Gemfile.erb | 0 7 files changed, 15 insertions(+), 15 deletions(-) rename lib/cybele/helpers/{haml_and_haml_rails.rb => haml.rb} (59%) rename templates/{haml_and_haml_rails => haml}/haml_Gemfile.erb (100%) diff --git a/lib/cybele.rb b/lib/cybele.rb index 75a4a2f..38d8c46 100644 --- a/lib/cybele.rb +++ b/lib/cybele.rb @@ -9,5 +9,5 @@ require 'cybele/helpers/simple_form' require 'cybele/helpers/show_for' require 'cybele/helpers/recipient_interceptor' -require 'cybele/helpers/haml_and_haml_rails' +require 'cybele/helpers/haml' require 'cybele/app_builder' diff --git a/lib/cybele/app_builder.rb b/lib/cybele/app_builder.rb index 265f71c..df8ed17 100644 --- a/lib/cybele/app_builder.rb +++ b/lib/cybele/app_builder.rb @@ -9,7 +9,7 @@ class AppBuilder < Rails::AppBuilder include Cybele::Helpers::SimpleForm include Cybele::Helpers::RecipientInterceptor include Cybele::Helpers::ShowFor - include Cybele::Helpers::HamlAndHamlRails + include Cybele::Helpers::Haml def readme template 'README.md.erb', diff --git a/lib/cybele/generators/app_generator.rb b/lib/cybele/generators/app_generator.rb index 0d0f8ab..4ce6e94 100644 --- a/lib/cybele/generators/app_generator.rb +++ b/lib/cybele/generators/app_generator.rb @@ -54,7 +54,7 @@ class AppGenerator < Rails::Generators::AppGenerator default: false, group: :cybele, desc: 'Skip show_for integration. Default: don\'t skip' - class_option :skip_haml_and_haml_rails, + class_option :skip_haml, type: :boolean, aliases: nil, default: false, @@ -74,7 +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_and_haml_rails) + option_with_ask_yes(:skip_haml) @options.freeze end @@ -83,7 +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_and_haml_rails_gems unless @options[:skip_haml_and_haml_rails] + build :add_haml_gems unless @options[:skip_haml] bundle_command 'install --binstubs=bin/stubs' end @@ -156,10 +156,10 @@ def setup_simple_form build :configure_simple_form end - def setup_haml_and_haml_rails - return if @options[:skip_haml_and_haml_rails] + def setup_haml + return if @options[:skip_haml] say 'Setting up haml and generate haml-rails', :green - build :configure_haml_and_haml_rails + build :configure_haml end def add_staging_secret_key diff --git a/lib/cybele/helpers/haml_and_haml_rails.rb b/lib/cybele/helpers/haml.rb similarity index 59% rename from lib/cybele/helpers/haml_and_haml_rails.rb rename to lib/cybele/helpers/haml.rb index c258767..5b2dc52 100644 --- a/lib/cybele/helpers/haml_and_haml_rails.rb +++ b/lib/cybele/helpers/haml.rb @@ -2,16 +2,16 @@ module Cybele module Helpers - module HamlAndHamlRails - def configure_haml_and_haml_rails + 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_and_haml_rails_gems + def add_haml_gems # Add Gems - append_file('Gemfile', template_content('haml_and_haml_rails/haml_Gemfile.erb')) + append_file('Gemfile', template_content('haml/haml_Gemfile.erb')) end end end diff --git a/spec/features/new_default_project_spec.rb b/spec/features/new_default_project_spec.rb index 1f39623..aa63036 100644 --- a/spec/features/new_default_project_spec.rb +++ b/spec/features/new_default_project_spec.rb @@ -170,7 +170,7 @@ expect(secret_file).to match('staging') end - it 'uses haml and haml_rails' do + it 'uses haml' do gemfile_file = content('Gemfile') expect(gemfile_file).to match(/^gem 'haml'/) expect(gemfile_file).to match(/^gem 'haml-rails'/) diff --git a/spec/features/new_not_default_project_spec.rb b/spec/features/new_not_default_project_spec.rb index d272610..667c0e2 100644 --- a/spec/features/new_not_default_project_spec.rb +++ b/spec/features/new_not_default_project_spec.rb @@ -7,7 +7,7 @@ drop_dummy_database remove_project_directory run_cybele('--database=sqlite3 --skip-create-database --skip-sidekiq --skip-simple-form --skip-show-for'\ - ' --skip-haml-and-haml-rails') + ' --skip-haml') setup_app_dependencies end @@ -154,7 +154,7 @@ expect(secret_file).to match('staging') end - it 'do not use haml and haml_rails' do + 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'/) diff --git a/templates/haml_and_haml_rails/haml_Gemfile.erb b/templates/haml/haml_Gemfile.erb similarity index 100% rename from templates/haml_and_haml_rails/haml_Gemfile.erb rename to templates/haml/haml_Gemfile.erb