Created
September 26, 2018 17:15
-
-
Save CheezItMan/ea1d733281df5a65563ec50d9ce6cfc8 to your computer and use it in GitHub Desktop.
A Rails Application Template using Bootstrap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
puts "Executing the Rails template" | |
API_MODE = ARGV.include? '--api' | |
puts "API mode: #{API_MODE}" | |
unless API_MODE | |
# jQuery is cool | |
gem 'jquery-rails' | |
# Make $(document).ready work as expected, despite turbolinks weirdness | |
gem 'jquery-turbolinks' | |
gem 'bootstrap', '~> 4.1.3' | |
# CSS libraries | |
# gem 'foundation-rails' | |
# gem 'normalize-rails' | |
end | |
gem_group :development, :test do | |
# Use pry for rails console, enable binding.pry | |
gem 'pry-rails' | |
end | |
unless API_MODE | |
gem_group :development do | |
# Improve the error message you get in the browser | |
gem 'better_errors' | |
# Nice interactive terminal when an exception happens | |
gem 'binding_of_caller' | |
# Automatically run our tests | |
gem 'guard' | |
gem 'guard-minitest' | |
end | |
end | |
# Add some extra minitest support | |
gem_group :test do | |
gem 'minitest-rails' | |
gem 'minitest-reporters' | |
end | |
unless API_MODE | |
# Don't even install coffeescript | |
gsub_file 'Gemfile', /^gem \'coffee-rails\'/ do | |
"\# gem 'coffee-rails'" | |
end | |
# Add jquery to application.js to work with foundation-rails | |
inject_into_file 'app/assets/javascripts/application.js', after: '// about supported directives.' do | |
<<-'JAVASCRIPT' | |
//= require jquery3 | |
//= require popper | |
//= require bootstrap-sprockets | |
JAVASCRIPT | |
end | |
append_to_file 'app/assets/stylesheets/application.css' do | |
<<-'SCSS' | |
/* Custom bootstrap variables must be set or imported *before* bootstrap. */ | |
@import "bootstrap"; | |
SCSS | |
end | |
end | |
gsub_file 'app/assets/stylesheets/application.css', / \*= require_tree .\n/ do | |
"" | |
end | |
gsub_file 'app/assets/stylesheets/application.css', / \*= require_self\n/ do | |
"" | |
end | |
run "mv app/assets/stylesheets/application.css app/assets/stylesheets/application.scss" | |
# Mess with generators to get the behavior we expect around new files | |
# For these injections, indentation matters! | |
inject_into_file 'config/application.rb', after: "class Application < Rails::Application\n" do | |
<<-'RUBY' | |
config.generators do |g| | |
# Force new test files to be generated in the minitest-spec style | |
g.test_framework :minitest, spec: true | |
# Always use .js files, never .coffee | |
g.javascript_engine :js | |
end | |
RUBY | |
end | |
create_file 'Guardfile' do | |
<<~GUARDFILE | |
guard :minitest, autorun: false, spring: true do | |
watch(%r{^app/(.+)\.rb$}) { |m| "test/\#{m[1]}_test.rb" } | |
watch(%r{^app/controllers/application_controller\.rb$}) { 'test/controllers' } | |
watch(%r{^app/controllers/(.+)_controller\.rb$}) { |m| "test/integration/\#{m[1]}_test.rb" } | |
watch(%r{^app/views/(.+)_mailer/.+}) { |m| "test/mailers/\#{m[1]}_mailer_test.rb" } | |
watch(%r{^lib/(.+)\.rb$}) { |m| "test/lib/\#{m[1]}_test.rb" } | |
watch(%r{^test/.+_test\.rb$}) | |
watch(%r{^test/test_helper\.rb$}) { 'test' } | |
end | |
GUARDFILE | |
end | |
# Things to do after all the gems have been installed | |
after_bundle do | |
# Run rails generate minitest:install | |
generate "minitest:install", "--force" | |
# Add minitest reporters support. This must be run after | |
# rails generate minitest:install, because that command | |
# changes test/test_helper.rb | |
inject_into_file 'test/test_helper.rb', after: 'require "minitest/rails"' do | |
<<-'RUBY' | |
require "minitest/reporters" # for Colorized output | |
# For colorful output! | |
Minitest::Reporters.use!( | |
Minitest::Reporters::SpecReporter.new, | |
ENV, | |
Minitest.backtrace_filter | |
) | |
RUBY | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment