Ruby on Railsのプラグイン(gem)まとめ

2009年11月7日の時点で、google先生に時々教えてもらう程度で知っているプラグイン(プラギン?)。誰もまとめてくれないので書く。

認証プラグイン

auth_logic

AuthlogicはBen Johnson@Binary Logic氏が作成した「キレイで、シンプルで、控えめな」認証プラグインだ。Railsの認証機能としては、Rails自身の簡便な認証機構や、acts_as_authentication / restful_authenticationを使うことが多いが、このプラグインも少しずつ人気が出てきているようだ
http://d.hatena.ne.jp/mothprog/20090331/1238494900

他には acts_as_authenticated や restful_authentication などの認証のためのプラグインが存在している。authlogic で具体的にどういう controller と view を書けばよいのか分からない場合は後述の groundwork を使うと実装された状態のテンプレートを作ることができる。

ページネーションプラグイン

mislav-will_paginate

The name of the will_paginate gem is now “mislav-will_paginate” because it’s being built by GitHub. If you have a gem named “will_paginate”, it is old and you are advised to remove it from your system.
http://wiki.github.com/mislav/will_paginate

だってさ。<> を作るのがダルいときにやってくれる。

HTMLテンプレートプラグイン

Haml
<div id="profile">
  <div class="left column">
    <div id="date"><%= print_date %></div>
    <div id="address"><%= current_user.address %></div>
  </div>
  <div class="right column">
    <div id="email"><%= current_user.email %></div>
    <div id="bio"><%= current_user.bio %></div>
  </div>
</div>

#profile
  .left.column
    #date= print_date
    #address= current_user.address
  .right.column
    #email= current_user.email
    #bio= current_user.bio

のように書ける。nested なレイアウトエンジン。
erb の代わりに使うので index.html.erb ではなく index.html.haml とする。

html から haml が生成できる html2haml が標準で付属することはあまり知られていない。

CSSテンプレートプラグイン

Sass

Haml と同様に

table.hl {
  margin: 2em 0;
}
table.hl td.ln {
  text-align: right;
}

li {
  font-family: serif;
  font-weight: bold;
  font-size: 1.2em;
}

table.hl
  margin: 2em 0
  td.ln
    text-align: right

li
  font:
    family: serif
    weight: bold
    size: 1.2em

のように書ける。変数にも対応する。

public/stylesheets ディレクトリに sass ディレクトリを作成して default.sass なんぞを置くと、stylesheets/default.css にアクセスされたときに自動で sass から css のファイルが作成され、配置される。変更があっても自動で反映される。

これも css2sass が標準で添付することはあまり知られていない。

テスト

cucumber, webrat

features テストを標準語に近い形で書ける。らしい。
BDD 駆動のテストができるなんたらかんたら。

glowl

マカー御用達。ちなみに Windows 版の glowl も出た。

Rails Webアプリケーションのテンプレート

Groundwork

で、以上に述べたプラグイン(からwill_paginateを除く)が全て実装された Rails Web アプリケーションの雛形を作ることのできるアプリケーションが Groundwork である。

Groundwork is a set of rails templates that has the goal to jump-start the development of rails applications by helping in the configuration of development environment and with the implementation of features present in the majority of web applications:

Authentication
Authorization
Internationalization
Basic Administration
Basic Layout
In the best case it will permit a developer to focus in the domain specific features of his application.
http://github.com/hectoregm/groundwork

rails アプリの git の初期設定は設定ファイルをよけるなどの作業がダルいのだが、この雛形作成アプリケーションでは自動で処理してくれる。国際化にも対応しているのでそのようなコードを書きたい場合は非常にいい(その逆の場合は大変だ)。

認証まわり、レイアウトまわり、自動テストまわりの今年4月時点の動向まで追いつきたい場合は、このコードを読むと一通りが分かってよさそうだ。

それ以降のトレンドは知らない。

その他

使うときは使うよねプラグイン

  • active_scaffold
    • もしかして ajax-scaffold
    • controllerとview書かずにmodelの値を編集できるページを作ってくれる
    • 管理者ホイホイ
  • auto_complete
    • 自動補完・サジェスト
    • 動的にデータベース問い合わせしない場合はsuggest.js使った方が幸せになれるかも
  • acts_as_ordered_tree
    • 順序つき木
    • sortable_elementと連携することで木+ajaxD&Dの荒業が可能
  • super_inplace_controls
    • in_place_editingの派生。
    • 文字列クリックしたら編集できるアレ
  • acts_as_versioned
    • 版管理
  • crummy
  • acts_as_paranoid
    • 論理削除
    • アカウント消してくださいと要望が来るけれども消えたように見えて内部的には「削除された日時」を書き込んで削除されたように見えるようにしただけで、実はデータベース上にデータは残ってたりするんですよ的なアレ
  • mimetype-fu
    • MIMETYPEを別のに設定したいときあるよね
  • search_do
    • HE(Hyper Estraier)な前文検索を簡単に
    • もしかして acts_as_searchable
  • html5jp_graphs
    • html5なグラフっしょ
  • google_charts_on_rails
    • google chartで十分っしょ
  • acts_as_commentable
    • モデルにコメントをつけたい
  • acts_as_rated
    • モデルに評価(レイティング)したい
  • ajaxful-rating
    • モデルに5つ星でajaxな評価をしたい
  • background-fu
    • DBを介して背景仕事を渡す
      • 非同期な長時間な仕事に向く?
  • backgrounDRb
    • Drubyを介して背景仕事を渡す
      • 同期な短時間の並列仕事に向く?
  • jpmobile
    • ケータイ
  • calendar_date_select
    • カレンダーの選択をグラフィカルに
  • jRails
  • web-app-theme
    • デフォルトのテーマ
    • 定型なのでCSSが色々と返られるし出てくる(はず)
    • 管理者画面でデザインを投げたいときー
    • jqueryのテーマがもっさりしていたときー
  • InlineRuby
  • aasm
    • !?
  • capistrano
    • アプリケーションの本番環境へのデプロイ(設置・更新・メンテナンスモード移行)をコマンド1つで
  • Sinatra
    • 節子、それプラギンちゃう

節子、なんでrailsのプラギンたくさんあるちゅうのに日本語解説サイトがすくないんやろか。

...にいちゃん、メリケン語...読めないからそう思うだけや。