RubyのWebフレームワークの1つSinatraが面白い
require "rubygems"require "sinatra"require "topwords"require "open-uri"get '/' dobase = 'base.txt'uri1 = 'http://www.gutenberg.org/files/16457/16457.txt'uri2 = 'http://www.gutenberg.org/files/11/11.txt'@base = WordDictionary.new(base)@moon = WordDictionary.new(uri1)@alice = WordDictionary.new(uri2)html = "<h1>Frequency Used Words</h1>"# html += "#{@moon.top_by_frequency(20)}"html += "<h3>#{uri1}</h3><p>#{uniq_words(@moon, @base).join(" ")}</p>"html += "<h3>#{uri2}</h3><p>#{uniq_words(@alice, @base).join(" ")}</p>"htmlendhelpers dodef uniq_words(wdic, base)wdic.uniq_words(20, base)endend
てな感じでget, post, delete, updateなどのHTTPリクエストに対する動作を書く
実行もRubyスクリプトを実行すればサーバーが立つ
Railsに比べて簡単軽量
./public以下にファイルを置けるのでここでcssとか規定すればよさげだな
Sinatra: README
No comments:
Post a Comment