Skip to content

Instantly share code, notes, and snippets.

@kumonopanya
Created March 4, 2010 15:21
Show Gist options
  • Save kumonopanya/321797 to your computer and use it in GitHub Desktop.
Save kumonopanya/321797 to your computer and use it in GitHub Desktop.
Rails template 機能
# Application Template機能はRAILS2.3からの新機能をつかう。
# この機能を使うと初期設定のルーチンワークから離れることが出来る。
#
# いままではrails [アプリ名] とコマンドを打ってから
# gitの設定や、定番プラグインを入れていた<=面倒!
# テンプレートエンジンのコード保存先としてGistを利用
# Gist - GitHub
# http://gist.github.com/
# Gistはgithubの短いコードを管理するウェブサービス。
# 指定方法
# http://gist.github.com/[取得した番号].txt
# 後ろの「.txt」の拡張子をつけると表示される。
# 実行方法
# rails [アプリネーム] -m http://gist.github.com/[取得した番号].txt
# 例)
# rails todo -m http://gist.github.com/321797.txt
##################################################
# 複数人でGit管理を想定して、
# 現環境のデータベース設定を待避(コピー)しておく。
# Copy database.yml
run "cp config/database.yml config/database.sample.yml"
# 不要なファイルの削除
# Delete unnecessary files
#run "rm README"
#run "rm public/index.html"
##################################################
# gitの初期化
# Set up git
git :init
git :add => '.'
##################################################
# Install plugins
# テスト駆動開発に必須のrspecプラグイン
#plugin 'rspec',
# :git => 'git://github.com/dchelimsky/rspec.git', :submodule => true
#plugin 'rspec-rails',
# :git => 'git://github.com/dchelimsky/rspec-rails.git', :submodule => true
# 国際化プラグイン
#plugin 'i18n_generators',
# :git => 'git://github.com/amatsuda/i18n_generators.git', :submodule => true
# 不要ならプラグインの先頭にコメント(#)をつける。
# 認証プラグイン
#plugin 'restful-authentication',
# :git => 'git://github.com/technoweenie/restful-authentication.git'
# ステートマシン(システムの状態を数学的に表現したもの)
# (ある事象(イベント)によりまた新しい状態(ステート)を生成する回路)
#gem 'rubyist-aasm',
# :lib => 'aasm', :source => 'http://gems.github.com'
#rake("gems:install")
#generate("authenticated", "--include-activation", "--aasm", "user", "session")
#rake("db:migrate")
#generate(:controller, 'welcome', 'index')
#route "map.root :controller => 'welcome'"
# 下記のgemコマンドは直接
# environment.rb
# に書く為に設定する。
# これによって各gemのバージョン指定ができる
# 他にもダウンロードする先のライブラリの場所も指定できる。
# (指定するgemはインストールしておく必要がある。)
# この「mislav-will_paginate」のライブラリ名は「will_paginate」なので
# 下記のように:lib => 'will_paginate'と指定しないと読み込みエラーとなる。
# gem list で現在インストールされているバージョンを確認する。
# gem list
# mislav-will_paginate (2.3.11)
# ↑バージョン確認
# paginat(1ページのデータ数が多くなる場合、適当なページ数に分けるプラグイン)
#gem 'mislav-will_paginate', :version => '~> 2.3.11',
# :lib => 'will_paginate', :source => 'http://gems.github.com'
#gem 'ruby-openid'
##################################################
# Gitで無視(バージョン管理しない)ファイルの設定。
# Add .gitignore
run "touch tmp/.gitignore"
run "touch log/.gitignore"
run "touch vendor/.gitignore"
file '.gitignore', <<-END
.DS_Store
log/*.log
tmp/**/*
.*.swp
config/database.yml
db/*.sqlite3
db/schema.rb
doc/api
doc/app
END
##################################################
# Execute generator
#generate :rspec
#generate :i18n, "ja"
# Commit git
git :submodule => "init"
git :add => "."
git :commit => "-a -m 'Initial commit'"
##################################################
##################################################
##################################################
# テンプレートで使えるDSL
#
# gem(name, options = {})
#
# config/environment.rbにconfig.gemを追加する
# plugin(name, options = {})
# -プラグインをインストールする
# initializer(filename, data = nil, &block)
#
# config/initializersに初期化スクリプトを作成する
# 同じようにlib()やvendor()といったメソッドもある。
# rakefile(filename, data = nil, &block)
#
# lib/tasksにrakeファイルを作成する
# generate(what, args)
#
# generatorスクリプトを実行する
# run(command)
#
# shellコマンドを実行する
# rake(command, options = {})
#
# rakeコマンドを実行する
# route(routing_code)
#
# config/routes.rbにルート定義を追加する
# inside(dir)
#
# ディレクトリの中でコマンドなどを実行する
# ask(question)
#
# ユーザーからの入力を取得する
# yes?(question) or no?(question)
#
# y/n形式の入力を待つ
# git(:must => “-a love”)
#
# gitコマンドを実行する
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment