Skip to content

Instantly share code, notes, and snippets.

on :receive do
pass! unless request.method? 'GET', 'HEAD'
pass! if request.header? 'Authorization', 'Expect'
lookup!
end
# sinatra/base does not modify anything outside of the Sinatra module.
require 'sinatra/base'
# Sinatra::Base subclasses run in isolation.
class Foo < Sinatra::Base
# options:
enable :static, :session
set :root, File.dirname(__FILE__)
set :custom_option, 'hello'
01:27 blakemizerany: you can ssh into your face and `su - hermes` then `rake tail`
01:27 rtomayko: "ssh into your face"?!
01:27 rtomayko: that would be awesome.
Let's make a list of Sinatra-based apps!
Apps:
- http://github.com/cschneid/irclogger "Sinatra based irclogger.com"
- http://github.com/rtomayko/wink "minimalist blogging engine"
- http://github.com/foca/integrity "The easy and fun Continuous Integration server"
- http://github.com/sr/git-wiki "git-powered wiki"
- http://github.com/entp/seinfeld "Seinfeld-inspired productivity calendar to track your public github commits."
- http://github.com/karmi/marley "Marley, the blog engine without <textareas>."
- http://github.com/ichverstehe/gaze "Serve up your Markdown files with this tiny Sinatra app!"
require 'benchmark'
class Memoized
def self.new(env)
env['foo.bar'] ||= super
end
def initialize(env)
@env = env
end
end
# thin looks for a class named like the file with: thin --rackup foo.rb start
# yet another interesting way of using the class based stuff on the hoboken branch...
require 'sinatra'
class Foo < Sinatra::Base
get '/foo' do
"Hello World!"
end
end
# Sinatra: multiple route patterns / same action
['/foo', '/bar'].each do |pattern|
get pattern do
"Hello World!"
end
end
require 'sinatra'
require 'sinatra/test/rspec'
require File.join(File.dirname(__FILE__), '../../server.rb')
Dir.chdir('../../')
describe 'Game logic' do
it 'should be able to play in 0,0' do
get '/new'
require 'rubygems'
require 'sinatra/base'
class App < Sinatra::Base
enable :static
set :app_file, __FILE__
get '/' do
'See <a href="/thing.txt">this text file</a>.'
end
def run(app, &blk)
app = app.new(&blk) if blk && app.respond_to?(:new)
@ins << app
end