Skip to content

Commit

Permalink
Merged in feature/configure_bootstrap_and_sass (pull request #27)
Browse files Browse the repository at this point in the history
KBP-116 #time 3h - Configure bootstrap and sass

Approved-by: İsmail Akbudak <[email protected]>
Hamdi Bayhan committed Nov 28, 2017
2 parents 11f3ec3 + 3e06f11 commit 3fb4c48
Showing 12 changed files with 158 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/cybele.rb
Original file line number Diff line number Diff line change
@@ -17,5 +17,7 @@
require 'cybele/helpers/devise'
require 'cybele/helpers/docker'
require 'cybele/helpers/error_pages'
require 'cybele/helpers/view_files/assets_files'
require 'cybele/helpers/view_files/view_gems'
require 'cybele/helpers/pronto'
require 'cybele/app_builder'
2 changes: 2 additions & 0 deletions lib/cybele/app_builder.rb
Original file line number Diff line number Diff line change
@@ -16,6 +16,8 @@ class AppBuilder < Rails::AppBuilder
include Cybele::Helpers::Paperclip
include Cybele::Helpers::Devise
include Cybele::Helpers::ErrorPages
include Cybele::Helpers::ViewFiles::AssetsFiles
include Cybele::Helpers::ViewFiles::ViewGems
include Cybele::Helpers::Docker
include Cybele::Helpers::Pronto

14 changes: 14 additions & 0 deletions lib/cybele/generators/app_generator.rb
Original file line number Diff line number Diff line change
@@ -60,6 +60,12 @@ class AppGenerator < Rails::Generators::AppGenerator
default: false,
group: :cybele,
desc: 'Skip haml and haml-rails integration. Default: don\'t skip'
class_option :skip_view_files,
type: :boolean,
aliases: nil,
default: false,
group: :cybele,
desc: 'Skip view files. Default: don\'t skip'
class_option :skip_docker,
type: :boolean,
aliases: nil,
@@ -81,6 +87,7 @@ def initialize(*args)
option_with_ask_yes(:skip_simple_form)
option_with_ask_yes(:skip_show_for)
option_with_ask_yes(:skip_haml)
option_with_ask_yes(:skip_view_files)
option_with_ask_yes(:skip_docker)
@options.freeze
end
@@ -92,6 +99,7 @@ def customize_gemfile
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]
build :add_required_view_gems unless @options[:skip_view_files]
bundle_command 'install --binstubs=bin/stubs'
end

@@ -231,6 +239,12 @@ def configure_error_pages
build :configure_error_pages
end

def customize_view_files
return if @options[:skip_view_files]
say 'Customize view files', :green
build :customize_assets_files
end

def setup_git_and_git_flow
say 'Initialize git and git flow'
build :git_and_git_flow_commands
33 changes: 33 additions & 0 deletions lib/cybele/helpers/view_files/assets_files.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

module Cybele
module Helpers
module ViewFiles
module AssetsFiles
def customize_assets_files
# Javascript Assets files
remove_file 'app/assets/javascripts/application.js', force: true

template 'view_files/app/assets/javascripts/application.js',
'app/assets/javascripts/application.js',
force: true

template 'view_files/app/assets/javascripts/hq/application.js',
'app/assets/javascripts/hq/application.js',
force: true

# Css Assets files
remove_file 'app/assets/stylesheets/application.css', force: true

template 'view_files/app/assets/stylesheets/application.css.sass',
'app/assets/stylesheets/application.css.sass',
force: true

template 'view_files/app/assets/stylesheets/hq/application.css.sass',
'app/assets/stylesheets/hq/application.css.sass',
force: true
end
end
end
end
end
14 changes: 14 additions & 0 deletions lib/cybele/helpers/view_files/view_gems.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

module Cybele
module Helpers
module ViewFiles
module ViewGems
def add_required_view_gems
# Add bootstrap gem
append_file('Gemfile', template_content('view_files/bootstrap_Gemfile.erb'))
end
end
end
end
end
19 changes: 19 additions & 0 deletions spec/features/new_default_project_spec.rb
Original file line number Diff line number Diff line change
@@ -216,6 +216,25 @@
git_ignore_test
end

it 'uses assets files' do
gemfile_file = content('Gemfile')
expect(gemfile_file).to match(/^gem 'bootstrap'/)

expect(File).not_to exist(file_project_path('app/assets/stylesheets/application.css'))

application_stylesheets_file = content('app/assets/stylesheets/application.css.sass')
expect(application_stylesheets_file).to match('@import "bootstrap"')

hq_stylesheets_js_file = content('app/assets/stylesheets/hq/application.css.sass')
expect(hq_stylesheets_js_file).to match('@import "bootstrap"')

application_js_file = content('app/assets/javascripts/application.js')
expect(application_js_file).to match('require bootstrap')

hq_application_js_file = content('app/assets/javascripts/hq/application.js')
expect(hq_application_js_file).to match('require bootstrap')
end

it 'uses ssl_setting' do
force_ssl
end
14 changes: 13 additions & 1 deletion spec/features/new_not_default_project_spec.rb
Original file line number Diff line number Diff line change
@@ -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 --skip-docker')
' --skip-haml --skip-docker --skip-view-files')
setup_app_dependencies
end

@@ -196,6 +196,18 @@
git_ignore_test
end

it 'do not use assets files' do
gemfile_file = content('Gemfile')
expect(gemfile_file).not_to match(/^gem 'bootstrap'/)

expect(File).to exist(file_project_path('app/assets/stylesheets/application.css'))
expect(File).not_to exist(file_project_path('app/assets/stylesheets/application.css.sass'))
expect(File).not_to exist(file_project_path('app/assets/stylesheets/hq/application.css.sass'))

expect(File).to exist(file_project_path('app/assets/javascripts/application.js'))
expect(File).not_to exist(file_project_path('app/assets/javascripts/hq/application.js'))
end

it 'uses ssl_setting' do
force_ssl
end
16 changes: 16 additions & 0 deletions templates/view_files/app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's
// vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file. JavaScript code in this file should be added after the last require_* statement.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require rails-ujs
//= require turbolinks
//= require bootstrap
//= require_tree .
16 changes: 16 additions & 0 deletions templates/view_files/app/assets/javascripts/hq/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's
// vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file. JavaScript code in this file should be added after the last require_* statement.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require rails-ujs
//= require turbolinks
//= require bootstrap
//= require_tree .
13 changes: 13 additions & 0 deletions templates/view_files/app/assets/stylesheets/application.css.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* This is a manifest file that will be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the top of the
* compiled file, but it's generally better to create a new file per style scope.
*
*= require_self
@import "bootstrap"
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* This is a manifest file that will be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the top of the
* compiled file, but it's generally better to create a new file per style scope.
*
*= require_self
@import "bootstrap"
3 changes: 3 additions & 0 deletions templates/view_files/bootstrap_Gemfile.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

# Bootstrap ruby gem.
gem 'bootstrap', '~> 4.0.0.beta2.1'

0 comments on commit 3fb4c48

Please sign in to comment.