Your SlideShare is downloading. ×
0
SINATRA
simple way to make web application
•   ( Sixeight )

•


•


•
•Sinatra   ?

•

•

•
SINATRA   ?


Web
SINATRA         ?
• Web              DSL

• Rack   Rails

•
DSL

require ‘rubygems’
require ‘sinatra’


get ‘/hi’ do
  ‘Hello World!’
end
                     app.rb
DSL
> ruby app.rb
== Sinatra/0.9.2 has taken the stage on 4567 for development with backup from Thin
>> Thin web server (v...
RACK   RAILS

• Rails

•         Rack
RACK             RAILS

• Rails

•         Rack



                 Sinatra
• View   /

 • Haml,      Erb, Builder, Sass

• Model      / OR

 • Sequel,     DataMapper, ActiveRecord, etc
• Routes

• Template

• Configuration

• Error   handling
• Helpers
ROUTES
•get(‘/’)   { ...            ... }

•post(‘/’)    { ..,              ... }

•put(‘/’)   { ...            ... }

•de...
ROUTES
• ‘/hi‘      Route

•                                URL
    •




• HTTP                 (GET, POST, PUT, DLETE)

...
ROUTES
•                            ‘/show/:id’
    • /show/5    #=> params[:id] == 5
•                                %r|...
TEMPLATE
•

    • haml, erb, builder, sass

•                        ./views
    • set   :views, File.dirname(__FILE__) + ...
CONFIGURATION
•   set
    • set   :max_length, 15 #=> options.max_length == 15

•                       enable, disable
  ...
ERROR HANDLING

•                                    (404 Not Found)
    • not_found     { ‘404            ’}

•          ...
HELPERS
• helpers

    helpers do
      def mr(name)
        “Mr. #{name}”
      end
    end

•

    get ‘/hello/:name’ do...
• Web

 • http://www.sinatrarb.com/

• Repository

 • http://github.com/sinatra/sinatra/tree/master

• Issue   tracker
 • ...
Sinatra事始め
Sinatra事始め
Upcoming SlideShare
Loading in...5
×

Sinatra事始め

2,044

Published on

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

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

No notes for slide

Transcript of "Sinatra事始め"

  1. 1. SINATRA simple way to make web application
  2. 2. • ( Sixeight ) • • •
  3. 3. •Sinatra ? • • •
  4. 4. SINATRA ? Web
  5. 5. SINATRA ? • Web DSL • Rack Rails •
  6. 6. DSL require ‘rubygems’ require ‘sinatra’ get ‘/hi’ do ‘Hello World!’ end app.rb
  7. 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. 8. RACK RAILS • Rails • Rack
  9. 9. RACK RAILS • Rails • Rack Sinatra
  10. 10. • View / • Haml, Erb, Builder, Sass • Model / OR • Sequel, DataMapper, ActiveRecord, etc
  11. 11. • Routes • Template • Configuration • Error handling • Helpers
  12. 12. ROUTES •get(‘/’) { ... ... } •post(‘/’) { .., ... } •put(‘/’) { ... ... } •delete(‘/’) { ... ... }
  13. 13. ROUTES • ‘/hi‘ Route • URL • • HTTP (GET, POST, PUT, DLETE) • get(‘/hi’) { ... } != put(‘/hi’) { ... }
  14. 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. 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. 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. 17. ERROR HANDLING • (404 Not Found) • not_found { ‘404 ’} • error • error {‘ ’} • error(MyError) { ‘MyError : } # raise MyError • production
  18. 18. HELPERS • helpers helpers do def mr(name) “Mr. #{name}” end end • get ‘/hello/:name’ do |name| “hello, #{mr(name)}” end
  19. 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
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×