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' | |
get '/' do | |
response.set_cookie "sushi", "tenpura"#argument 2 | |
"Cookie set. Would like to <a href='/read'>read it.</a>?" | |
end | |
get '/read' do | |
"Cookie has a value of:#{request.cookies['sushi']}." | |
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 '/attachment' do | |
attachment 'name_your_konishiki.txt' | |
"Here's what will be sent downstream, in an attachment called 'name_your_konishiki.txt.'" | |
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 | |
connections = [] | |
get '/consume' do | |
stream(:keep_open) do |out| |
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' | |
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/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' | |
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
<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' | |
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
require 'sinatra' | |
helpers do | |
def assert(condition) | |
fail "something is terribly broken" unless condition | |
end | |
end | |
get '/' do | |
p env['PATH_INFO'] |
OlderNewer