Sinatraを使ってみる

Rubyを全くまだ理解していないのにSinatraに手を出してみる。

gemでインストールしてみる

sudo gem install sinatra
Password:
Fetching: rack-1.5.2.gem (100%)
Successfully installed rack-1.5.2
Fetching: tilt-1.4.1.gem (100%)
Successfully installed tilt-1.4.1
Fetching: rack-protection-1.5.1.gem (100%)
Successfully installed rack-protection-1.5.1
Fetching: sinatra-1.4.4.gem (100%)
Successfully installed sinatra-1.4.4
Parsing documentation for rack-1.5.2
Installing ri documentation for rack-1.5.2
Parsing documentation for tilt-1.4.1
Installing ri documentation for tilt-1.4.1
Parsing documentation for rack-protection-1.5.1
Installing ri documentation for rack-protection-1.5.1
Parsing documentation for sinatra-1.4.4
unable to convert "x89" from ASCII-8BIT to UTF-8 for lib/sinatra/images/404.png, skipping
unable to convert "x89" from ASCII-8BIT to UTF-8 for lib/sinatra/images/500.png, skipping
Installing ri documentation for sinatra-1.4.4

WEBアクセスしてみる

$ ruby app.rb
[2013-11-21 00:04:14] INFO WEBrick 1.3.1
[2013-11-21 00:04:14] INFO ruby 2.0.0 (2013-06-27) [universal.x86_64-darwin13]
== Sinatra/1.4.4 has taken the stage on 4567 for development with backup from WEBrick
[2013-11-21 00:04:14] INFO WEBrick::HTTPServer#start: pid=1142 port=4567
#ここでブラウザで http://localhost:4567/ にアクセスしてみた
::1 - - [21/Nov/2013 00:05:50] "GET / HTTP/1.1" 200 12 0.0032
localhost - - [21/Nov/2013:00:05:50 JST] "GET / HTTP/1.1" 200 12
- -> /
::1 - - [21/Nov/2013 00:05:51] "GET /favicon.ico HTTP/1.1" 404 448 0.0014
localhost - - [21/Nov/2013:00:05:51 JST] "GET /favicon.ico HTTP/1.1" 404 448
- -> /favicon.ico
おーなんか出来てるね。HTML組むより早いw
padrinoを使ってみる
padrinoはsinatraのいいところを引き継ぎつつ、
sinatraにできな難しいことをできるように頑張っちゃいますよなツールらしいです。
$ sudo gem install padrino
Password:
Fetching: url_mount-0.2.1.gem (100%)
Successfully installed url_mount-0.2.1
Fetching: http_router-0.11.0.gem (100%)
Successfully installed http_router-0.11.0
Fetching: thor-0.17.0.gem (100%)
Successfully installed thor-0.17.0
Fetching: i18n-0.6.5.gem (100%)
Successfully installed i18n-0.6.5
Fetching: multi_json-1.8.2.gem (100%)
Successfully installed multi_json-1.8.2
Fetching: activesupport-3.2.15.gem (100%)
Successfully installed activesupport-3.2.15
Fetching: padrino-core-0.11.4.gem (100%)
Successfully installed padrino-core-0.11.4
Fetching: padrino-helpers-0.11.4.gem (100%)
Successfully installed padrino-helpers-0.11.4
Fetching: mime-types-1.25.gem (100%)
Successfully installed mime-types-1.25
Fetching: polyglot-0.3.3.gem (100%)
Successfully installed polyglot-0.3.3
Fetching: treetop-1.4.15.gem (100%)
Successfully installed treetop-1.4.15
Fetching: mail-2.5.4.gem (100%)
Successfully installed mail-2.5.4
Fetching: padrino-mailer-0.11.4.gem (100%)
Successfully installed padrino-mailer-0.11.4
Fetching: bundler-1.3.5.gem (100%)
Successfully installed bundler-1.3.5
Fetching: padrino-gen-0.11.4.gem (100%)
Successfully installed padrino-gen-0.11.4
Fetching: padrino-cache-0.11.4.gem (100%)
Successfully installed padrino-cache-0.11.4
Fetching: padrino-admin-0.11.4.gem (100%)
Successfully installed padrino-admin-0.11.4
Fetching: padrino-0.11.4.gem (100%)
Successfully installed padrino-0.11.4
Parsing documentation for url_mount-0.2.1
Installing ri documentation for url_mount-0.2.1
Parsing documentation for http_router-0.11.0
Installing ri documentation for http_router-0.11.0
Parsing documentation for thor-0.17.0
Installing ri documentation for thor-0.17.0
Parsing documentation for i18n-0.6.5
Installing ri documentation for i18n-0.6.5
Parsing documentation for multi_json-1.8.2
Installing ri documentation for multi_json-1.8.2
Parsing documentation for activesupport-3.2.15
unable to convert "x80" from ASCII-8BIT to UTF-8 for lib/active_support/values/unicode_tables.dat, skipping
Installing ri documentation for activesupport-3.2.15
Parsing documentation for padrino-core-0.11.4
unable to convert "x89" from ASCII-8BIT to UTF-8 for lib/padrino-core/images/404.png, skipping
unable to convert "x89" from ASCII-8BIT to UTF-8 for lib/padrino-core/images/500.png, skipping
Installing ri documentation for padrino-core-0.11.4
Parsing documentation for padrino-helpers-0.11.4
Installing ri documentation for padrino-helpers-0.11.4
Parsing documentation for mime-types-1.25
Installing ri documentation for mime-types-1.25
Parsing documentation for polyglot-0.3.3
Installing ri documentation for polyglot-0.3.3
Parsing documentation for treetop-1.4.15
Installing ri documentation for treetop-1.4.15
Parsing documentation for mail-2.5.4
unable to convert "x80" from ASCII-8BIT to UTF-8 for lib/mail/values/unicode_tables.dat, skipping
Installing ri documentation for mail-2.5.4
Parsing documentation for padrino-mailer-0.11.4
Installing ri documentation for padrino-mailer-0.11.4
Parsing documentation for bundler-1.3.5
Installing ri documentation for bundler-1.3.5
Parsing documentation for padrino-gen-0.11.4
unable to convert "x89" from ASCII-8BIT to UTF-8 for lib/padrino-gen/generators/project/public/favicon.ico, skipping
Installing ri documentation for padrino-gen-0.11.4
Parsing documentation for padrino-cache-0.11.4
Installing ri documentation for padrino-cache-0.11.4
Parsing documentation for padrino-admin-0.11.4
unable to convert "x89" from ASCII-8BIT to UTF-8 for lib/padrino-admin/generators/templates/assets/images/favicon.ico, skipping
unable to convert "x80" from ASCII-8BIT to UTF-8 for lib/padrino-admin/generators/templates/assets/images/font/FontAwesome.otf, skipping
unable to convert "x92" from ASCII-8BIT to UTF-8 for lib/padrino-admin/generators/templates/assets/images/font/fontawesome-webfont.eot, skipping
unable to convert "xAA" from ASCII-8BIT to UTF-8 for lib/padrino-admin/generators/templates/assets/images/font/fontawesome-webfont.woff, skipping
unable to convert "x89" from ASCII-8BIT to UTF-8 for lib/padrino-admin/generators/templates/assets/images/logo.png, skipping
Installing ri documentation for padrino-admin-0.11.4
Parsing documentation for padrino-0.11.4
Installing ri documentation for padrino-0.11.4
18 gems installed
なんか見本で書いてあるのを見て作ったんだけど
なんか間違っててエラーページが出てきて、おーアプリケーションっぽいってかんじです。
リビジョン管理がめんどくさくてDropboxにとりあえず投げてしまっているバレバレですね。
とりあえず今日はこのへんにしておいてやろう(全然わからなかった)