diff --git a/lib/cybele.rb b/lib/cybele.rb index 58c5249..d25d87f 100644 --- a/lib/cybele.rb +++ b/lib/cybele.rb @@ -9,5 +9,6 @@ require 'cybele/helpers/simple_form' require 'cybele/helpers/show_for' require 'cybele/helpers/recipient_interceptor' +require 'cybele/helpers/haml' require 'cybele/helpers/locale_language' require 'cybele/app_builder' diff --git a/lib/cybele/app_builder.rb b/lib/cybele/app_builder.rb index 9f0b5e1..5c0a46b 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::Haml include Cybele::Helpers::LocaleLanguage def readme @@ -35,6 +36,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 e19ae78..691509b 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 @@ -153,6 +166,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/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/spec/features/new_default_project_spec.rb b/spec/features/new_default_project_spec.rb index ac435f2..4dac195 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'/) @@ -216,4 +221,13 @@ secret_file = content('config/secrets.yml') expect(secret_file).to match('staging') 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 4f85c74..06963a6 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 @@ -181,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'/) @@ -195,4 +201,13 @@ secret_file = content('config/secrets.yml') expect(secret_file).to match('staging') 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 00ebecc..c973621 100644 --- a/templates/Gemfile.erb +++ b/templates/Gemfile.erb @@ -29,4 +29,4 @@ group :development, :test do 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' \ No newline at end of file +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/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