Last active
December 17, 2015 20:38
-
-
Save maca/5668642 to your computer and use it in GitHub Desktop.
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
require 'bundler' | |
run "echo TODO > README.rdoc" | |
wants_bootstrap = yes? 'Do you want to use bootstrap?' | |
wants_devise = yes? 'Do you want to use devise?' | |
if wants_devise | |
devise_model = ask 'What would you like your devise model to be?' | |
devise_model_fields = ask 'Yo can optionally provide additional params for the devise model (eg. name:string)' | |
end | |
staging_host = ask 'What is the mailer host for your staging server?' | |
production_host = ask 'What is the mailer host for your production server?' | |
inject_into_file 'Gemfile', after: "source 'https://rubygems.org'\n" do | |
'ruby "2.0.0"' | |
end | |
gem 'devise' if wants_devise | |
gem 'simple_form' | |
gem 'thin' | |
gem_group :assets do | |
gem 'bootstrap-sass' if wants_bootstrap | |
end | |
gem_group :development, :test do | |
gem 'factory_girl_rails' | |
end | |
gem_group :test do | |
gem 'rspec-rails' | |
gem 'capybara', require: %w{capybara capybara/rspec} | |
gem 'capybara-email', require: "capybara/email/rspec" | |
gem 'shoulda-matchers' | |
gem 'launchy' | |
end | |
Bundler.with_clean_env do | |
run :bundle | |
end | |
environment "config.time_zone = 'Central Time (US & Canada)'" | |
environment "config.i18n.default_locale = :es" | |
environment "config.assets.initialize_on_precompile = false" | |
environment <<-RUBY, env: :development | |
config.generators do |gen| | |
gen.orm :active_record | |
gen.test_framework :rspec | |
gen.fixture_replacement :factory_girl, dir: 'spec/factories' | |
gen.view_specs = false | |
gen.controller_specs = true | |
gen.routing_specs = false | |
gen.helper = false | |
gen.stylesheets = true | |
gen.javascripts = true | |
end | |
RUBY | |
### Production and staging ### | |
run 'cp config/environments/production.rb config/environments/staging.rb' | |
environment "config.action_mailer.default_url_options = {host: 'localhost:3000'}", | |
env: :development | |
environment "config.action_mailer.default_url_options = {host: 'example.com'}", | |
env: :test | |
environment "config.action_mailer.default_url_options = {host: '#{production_host}'}", | |
env: :production | |
environment "config.action_mailer.default_url_options = {host: '#{staging_host}'}", | |
env: :staging | |
### Stylesheets ### | |
inside 'app/assets/stylesheets' do | |
remove_file 'application.css' | |
file 'application.css.scss' | |
append_file 'application.css.scss' do | |
'@import "bootstrap";' if wants_bootstrap | |
end | |
end | |
### Javascripts ### | |
inside "app/assets/javascripts" do | |
remove_file "application.js" | |
file 'application.js.coffee', <<-CODE | |
#= require jquery | |
#= require jquery_ujs | |
#= require_tree . | |
CODE | |
inject_into_file "application.js.coffee", before: "#= require_tree ." do | |
"#= require bootstrap\n" if wants_bootstrap | |
end | |
end | |
### Simple form ### | |
if wants_bootstrap | |
generate 'simple_form:install --bootstrap' | |
else | |
generate 'simple_form:install' | |
end | |
### Home controller ### | |
generate "controller home index" | |
route "root to: 'home#index'" | |
remove_file "public/index.html" | |
### TDD ### | |
run "rm -r test" | |
generate "rspec:install" | |
inside 'spec' do | |
append_file "spec_helper.rb" do | |
<<-RUBY | |
class ActiveRecord::Base | |
mattr_accessor :shared_connection | |
@@shared_connection = nil | |
def self.connection | |
@@shared_connection || retrieve_connection | |
end | |
end | |
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection | |
RUBY | |
end | |
inject_into_file 'spec_helper.rb', after: "require 'rspec/autorun'\n" do | |
"require 'capybara/rails'" | |
end | |
file 'support/feature_helpers.rb', <<-RUBY | |
module FeatureSpecHelpers | |
# Put helper methods you need to be available in all acceptance specs here. | |
end | |
RSpec.configuration.include FeatureSpecHelpers, type: :feature | |
RUBY | |
file 'support/matchers.rb', <<-RUBY | |
module DefinePageMatcher | |
def define_matcher name, &block | |
mod = self | |
klass = Class.new do | |
include Capybara::RSpecMatchers | |
include Capybara::DSL | |
include mod | |
attr_reader :expected | |
def initialize expected | |
@expected = expected | |
end | |
define_method :matches?, &block | |
end | |
define_method name do |expected| | |
klass.new expected | |
end | |
end | |
end | |
module PageMatchers | |
extend DefinePageMatcher | |
define_matcher :show_notice do |page| | |
within '.alert-notice' do | |
page.should have_content expected | |
end | |
end | |
define_matcher :show_alert do |page| | |
within '.alert-alert' do | |
page.should have_content expected | |
end | |
end | |
define_matcher :show_error do |page| | |
within '.alert-error' do | |
page.should have_content expected | |
end | |
end | |
end | |
RSpec.configuration.include PageMatchers, type: :feature | |
RUBY | |
run 'mkdir features' | |
end | |
### application layout ### | |
gsub_file 'app/views/layouts/application.html.erb', /<%= yield %>/ do | |
<<-ERB | |
<header></header> | |
<section class="content"> | |
<% flash.each do |key, val| %> | |
<header class='flash alert alert-<%= key %>'> | |
<button type="button" class="close" data-dismiss="alert">×</button> | |
<%= val %> | |
</header> | |
<% end %> | |
<div> | |
<%= yield %> | |
</div> | |
</section> | |
<footer></footer> | |
ERB | |
end | |
### spanish locales ### | |
inside "config/locales" do | |
file "application.es.yml", 'es:' | |
file "forms.es.yml", 'es:' | |
remove_file "en.yml" | |
run "curl https://raw.github.com/svenfuchs/rails-i18n/master/rails/locale/es-MX.yml > es.yml" | |
end | |
### Devise ### | |
if wants_devise | |
run "curl https://gist.github.com/sartip/2231938/raw > config/locales/devise.es.yml" | |
generate "devise:install" | |
generate "devise #{devise_model} #{devise_model_fields}" | |
end | |
### GIT ### | |
git :init | |
file ".gitignore", <<-EOF | |
/.bundle | |
/db/*.sqlite3 | |
/log/*.log | |
/tmp | |
*.swp | |
/wireframes | |
.ruby-version | |
*.swo | |
\#*# | |
EOF | |
git add: '.' | |
git commit: "-m 'initial commit'" | |
run "touch tmp/restart.txt" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment