• 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

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

Comments:

Face Yuumi3 almost 15 years ago.

Emacs、TextMateともSyntaxハイライトはちゃんとしてます。

Png 瀧内元気 almost 15 years ago.

おお。レポートどうもです :-)

or Preview
Social Bookmarks
  • Delicious
  • B_entry1558
  • Clip_16_12_w
Services from s21g
twpro(ツイプロ)
Twitterプロフィールを快適検索
地価2009
土地の値段を調べてみよう
MyRestaurant
自分だけのレストラン手帳
Formula
ブログに数式を埋め込める数式コミュニティ