Your SlideShare is downloading. ×
Sinatra事始め
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Sinatra事始め

1,982
views

Published on

Published in: Technology

0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,982
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
16
Comments
0
Likes
3
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. SINATRA simple way to make web application
  • 2. • ( Sixeight ) • • •
  • 3. •Sinatra ? • • •
  • 4. SINATRA ? Web
  • 5. SINATRA ? • Web DSL • Rack Rails •
  • 6. DSL require ‘rubygems’ require ‘sinatra’ get ‘/hi’ do ‘Hello World!’ end app.rb
  • 7. DSL > ruby app.rb == Sinatra/0.9.2 has taken the stage on 4567 for development with backup from Thin >> Thin web server (v1.2.2 codename I Find Your Lack of Sauce Disturbing) >> Maximum connections set to 1024 >> Listening on 0.0.0.0:4567, CTRL+C to stop
  • 8. RACK RAILS • Rails • Rack
  • 9. RACK RAILS • Rails • Rack Sinatra
  • 10. • View / • Haml, Erb, Builder, Sass • Model / OR • Sequel, DataMapper, ActiveRecord, etc
  • 11. • Routes • Template • Configuration • Error handling • Helpers
  • 12. ROUTES •get(‘/’) { ... ... } •post(‘/’) { .., ... } •put(‘/’) { ... ... } •delete(‘/’) { ... ... }
  • 13. ROUTES • ‘/hi‘ Route • URL • • HTTP (GET, POST, PUT, DLETE) • get(‘/hi’) { ... } != put(‘/hi’) { ... }
  • 14. ROUTES • ‘/show/:id’ • /show/5 #=> params[:id] == 5 • %r|/hello/(w{3})| • /hello/tomohiro #=> params[:captures][0] == ‘tom’ • • get '/foo', :agent => /Songbird (d.d)[d/]*?/
  • 15. TEMPLATE • • haml, erb, builder, sass • ./views • set :views, File.dirname(__FILE__) + '/templates' • ./views/layout.[type] • e.g.) ./views/layout.haml • haml :index, :layout => false #=>
  • 16. CONFIGURATION • set • set :max_length, 15 #=> options.max_length == 15 • enable, disable • enable :sessions #=> options.sessions == true • (development, product, test) • configure(:production) { enable :log }
  • 17. ERROR HANDLING • (404 Not Found) • not_found { ‘404 ’} • error • error {‘ ’} • error(MyError) { ‘MyError : } # raise MyError • production
  • 18. HELPERS • helpers helpers do def mr(name) “Mr. #{name}” end end • get ‘/hello/:name’ do |name| “hello, #{mr(name)}” end
  • 19. • Web • http://www.sinatrarb.com/ • Repository • http://github.com/sinatra/sinatra/tree/master • Issue tracker • https://sinatra.lighthouseapp.com/projects/9779-sinatra • Mailing List • http://groups.google.com/group/sinatrarb