Created
July 29, 2011 15:58
-
-
Save kennyj/1114101 to your computer and use it in GitHub Desktop.
backbone.jsが利用できる状態でrailsプロジェクト生成
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
#!/bin/sh | |
# railsプロジェクト作成して移動する | |
rails new "$1" -T -J | |
cd "$1" | |
# Gemfileに必要なgemを追記する | |
cat << HERE >> Gemfile | |
gem 'jquery-rails' | |
group :development, :test do | |
gem 'rspec' | |
gem 'rspec-rails' | |
gem 'simplecov' | |
gem 'simplecov-rcov' | |
gem 'ci_reporter' | |
end | |
HERE | |
# gemをインストールする | |
bundle install | |
# ジェネレータを起動する | |
rails g rspec:install | |
rails g jquery:install --ui | |
# jqueryをデフォルトの設定に任せ利用するようにする。 | |
perl -pi -e 's/config\.action_view\.javascript_expansions/# config.action_view.javascript_expansions/g' config/application.rb | |
# backbone.jsを利用出来るようにする | |
mkdir lib/generators | |
cat << HERE >> lib/generators/backbone_js_generator.rb | |
require 'openssl' | |
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE | |
class BackboneJsGenerator < Rails::Generators::Base | |
desc "This generator downloads and installs json2.js, underscore.js, backbone.js" | |
def download_json2_js | |
say_status("fetching", "json2.js", :green) | |
get "https://github.com/douglascrockford/JSON-js/raw/master/json2.js", | |
"public/javascripts/json2.js" | |
end | |
def download_underscore_js | |
say_status("fetching", "underscore.js", :green) | |
download_via_documentcloud("underscore") | |
download_via_documentcloud("underscore", "-min") | |
end | |
def download_backbone_js | |
say_status("fetching", "backbone.js", :green) | |
download_via_documentcloud("backbone") | |
download_via_documentcloud("backbone", "-min") | |
end | |
private | |
def download_via_documentcloud(product, suffix = "") | |
get "http://documentcloud.github.com/#{product}/#{product}#{suffix}.js", | |
"public/javascripts/#{product}#{suffix}.js" | |
end | |
end | |
HERE | |
rails g backbone_js | |
cat << HERE >> config/initializers/backbone_js.rb | |
module BackboneJs | |
module Rails | |
class Railtie < ::Rails::Railtie | |
config.before_configuration do | |
config.action_view.javascript_expansions[:backbone] = | |
::Rails.env.production? ? %w(json2 underscore-min backbone-min) : %w(json2 underscore backbone) | |
end | |
end | |
end | |
end | |
HERE | |
# 日本語翻訳ファイルを用意する | |
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: | |
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 | |
# レイアウトに文字コード指定と、backbone.jsの設定を追記する | |
cat << HERE > app/views/layouts/application.html.erb | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>$1</title> | |
<meta charset="utf-8"/> | |
<%= stylesheet_link_tag :all %> | |
<%= javascript_include_tag :defaults %> | |
<%= javascript_include_tag :backbone %> | |
<%= csrf_meta_tag %> | |
</head> | |
<body> | |
<%= yield %> | |
</body> | |
</html> | |
HERE | |
# simplecov利用を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' | |
# 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 | |
HERE | |
# ci_reporterのtaskを追加 | |
cat << HERE > lib/tasks/ci_reporter.rake | |
require 'ci/reporter/rake/rspec' | |
HERE | |
# 履歴管理開始する | |
git init | |
git add . | |
git commit -m "first commit" | |
# rails g scaffold post title:string body:text published:boolean | |
# とりあえず一度specを流す | |
rake db:migrate | |
COVERAGE=yes rake ci:setup:rspec spec | |
# とりあえずサーバ起動 | |
rails s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment