Rub はHaml的なEndless Rubyを気軽にはじめるために作ったGemです。 GitHubをsourceに追加して以下のようにインストールできます。

   1  % sudo gem install genki-rub

ソースコード を見るとわかりますが、非常に短いので現時点では、if文の複数行にまたがる条件文などには対応していません。気が向けばそのうち対応するかもしれません。

Rubを使ってSinatraアプリを作るには以下のようにします。

config.ru

   1  require "rubygems"
   2  require "rub"
   3  rub "app.rb"
   4  run Sinatra::Application

app.rb

   1  require "sinatra"
   2  require "dm-core"
   3  require "haml"
   4  
   5  DataMapper::setup(:default, ENV['DATABASE_URL'] || 'sqlite3://db.sqlite3')
   6  
   7  class Post
   8    include DataMapper::Resource
   9    property :id, Serial
  10    property :content, Text
  11    auto_upgrade!
  12  
  13  get "/" do
  14    @posts = Post.all(:order => [:id.desc])
  15    haml :index
  16  
  17  post "/" do
  18    Post.create(params)
  19    redirect "/"
  20  
  21  __END__
  22  @@ index
  23  %h1 Hello, Sinatra!
  24  %ul
  25    - @posts.each do |post|
  26      %li= post.content
  27  %form{:method => :post}
  28    %textarea{:name => :content}
  29    %input{:type => :submit, :value => "Post"}

面白い点として、 Endless RubyでもVimやこのブログのSyntaxハイライトはちゃんと機能してくれます(Emacs使いのレポート求む)

必要なファイルはこれだけです。あとはおもむろにshotgunしましょう。

   1  % shotgun
   2  == Shotgun starting Rack::Handler::Mongrel on localhost:9393

あとはhttp://localhost:9393にアクセスするだけです。 app.rbを適当に書き換えてリロードすると、変更が反映される事が確認できます。

shotgunは

   1  % sudo gem install shotgun

でインストールできます。

posted by Png genki on Mon 20 Jul 2009 at 05:09 with 2 comments
Contents
Shotgun+Sinatra+RubではじめるEndless Ruby生活
Comments
瀧内元気: MacOS版は以下にあります * [genki/ViMouse](https://githu... '23-1
KingofSmack: Here also good reads for this mobile applicatio... '14-5
Spencer: You don't have to re-compile it, this version w... '14-4
staiano: Any chance we can get a recompile for 10.9? '14-1
dsjf: https://gist.github.com/6bf1bf2c3cbb5eb6e7a7 これ... '13-1
Services from s21g
twpro(ツイプロ)
Twitterプロフィールを快適検索
地価2009
土地の値段を調べてみよう
MyRestaurant
自分だけのレストラン手帳
Formula
ブログに数式を埋め込める数式コミュニティ