This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# generate sinatra app | |
mkdir -p $1/views $1/public | |
cat <<RUBY > $1/app.rb | |
#!/usr/bin/env ruby | |
require 'sinatra' | |
set :views, File.dirname(__FILE__) + '/views' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class App1 < Sinatra::Base | |
set :views, "/path/to/views" | |
set :public, "/path/to/static/files" | |
def strong(text) | |
"<strong>#{text}</strong>" | |
end | |
get '/' do | |
strong "Hello World" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on :receive do | |
pass! unless request.method? 'GET', 'HEAD' | |
pass! if request.header? 'Authorization', 'Expect' | |
lookup! | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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' | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
class Memoized | |
def self.new(env) | |
env['foo.bar'] ||= super | |
end | |
def initialize(env) | |
@env = env | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Sinatra: multiple route patterns / same action | |
['/foo', '/bar'].each do |pattern| | |
get pattern do | |
"Hello World!" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |