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_middleware' | |
require './config/environment' | |
use Sinatra::Application | |
run MyRailsProject::Application |
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
module MySinatra | |
class Base | |
def self.prototype | |
@prototype ||= new | |
end | |
def self.call(env) | |
prototype.call(env) | |
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' | |
helpers do | |
def assert(condition) | |
fail "something is terribly broken" unless condition | |
end | |
end | |
get '/' do | |
p env['PATH_INFO'] |
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' | |
module MySinatra | |
class Application | |
def self.call(env) | |
new.call(env) | |
end | |
def call(env) | |
headers = {'Content-Type' => 'text/html'} | |
if env['PATH_INFO'] == '/' |
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
<html> | |
<head> | |
<title>Link Helper Test</title> | |
</head> | |
<body> | |
<nav> | |
<ul> | |
<li><a href="<%= link(:index) %>">index</a></li> | |
<li><a href="<%= link(:about) %>">About</a></li> | |
<li><a href="<%= link(:random) %>">Random</a></li> |
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/post_get' | |
post_get '/' do | |
"Hi #params[:name]" | |
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/base' | |
module Sinatra | |
module PostGet | |
def post_get(route, &block) | |
get(route, &block) | |
post(route, &block) | |
end | |
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' | |
outer_self = self | |
get '/' do | |
content_type :txt | |
"outer self: #{outer_self}, inner self: #{self}" | |
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' | |
before do | |
content_type :txt | |
end | |
get '/har-har' do | |
stream do |out| | |
out << "Wanna hear a joke about potassium?\n" | |
sleep 1.5 |
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' | |
before do | |
content_type :txt | |
end | |
connections = [] | |
get '/consume' do | |
stream(:keep_open) do |out| |