Last active
August 29, 2015 14:18
-
-
Save jose8a/0cd4977f5c00c89a3440 to your computer and use it in GitHub Desktop.
Basic Rails Template
This file contains 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
##################################################################################################################### | |
##### Rails Template adapted from: | |
##### https://damirsvrtan.github.io/blog/2014/11/26/automate-generating-new-rails-applications/ | |
##### | |
##################################################################################################################### | |
##################################################################################################################### | |
##### Create a bin/setup file so new developers can start right away by executing just one command | |
##### Move this part once Rails 4.2.0 comes out, b/c the bin/setup script will be in | |
##### new Rails projects by default. | |
##################################################################################################################### | |
bin_setup_file = <<-FILE | |
#!/bin/sh | |
bundle install --path vendor/bundle | |
bundle exec rake db:setup | |
FILE | |
create_file 'bin/setup', bin_setup_file | |
##################################################################################################################### | |
##### Add an RBENV file to control the ruby version for the application | |
##################################################################################################################### | |
create_file ".ruby-version", "2.1.2" | |
##################################################################################################################### | |
##### Create a README for the project | |
##################################################################################################################### | |
remove_file "README.rdoc" | |
create_file "README.md", "Development: run ./bin/setup" | |
# Uncomment following line if using SCSS stylesheets instead of CSS | |
#run 'mv app/assets/stylesheets/application.css app/assets/stylesheets/application.scss' | |
##################################################################################################################### | |
##### Configure the appropriate Database Engine for the project | |
##################################################################################################################### | |
database_type = ask("Do you want to use postgres or mysql?", limited_to: ["pg", "mysql"]) | |
adapter = if database_type == 'pg' | |
gem 'pg' | |
'postgresql' | |
else | |
gem 'mysql2' | |
'mysql2' | |
end | |
database_file = <<-FILE | |
default: &default | |
adapter: <%= adapter %> | |
pool: 5 | |
timeout: 5000 | |
host: localhost | |
username: root | |
development: | |
<<: *default | |
database: <%= @app_name %>_development | |
password: | |
test: | |
<<: *default | |
database: <%= @app_name %>_test | |
production: | |
<<: *default | |
database: <%= @app_name %>_production | |
FILE | |
create_file 'config/database.yml', ERB.new(database_file).result(binding), force: true | |
##################################################################################################################### | |
##### Gemfile (tutorial approach): | |
##### 1) Remove unwanted gems from the default Gemfile | |
##### 2) Remove comments and double newlines from Gemfile | |
##### | |
##### Gemfile (my new approach): | |
##### 1) delete the default Gemfile | |
##### 2) generate a new Gemfile with our favorite gems | |
##### | |
##################################################################################################################### | |
##### Custom Gemfile approach from the tutorial: | |
# %w(spring coffee-rails sqlite3).each do |unwanted_gem| | |
# gsub_file("Gemfile", /gem '#{unwanted_gem}'.*\n/, '') | |
# end | |
# | |
# gsub_file("Gemfile", /#.*\n/, '') | |
# gsub_file("Gemfile", /^\n\n/, '') | |
##### Custom Gemfile approach from tutorial | |
# Maybe better to delete the Gemfile and re-create it with our favorite gems | |
new_gemfile = <<-FILE | |
gem 'rails', '4.0.8' | |
gem 'sqlite3' | |
# ================================================== | |
# Auth Libraries | |
# ================================================== | |
gem 'devise' | |
gem 'omniauth' | |
gem 'omniauth-twitter' | |
# ================================================== | |
# External Service tools | |
# ================================================== | |
gem 'jbuilder', '~> 1.2' | |
gem 'metainspector' | |
gem 'simple_form' | |
gem 'slim-rails' | |
gem 'draper' | |
group :development, :test do | |
gem 'rspec-rails', '~> 3.0.1' | |
gem 'factory_girl_rails', '~> 4.4.1' | |
end | |
group :test do | |
gem 'faker', '~> 1.4.3' | |
gem 'capybara', '~> 2.4.3' | |
gem 'database_cleaner', '~> 1.3.0' | |
gem 'launchy', '~> 2.4.2' | |
gem 'selenium-webdriver', '~> 2.43.0' | |
end | |
group :development do | |
gem 'spring' | |
gem 'pry-rails' | |
gem 'bullet' | |
gem 'traceroute' | |
gem 'better_errors' | |
gem 'binding_of_caller' | |
gem 'quiet_assets' | |
gem 'railroady' | |
gem 'sextant' | |
gem 'figaro' | |
gem 'rails_layout' | |
gem 'open_gem' | |
gem 'rb-readline' | |
#gem 'rails-footnotes' | |
#gem 'rails_best_practices' | |
#gem 'rubocop' | |
#gem 'reek' | |
end | |
FILE | |
remove_file "Gemfile" | |
create_file "Gemfile", new_gemfile | |
run "bundle install" | |
# Uncomment next line if using simple_form | |
# generate simple_form_installation | |
##################################################################################################################### | |
##### Git: | |
##### Initialize a git repo for the project and generate a default '.gitignore' | |
##### | |
##################################################################################################################### | |
git :init | |
%w(.sass-cache powder public/system dump.rdb logfile .DS_Store).each do |gitignored| | |
append_file ".gitignore", gitignored | |
end | |
git add: ".", commit: "-m 'Initial commit'" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment