Skip to content

Commit

Permalink
Merged in feature/integrate_haml_and_haml_rails_gem (pull request #9)
Browse files Browse the repository at this point in the history
Feature/integrate haml and haml rails gem

Approved-by: Fatih Avsan <[email protected]>
Approved-by: Hamdi Bayhan <[email protected]>
Approved-by: İsmail Akbudak <[email protected]>
  • Loading branch information
Eşref VİDUŞLU authored and İsmail Akbudak committed Oct 31, 2017
2 parents 8434185 + 34c2630 commit c6dd629
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/cybele.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
1 change: 1 addition & 0 deletions lib/cybele/app_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 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 Down Expand Up @@ -153,6 +161,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
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
9 changes: 9 additions & 0 deletions spec/features/new_default_project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,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
12 changes: 11 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 @@ -191,4 +192,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
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'

0 comments on commit c6dd629

Please sign in to comment.