This file contains hidden or 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 hidden or 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 hidden or 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 'compass' | |
require 'ostruct' | |
enable :static, :logging | |
set :views, "#{root}/app/views" | |
set :haml, :format => :html4, :attr_wrapper => '"' | |
set :sass, :style => :compact |
This file contains hidden or 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 CachePolicy < Sinatra::Base | |
# always forward the request downstream immediately (before processing routes) | |
before { forward } | |
# anything with a cache breaking timestamp gets an insanely long max-age | |
get '/public/*' do | |
pass unless request.query_string =~ /^\d+$/ | |
response['Cache-Control'] = 'public, max-age=1000000000' | |
end |
This file contains hidden or 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
Warden::Manager.serialize_into_session{|user| user.id } | |
Warden::Manager.serialize_from_session{|id| User.get(id) } | |
Warden::Manager.before_failure do |env,opts| | |
# Sinatra is very sensitive to the request method | |
# since authentication could fail on any type of method, we need | |
# to set it for the failure app so it is routed to the correct block | |
env['REQUEST_METHOD'] = "POST" | |
end | |
This file contains hidden or 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
# The code in lib/foobar.rb | |
require 'sinatra/base' | |
class Foobar < Sinatra::Base | |
VERSION = '1.0.0' | |
configure do | |
set :foobar, environment | |
end | |
end | |
# The tests in test/test_foobar.rb |
This file contains hidden or 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
# ~rtomayko/.screenrc | |
# ------------------------------------------------------------------- | |
# Settings | |
# ------------------------------------------------------------------- | |
crlf off # No Microsoft linebreaks | |
startup_message off # bypass GPL notice (we're aware) | |
defscrollback 15000 # big scrollback | |
shell bash # don't start login shells | |
shelltitle "" # no title by default - set in PS1 |
This file contains hidden or 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
Warden::Manager.serialize_into_session{|user| user.id } | |
Warden::Manager.serialize_from_session{|id| User.get(id) } | |
Warden::Manager.before_failure do |env,opts| | |
# Sinatra is very sensitive to the request method | |
# since authentication could fail on any type of method, we need | |
# to set it for the failure app so it is routed to the correct block | |
env['REQUEST_METHOD'] = "POST" | |
end | |
This file contains hidden or 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 'bcrypt' | |
module EasyAuth | |
# http://techspeak.plainlystated.com/2010/03/drop-dead-simple-authentication-for.html | |
# To generate a crypted password (in irb): | |
# require 'easy_auth' | |
# EasyAuth.encrypt_password('my_password') # Put returned array in AUTHORIZED_USERS | |
AUTHORIZED_USERS = { |
This file contains hidden or 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
# Author: Pieter Noordhuis | |
# Description: Simple demo to showcase Redis PubSub with EventMachine | |
# | |
# Update 7 Oct 2010: | |
# - This example does *not* appear to work with Chrome >=6.0. Apparently, | |
# the WebSocket protocol implementation in the cramp gem does not work | |
# well with Chrome's (newer) WebSocket implementation. | |
# | |
# Requirements: | |
# - rubygems: eventmachine, thin, cramp, sinatra, yajl-ruby |
OlderNewer