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_U RL'] || 'sqlite3:// db.sqlite3 ') 6 7 class Post 8 include DataMapper ::Resource 9 property :id, Serial 10 property :content, Text 11 auto_upgra de! 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.conte nt 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::Mongr el on localhost: 9393
あとはhttp://loc
shotgunは
1 % sudo gem install shotgun
でインストールできます。
posted by
genki
on Mon 20 Jul 2009
at 05:09
with
2 comments
Emacs、TextMateともSyntaxハイライトはちゃんとしてます。
おお。レポートどうもです :-)