Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
My rails 3 app template
# Cleaning up and extending the Gemfile
remove_file 'Gemfile'
create_file 'Gemfile', <<-GEMFILE
source 'http://rubygems.org'
gem 'rails', '3.2.8'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3'
gem 'pg', :group => :production
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
gem 'twitter-bootstrap-rails'
gem 'backbone-rails'
gem 'haml-rails'
gem 'haml-coffee'
gem 'faraday'
gem 'warden'
# To use ActiveModel has_secure_password
gem 'bcrypt-ruby', '~> 3.0.0'
# To use Jbuilder templates for JSON
# gem 'jbuilder'
# Use unicorn as the app server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
group :production, :test, :cucumber, :development do
# gem 'aws-s3'
# gem 'paperclip'
gem 'cancan'
end
group :test, :cucumber, :development do
gem 'pry'
gem 'ffaker'
gem 'factory_girl_rails'
gem 'factory_girl_generator'
end
group :test, :cucumber do
gem 'rack-test', :git => "https://github.com/hassox/rack-test.git"
gem 'capybara'
gem 'capybara-envjs', '= 0.4.0'
gem 'cucumber-rails'
gem 'pickle'
gem 'timecop'
gem 'launchy'
gem 'rspec-rails'
gem 'turn', :require => False #Pretty printed test output
gem 'fredo'
end
group :development do
gem 'wirble'
gem 'awesome_print'
gem 'ruby-debug'
end
GEMFILE
# Initializers and loading
application 'config.autoload_paths += %W(#{config.root}/lib)'
create_file 'config/secrets.yml.template', <<-SECRETS
# Environment secrets
S3_KEY: somekey
S3_SECRET: somesecret
S3_BUCKET: my-own-bucket
SECRETS
File.open('config/environment.rb', 'r+') do |env|
environment = env.read
env.pos = 0
secrets = <<-ENVIRONMENT
require 'yaml'
# Load the environment variables
unless ENV['RACK_ENV'] == 'production'
begin
YAML.load_file(File.expand_path('secrets.yml', File.dirname(__FILE__))).each do |key, value|
ENV[key] = value
end
rescue
raise "Error loading secrets configuration, please edit config/secrets.yml"
end
end
ENVIRONMENT
env << secrets
env << environment
end
# Generators
application <<-GENERATORS
config.generators do |g|
g.template_engine :haml
g.test_framework :rspec, :fixture => true, :views => false
g.integration_tool :cucumber
g.fixture_replacement :factory_girl, :dir => "spec/factories"
end
GENERATORS
# A good way to reach your own generators
# empty_directory 'lib/generators'
# git :clone => "--depth 0 https://github.com/leshill/rails3-app.git lib/generators"
# remove_dir 'lib/generators/.git'
# remove_file 'lib/generators/app.rb'
# Middleware
application <<-MIDDLEWARE
# config.middleware.use Warden::Manager do |manager|
# manager.default_strategies :sign_in
# manager.failure_app = SessionsController.action(:unauthorized)
# manager.serialize_into_session {|user| user.id}
# manager.serialize_from_session {|id| User.find(id)}
# end
# config.middleware.delete 'Sass::Plugin::Rack'
MIDDLEWARE
# Assets cleanup
remove_file "README"
remove_file "LICENSE"
remove_file "public/index.html"
remove_file "public/favicon.ico"
remove_file "public/robots.txt"
remove_file "public/images/rails.png"
readme = <<-README
=#{app_name.humanize}
=== A Rails 3 application
== Copyright
Copyright (c) #{Time.now.year} Leandro Pedroni. See LICENSE for details.
README
create_file "README.md", readme
# how do I output errors from the bundle install??
run 'bundle install --without production'
# After the app responds
rake "db:migrate"
rake "secret"
generate "rspec:install"
generate "cucumber:install --rspec --capybara"
generate "pickle --paths --email"
# Git
gitignore = <<-GITIGNORE
.bundle
db/*.sqlite3
log/*.log
tmp/**/*
.DS_Store
**/.DS_Store
db/schema.rb
config/secrets.yml
vendor/cache/*
GITIGNORE
remove_file '.gitignore'
create_file '.gitignore', gitignore
git :init
git :add => "."
git :commit => "-a -m 'Initial Commit'"
# Print documentation
docs = <<-DOCS
Good luck developing #{app_name.humanize}!
DOCS
log docs
@ilpoldo
Copy link
Author

ilpoldo commented Sep 2, 2010

Here's how to run the template:

rails new my_app_name -J -T -m https://gist.github.com/562360.txt

@ilpoldo
Copy link
Author

ilpoldo commented Apr 10, 2011

To do:

  • Add to the picke paths:

    when /^"(.+)"$/
    $1

  • Start using rvm and gemsets

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment