Skip to content

Instantly share code, notes, and snippets.

@kennyj
Created October 5, 2011 17:23
Show Gist options
  • Save kennyj/1265077 to your computer and use it in GitHub Desktop.
Save kennyj/1265077 to your computer and use it in GitHub Desktop.
backbone.jsが利用できる状態でrailsプロジェクト生成(rails3.1版)
#!/bin/sh
# railsプロジェクト作成して移動する
rails new "$1" -T
cd "$1"
# Gemfileに必要なgemを追記する
cat << HERE >> Gemfile
gem 'rails-backbone'
group :development, :test do
gem 'rspec'
gem 'rspec-rails'
gem 'capybara'
gem 'capybara-webkit'
gem 'headless'
gem 'simplecov'
gem 'simplecov-rcov'
gem 'ci_reporter'
end
HERE
perl -pi -e "s/# gem 'capistrano'/gem 'capistrano'/g" Gemfile
perl -pi -e "s/# gem 'ruby-debug19'/gem 'ruby-debug19'/g" Gemfile
# gemをインストールする
bundle install
# ジェネレータを起動する
bundle exec rails g rspec:install
bundle exec rails g backbone:install
bundle exec capify .
# 日本語翻訳ファイルを用意する
perl -pi -e 's/# config\.i18n\.default_locale = :de/config.i18n.default_locale = :ja/g' config/application.rb
cd config/locales
wget https://raw.github.com/svenfuchs/rails-i18n/master/rails/locale/ja.yml
cat <<HERE > translation_ja.yml
ja:
activerecord:
models:
attributes:
HERE
cd -
# specコマンドへのオプションを指定する
cat << HERE > .rspec
--color
--format documentation
--drb
HERE
# .gitignoreに履歴管理しないファイルを記載する
cat << HERE > .gitignore
*.swp
**.orig
*.rbc
*.sassc
.sass-cache
capybara-*.html
.rspec
/.bundle
/vendor/bundle
/log/*
/tmp/*
/db/*.sqlite3
/db/*.db
/public/system/*
/coverage/
/spec/reports/
/spec/tmp/*
config/*.yml
rerun.txt
pickle-email-*.html
HERE
# レイアウトに文字コード指定を追記する
cat << HERE > app/views/layouts/application.html.erb
<!DOCTYPE html>
<html>
<head>
<title>$1</title>
<meta charset="utf-8"/>
<%= stylesheet_link_tag "application" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tag %>
</head>
<body>
<%= yield %>
</body>
</html>
HERE
# simplecov、capybara利用をspec_helper.rbに付加
cat << HERE > spec/spec_helper.rb
if %w(yes y on).include?(ENV['COVERAGE'])
require 'simplecov'
require 'simplecov-rcov'
SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
SimpleCov.start 'rails'
end
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'capybara/rails'
require 'capybara/rspec'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
RSpec.configure do |config|
# == Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
config.mock_with :rspec
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = true
end
# see http://kennyj-jp.blogspot.com/2011/08/capybara-webkit.html
Capybara.javascript_driver = :webkit
# see http://kennyj-jp.blogspot.com/2011/09/capybarawebkitselenium.html
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
HERE
# headlessをサポート
mkdir -p spec/support
cat << HERE > spec/support/headless.rb
if %w(yes y on).include?(ENV['HEADLESS'])
require 'headless'
headless = Headless.new
headless.start
at_exit do
headless.destroy
end
end
HERE
# ci_reporterのtaskを追加
cat << HERE > lib/tasks/ci_reporter.rake
require 'ci/reporter/rake/rspec'
HERE
# stagingに対応しておく
cp config/environments/production.rb config/environments/staging.rb
cat << HERE >> config/database.yml
staging:
adapter: sqlite3
database: db/staging.sqlite3
pool: 5
timeout: 5000
HERE
# database.ymlは履歴管理しないので
cp config/database.yml config/database.yml.example
# http://kennyj-jp.blogspot.com/2011/08/rails3sub.html
perl -pi -e 's/(run .+Application)/map ActionController::Base.config.relative_url_root || "\/" do\n \1\nend/g' config.ru
# 履歴管理開始する
git init
git add .
git commit -m "first commit"
# bundle exec rails g scaffold post title:string body:text published:boolean
# rm public/index.html
# とりあえず一度specを流す
bundle exec rake db:migrate
HEADLESS=yes COVERAGE=yes bundle exec rake ci:setup:rspec spec
# とりあえずサーバ起動
bundle exec rails s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment