deiga
4/1/2012 - 4:07 PM

Rails template

Rails template

options = {}
if yes?("Do you want to use Devise?")
  options[:devise_model] = ask "What would you like the user model to be called? [user]"
  options[:devise_model] = "user" if options[:devise_model].blank?

  default_email = `git config --get user.email`.chomp
  default_password = 'password'

  email = ask "Initial user's email [#{default_email}]"
  password = ask "Initial user's password [#{default_password}]"

  options[:user_email] = email.blank? ? default_email : email
  options[:user_password] = password.blank? ? default_password : password
end

gem "newrelic_rpm"

if options[:devise_model]
  gem "devise"
end

gem "haml", :version => "~> 3.2.0.alpha.10"
gem "jquery-rails"
gem "kramdown"
gem "simple_form"

gem_group :assets do
  gem "sass-rails", :version => "~> 3.2.3"
  gem "coffee-rails", :version => "~> 3.2.1"
  gem "uglifier", :version => ">= 1.0.3"

  gem "bootstrap-sass-rails",
      :git => 'git://github.com/yabawock/bootstrap-sass-rails.git',
      :branch => 'develop'
  gem 'haml-rails'
  gem 'modernizr-rails'
end

gem_group :development, :test do
  gem "rspec-rails"
  # gem 'ruby-debug19', :require => 'ruby-debug'
end

gem_group :development do
  gem "thin"
  gem "foreman"
  gem "heroku"

  gem "guard-rspec"
  gem "guard-cucumber"
end

gem_group :test do
  gem "factory_girl_rails"
  gem "ffaker"
  gem "shoulda-matchers"
  gem "valid_attribute"
  gem "cucumber-rails", :require => false
end


run "bundle install --binstubs=./bundler_stubs"

# configure newrelic for heroku
get "https://raw.github.com/gist/2253296/newrelic.yml", "config/newrelic.yml"

generate "rspec:install"
generate "cucumber:install"
generate "simple_form:install", "--bootstrap"


if options[:devise_model]
  generate "devise:install"
  generate "devise", options[:devise_model]

  append_to_file "db/seeds.rb" do
<<-EOS

# create initial user
User.create!(:email => %q{#{options[:user_email]}}, :password => %q{#{options[:user_password]}})
EOS
  end
end


# initialize guard for rspec and cucumber
run "bundle exec guard init rspec"
run "bundle exec guard init cucumber"


# for deployment to heroku
application "config.assets.initialize_on_precompile = false"


# Enable simple factory syntax (create, build) in RSpec.
create_file "spec/support/factory_girl.rb" do
<<-EOS
RSpec.configure do |config|
  config.include FactoryGirl::Syntax::Methods
end
EOS
end

# Enable simple factory syntax (create, build) in Cucumber.
append_to_file "features/support/env.rb", "World(FactoryGirl::Syntax::Methods)"


initializer("mail.rb") do
<<-EOS
ActionMailer::Base.smtp_settings = {
  :address        => 'smtp.sendgrid.net',
  :port           => '587',
  :authentication => :plain,
  :user_name      => ENV['SENDGRID_USERNAME'],
  :password       => ENV['SENDGRID_PASSWORD'],
  :domain         => 'heroku.com'
}
ActionMailer::Base.delivery_method = :smtp
EOS
end


append_to_file "app/assets/javascripts/application.js" do
<<-EOS
//= require twitter/bootstrap
//= require modernizr
EOS
end

append_to_file "app/assets/stylesheets/application.css" do
<<-EOS
*= require twitter/bootstrap
*= require screen
EOS
end

create_file "app/assets/stylesheets/screen.css.scss" do
<<-EOS
@import "twitter/bootstrap";
@import "twitter/bootstrap/responsive";
EOS
end

create_file "app/views/layouts/application.html.haml" do
<<-EOS
!!! 5
%html.no-js{ lang: 'en' }
  %head
    %title= yield(:title)

    %meta{ name: 'viewport', content: 'width=device-width, initial-scale=1.0' }
    %meta{ charset: 'utf-8' }

    = csrf_meta_tag

    = stylesheet_link_tag :application
    = javascript_include_tag :application

  %body
    .container-fluid
      = yield
EOS
end


# set up procfile for foreman
create_file "Procfile" do
<<-EOS
web: bundle exec thin start -p $PORT -e $RACK_ENV
EOS
end


rake "db:migrate"
rake "db:seed"

remove_file 'public/index.html'
remove_file 'app/assets/images/rails.png'

git :init
git :add => "."
git :commit => %{-m "Initial commit"}