sinatra 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of sinatra might be problematic. Click here for more details.
- data/CHANGELOG +1 -0
- data/LICENSE +22 -0
- data/Manifest +53 -0
- data/README +99 -0
- data/RakeFile +36 -0
- data/Rakefile +36 -0
- data/examples/hello/hello.rb +30 -0
- data/examples/hello/views/hello.erb +1 -0
- data/examples/todo/todo.rb +38 -0
- data/files/default_index.erb +42 -0
- data/files/error.erb +9 -0
- data/files/logo.png +0 -0
- data/files/not_found.erb +52 -0
- data/lib/sinatra.rb +47 -0
- data/lib/sinatra/context.rb +88 -0
- data/lib/sinatra/context/renderer.rb +75 -0
- data/lib/sinatra/core_ext/array.rb +5 -0
- data/lib/sinatra/core_ext/class.rb +49 -0
- data/lib/sinatra/core_ext/hash.rb +7 -0
- data/lib/sinatra/core_ext/kernel.rb +16 -0
- data/lib/sinatra/core_ext/metaid.rb +18 -0
- data/lib/sinatra/core_ext/module.rb +11 -0
- data/lib/sinatra/core_ext/symbol.rb +5 -0
- data/lib/sinatra/dispatcher.rb +27 -0
- data/lib/sinatra/dsl.rb +163 -0
- data/lib/sinatra/environment.rb +15 -0
- data/lib/sinatra/event.rb +184 -0
- data/lib/sinatra/irb.rb +55 -0
- data/lib/sinatra/loader.rb +31 -0
- data/lib/sinatra/logger.rb +22 -0
- data/lib/sinatra/options.rb +43 -0
- data/lib/sinatra/rack_ext/request.rb +15 -0
- data/lib/sinatra/route.rb +65 -0
- data/lib/sinatra/server.rb +54 -0
- data/lib/sinatra/sessions.rb +21 -0
- data/lib/sinatra/test_methods.rb +55 -0
- data/sinatra.gemspec +60 -0
- data/site/index.htm +100 -0
- data/site/index.html +100 -0
- data/site/logo.png +0 -0
- data/test/helper.rb +17 -0
- data/test/sinatra/dispatcher_test.rb +91 -0
- data/test/sinatra/event_test.rb +37 -0
- data/test/sinatra/renderer_test.rb +47 -0
- data/test/sinatra/request_test.rb +21 -0
- data/test/sinatra/route_test.rb +21 -0
- data/test/sinatra/static_files/foo.txt +1 -0
- data/test/sinatra/static_files_test.rb +41 -0
- data/test/sinatra/url_test.rb +18 -0
- data/vendor/erb/init.rb +3 -0
- data/vendor/erb/lib/erb.rb +41 -0
- data/vendor/haml/init.rb +3 -0
- data/vendor/haml/lib/haml.rb +41 -0
- metadata +121 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
module Sinatra
|
2
|
+
module Session
|
3
|
+
class Cookie
|
4
|
+
def self.use=(v)
|
5
|
+
@@use = v unless Sinatra::Server.running # keep is thread-safe!
|
6
|
+
end
|
7
|
+
|
8
|
+
def initialize(app, options = {})
|
9
|
+
@app = if (@@use ||= :on) == :off
|
10
|
+
app
|
11
|
+
else
|
12
|
+
Rack::Session::Cookie.new(app)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(env)
|
17
|
+
@app.call(env)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
3
|
+
module Sinatra
|
4
|
+
|
5
|
+
# These methods are for integration testing without an internet connection. They are available in Test::Unit::TestCase and when in Irb.
|
6
|
+
|
7
|
+
module TestMethods
|
8
|
+
|
9
|
+
# get_it, post_it, put_it, delete_it
|
10
|
+
# Executes the method and returns the result of the body
|
11
|
+
#
|
12
|
+
# options:
|
13
|
+
# +:params+ a hash of name parameters
|
14
|
+
#
|
15
|
+
# Example:
|
16
|
+
# get_it '/', :name => 'Blake' # => 'Hello Blake!'
|
17
|
+
#
|
18
|
+
%w(get post put delete).each do |verb|
|
19
|
+
module_eval <<-end_eval
|
20
|
+
def #{verb}_it(path, params = {})
|
21
|
+
request = Rack::MockRequest.new(Sinatra::Dispatcher.new)
|
22
|
+
@response = request.#{verb} path, :input => generate_input(params)
|
23
|
+
body
|
24
|
+
end
|
25
|
+
end_eval
|
26
|
+
end
|
27
|
+
|
28
|
+
def response
|
29
|
+
@response || Rack::MockResponse.new(404, {}, '')
|
30
|
+
end
|
31
|
+
|
32
|
+
def status
|
33
|
+
response.status
|
34
|
+
end
|
35
|
+
|
36
|
+
def text
|
37
|
+
response.body
|
38
|
+
end
|
39
|
+
alias :xml :text
|
40
|
+
alias :html :text
|
41
|
+
alias :body :text
|
42
|
+
|
43
|
+
def headers
|
44
|
+
response.headers
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def generate_input(params)
|
50
|
+
params.map { |k,v| "#{k}=#{URI.escape(v)}" }.join('&')
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
data/sinatra.gemspec
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
|
2
|
+
# Gem::Specification for Sinatra-0.1.0
|
3
|
+
# Originally generated by Echoe
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = %q{sinatra}
|
7
|
+
s.version = "0.1.0"
|
8
|
+
s.date = %q{2007-10-04}
|
9
|
+
s.summary = %q{Sinatra is a classy web-framework dressed in a DSL}
|
10
|
+
s.email = %q{blake.mizerany@gmail.com}
|
11
|
+
s.homepage = %q{http://sinatra.rubyforge.org/}
|
12
|
+
s.rubyforge_project = %q{bmizerany}
|
13
|
+
s.description = %q{Sinatra is a classy web-framework dressed in a DSL}
|
14
|
+
s.has_rdoc = true
|
15
|
+
s.authors = ["Blake Mizerany"]
|
16
|
+
s.files = ["CHANGELOG", "examples/hello/hello.rb", "examples/hello/views/hello.erb", "examples/todo/todo.rb", "files/default_index.erb", "files/error.erb", "files/logo.png", "files/not_found.erb", "lib/sinatra/context/renderer.rb", "lib/sinatra/context.rb", "lib/sinatra/core_ext/array.rb", "lib/sinatra/core_ext/class.rb", "lib/sinatra/core_ext/hash.rb", "lib/sinatra/core_ext/kernel.rb", "lib/sinatra/core_ext/metaid.rb", "lib/sinatra/core_ext/module.rb", "lib/sinatra/core_ext/symbol.rb", "lib/sinatra/dispatcher.rb", "lib/sinatra/dsl.rb", "lib/sinatra/environment.rb", "lib/sinatra/event.rb", "lib/sinatra/irb.rb", "lib/sinatra/loader.rb", "lib/sinatra/logger.rb", "lib/sinatra/options.rb", "lib/sinatra/rack_ext/request.rb", "lib/sinatra/route.rb", "lib/sinatra/server.rb", "lib/sinatra/sessions.rb", "lib/sinatra/test_methods.rb", "lib/sinatra.rb", "LICENSE", "RakeFile", "README", "sinatra.gemspec", "site/index.htm", "site/index.html", "site/logo.png", "test/helper.rb", "test/sinatra/dispatcher_test.rb", "test/sinatra/event_test.rb", "test/sinatra/renderer_test.rb", "test/sinatra/request_test.rb", "test/sinatra/route_test.rb", "test/sinatra/static_files/foo.txt", "test/sinatra/static_files_test.rb", "test/sinatra/url_test.rb", "vendor/erb/init.rb", "vendor/erb/lib/erb.rb", "vendor/haml/init.rb", "vendor/haml/lib/haml.rb", "Rakefile", "Manifest"]
|
17
|
+
s.test_files = ["test/sinatra/dispatcher_test.rb", "test/sinatra/event_test.rb", "test/sinatra/renderer_test.rb", "test/sinatra/request_test.rb", "test/sinatra/route_test.rb", "test/sinatra/static_files_test.rb", "test/sinatra/url_test.rb"]
|
18
|
+
s.add_dependency(%q<mongrel>, [">= 1.0.1"])
|
19
|
+
s.add_dependency(%q<rack>, [">= 0.2.0"])
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
# # Original Rakefile source (requires the Echoe gem):
|
24
|
+
#
|
25
|
+
# require 'rake/testtask'
|
26
|
+
# require 'ftools'
|
27
|
+
# require 'hoe'
|
28
|
+
#
|
29
|
+
# Version = '0.1.0'
|
30
|
+
#
|
31
|
+
# begin
|
32
|
+
# require 'rubygems'
|
33
|
+
# gem 'echoe'
|
34
|
+
# ENV['RUBY_FLAGS'] = ""
|
35
|
+
# require 'echoe'
|
36
|
+
#
|
37
|
+
# Echoe.new('sinatra') do |p|
|
38
|
+
# p.rubyforge_name = 'bmizerany'
|
39
|
+
# p.dependencies = ['mongrel >=1.0.1', 'rack >=0.2.0']
|
40
|
+
# p.summary = "Sinatra is a classy web-framework dressed in a DSL"
|
41
|
+
# p.description = "Sinatra is a classy web-framework dressed in a DSL"
|
42
|
+
# p.url = "http://sinatra.rubyforge.org/"
|
43
|
+
# p.author = 'Blake Mizerany'
|
44
|
+
# p.email = "blake.mizerany@gmail.com"
|
45
|
+
# p.test_pattern = 'test/**/*_test.rb'
|
46
|
+
# p.include_rakefile = true
|
47
|
+
# p.rdoc_pattern = ['README', 'LICENSE'] << Dir.glob('lib/**/*.rb') << Dir.glob('vendor/**/*.rb')
|
48
|
+
# p.docs_host = "bmizerany@rubyforge.org:/var/www/gforge-projects/sinatra/"
|
49
|
+
# end
|
50
|
+
#
|
51
|
+
# rescue LoadError
|
52
|
+
# end
|
53
|
+
#
|
54
|
+
# desc 'Clear all the log files from here down'
|
55
|
+
# task :remove_logs do
|
56
|
+
# Dir.glob(Dir.pwd + '/**/*.log') do |logfile|
|
57
|
+
# FileUtils.rm(logfile)
|
58
|
+
# puts 'Removed: %s' % logfile
|
59
|
+
# end
|
60
|
+
# end
|
data/site/index.htm
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
3
|
+
|
4
|
+
<html>
|
5
|
+
<head>
|
6
|
+
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
|
7
|
+
<title>Sinatra : Classy web-development dressed in a DSL</title>
|
8
|
+
</head>
|
9
|
+
|
10
|
+
<body>
|
11
|
+
<style type="text/css" media="screen">
|
12
|
+
body {
|
13
|
+
background-color: #fff;
|
14
|
+
color: #333;
|
15
|
+
font-size: 0.75em;
|
16
|
+
}
|
17
|
+
|
18
|
+
#container {
|
19
|
+
width: 600px;
|
20
|
+
margin: 0 auto;
|
21
|
+
font-size: 1.5em;
|
22
|
+
}
|
23
|
+
|
24
|
+
#container pre {
|
25
|
+
font-size: .8em;
|
26
|
+
background-color: #F5F6C9;
|
27
|
+
width: 100%;
|
28
|
+
}
|
29
|
+
|
30
|
+
#container note {
|
31
|
+
font-size: .7em;
|
32
|
+
}
|
33
|
+
|
34
|
+
#banner {
|
35
|
+
width: 600px;
|
36
|
+
text-align: center;
|
37
|
+
}
|
38
|
+
|
39
|
+
pre {
|
40
|
+
padding: 10px;
|
41
|
+
}
|
42
|
+
|
43
|
+
.clear {
|
44
|
+
clear: both;
|
45
|
+
}
|
46
|
+
</style>
|
47
|
+
|
48
|
+
<div id="container">
|
49
|
+
<div id="banner">
|
50
|
+
<img src='logo.png' />
|
51
|
+
<h2><em>Classy web-development dressed in a DSL</em></h2>
|
52
|
+
</div>
|
53
|
+
<div class="clear"></div>
|
54
|
+
<div>
|
55
|
+
<div>
|
56
|
+
<p>
|
57
|
+
<strong>Install!</strong><br/>
|
58
|
+
<pre>gem install sinatra -y</pre>
|
59
|
+
</p>
|
60
|
+
<p>
|
61
|
+
<strong>Require!</strong> (any filename you wish)<br/>
|
62
|
+
<pre>
|
63
|
+
# lyrics.rb
|
64
|
+
require 'rubygems'
|
65
|
+
require 'sinatra'</pre>
|
66
|
+
<note>yup.. that's it for a sec</note><br />
|
67
|
+
</p>
|
68
|
+
<p>
|
69
|
+
<strong>Run!</strong><br />
|
70
|
+
<pre>ruby lyrics.rb</pre>
|
71
|
+
</p>
|
72
|
+
<p>
|
73
|
+
<strong>Bask!</strong><br />
|
74
|
+
<pre>http://localhost:4567</pre>
|
75
|
+
</p>
|
76
|
+
<p>
|
77
|
+
<strong>Write!</strong>
|
78
|
+
<pre>
|
79
|
+
get '/' do
|
80
|
+
"Now that's a fine looking dame!"
|
81
|
+
end</pre>
|
82
|
+
</p>
|
83
|
+
<p>
|
84
|
+
<strong>Examples!</strong><br />
|
85
|
+
<pre><a href="http://repo.or.cz/w/sinatra.git?a=tree;f=examples;h=fd7513e49762738ad945adbb2e15bb31528b4207;hb=HEAD">here</a></pre>
|
86
|
+
</p>
|
87
|
+
<p>
|
88
|
+
<strong>Contribute!</strong><br />
|
89
|
+
<pre><a href="http://repo.or.cz/w/sinatra.git">using git</a></pre>
|
90
|
+
</p>
|
91
|
+
<p>
|
92
|
+
<strong>Docs!</strong><br />
|
93
|
+
<pre><a href="http://sinatra.rubyforge.org/doc/">here</a></pre>
|
94
|
+
</p>
|
95
|
+
|
96
|
+
</div>
|
97
|
+
</div>
|
98
|
+
</div>
|
99
|
+
</body>
|
100
|
+
</html>
|
data/site/index.html
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
3
|
+
|
4
|
+
<html>
|
5
|
+
<head>
|
6
|
+
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
|
7
|
+
<title>Sinatra : Classy web-development dressed in a DSL</title>
|
8
|
+
</head>
|
9
|
+
|
10
|
+
<body>
|
11
|
+
<style type="text/css" media="screen">
|
12
|
+
body {
|
13
|
+
background-color: #fff;
|
14
|
+
color: #333;
|
15
|
+
font-size: 0.75em;
|
16
|
+
}
|
17
|
+
|
18
|
+
#container {
|
19
|
+
width: 600px;
|
20
|
+
margin: 0 auto;
|
21
|
+
font-size: 1.5em;
|
22
|
+
}
|
23
|
+
|
24
|
+
#container pre {
|
25
|
+
font-size: .8em;
|
26
|
+
background-color: #F5F6C9;
|
27
|
+
width: 100%;
|
28
|
+
}
|
29
|
+
|
30
|
+
#container note {
|
31
|
+
font-size: .7em;
|
32
|
+
}
|
33
|
+
|
34
|
+
#banner {
|
35
|
+
width: 600px;
|
36
|
+
text-align: center;
|
37
|
+
}
|
38
|
+
|
39
|
+
pre {
|
40
|
+
padding: 10px;
|
41
|
+
}
|
42
|
+
|
43
|
+
.clear {
|
44
|
+
clear: both;
|
45
|
+
}
|
46
|
+
</style>
|
47
|
+
|
48
|
+
<div id="container">
|
49
|
+
<div id="banner">
|
50
|
+
<img src='logo.png' />
|
51
|
+
<h2><em>Classy web-development dressed in a DSL</em></h2>
|
52
|
+
</div>
|
53
|
+
<div class="clear"></div>
|
54
|
+
<div>
|
55
|
+
<div>
|
56
|
+
<p>
|
57
|
+
<strong>Install!</strong><br/>
|
58
|
+
<pre>gem install sinatra -y</pre>
|
59
|
+
</p>
|
60
|
+
<p>
|
61
|
+
<strong>Require!</strong> (any filename you wish)<br/>
|
62
|
+
<pre>
|
63
|
+
# lyrics.rb
|
64
|
+
require 'rubygems'
|
65
|
+
require 'sinatra'</pre>
|
66
|
+
<note>yup.. that's it for a sec</note><br />
|
67
|
+
</p>
|
68
|
+
<p>
|
69
|
+
<strong>Run!</strong><br />
|
70
|
+
<pre>ruby lyrics.rb</pre>
|
71
|
+
</p>
|
72
|
+
<p>
|
73
|
+
<strong>Bask!</strong><br />
|
74
|
+
<pre>http://localhost:4567</pre>
|
75
|
+
</p>
|
76
|
+
<p>
|
77
|
+
<strong>Write!</strong>
|
78
|
+
<pre>
|
79
|
+
get '/' do
|
80
|
+
"Now that's a fine looking dame!"
|
81
|
+
end</pre>
|
82
|
+
</p>
|
83
|
+
<p>
|
84
|
+
<strong>Examples!</strong><br />
|
85
|
+
<pre><a href="http://repo.or.cz/w/sinatra.git?a=tree;f=examples;h=fd7513e49762738ad945adbb2e15bb31528b4207;hb=HEAD">here</a></pre>
|
86
|
+
</p>
|
87
|
+
<p>
|
88
|
+
<strong>Contribute!</strong><br />
|
89
|
+
<pre><a href="http://repo.or.cz/w/sinatra.git">using git</a></pre>
|
90
|
+
</p>
|
91
|
+
<p>
|
92
|
+
<strong>Docs!</strong><br />
|
93
|
+
<pre><a href="http://sinatra.rubyforge.org/doc/">here</a></pre>
|
94
|
+
</p>
|
95
|
+
|
96
|
+
</div>
|
97
|
+
</div>
|
98
|
+
</div>
|
99
|
+
</body>
|
100
|
+
</html>
|
data/site/logo.png
ADDED
Binary file
|
data/test/helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../lib/sinatra'
|
2
|
+
|
3
|
+
%w(mocha test/spec).each do |library|
|
4
|
+
begin
|
5
|
+
require library
|
6
|
+
rescue
|
7
|
+
STDERR.puts "== Sinatra's tests need #{library} to run."
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
Sinatra::Server.running = true
|
12
|
+
Sinatra::Options.set_environment :test
|
13
|
+
Sinatra::Environment.prepare_loggers
|
14
|
+
|
15
|
+
class Test::Unit::TestCase
|
16
|
+
include Sinatra::TestMethods
|
17
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../helper'
|
2
|
+
|
3
|
+
describe "When a dispatcher receives a request" do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
Sinatra::EventManager.reset!
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should attend to the event" do
|
10
|
+
|
11
|
+
Sinatra::Event.new(:get, '/') do
|
12
|
+
body 'this is the index as a get'
|
13
|
+
end
|
14
|
+
|
15
|
+
get_it "/"
|
16
|
+
|
17
|
+
status.should.equal 200
|
18
|
+
text.should.equal 'this is the index as a get'
|
19
|
+
headers['Content-Type'].should.equal 'text/html'
|
20
|
+
|
21
|
+
post_it "/"
|
22
|
+
|
23
|
+
status.should.equal 404
|
24
|
+
text.scan("Not Found :: Sinatra").size.should.equal 1
|
25
|
+
headers['Content-Type'].should.equal 'text/html'
|
26
|
+
|
27
|
+
get_it '/foo'
|
28
|
+
|
29
|
+
status.should.equal 404
|
30
|
+
text.scan("Not Found :: Sinatra").size.should.equal 1
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should use custom error pages if present" do
|
35
|
+
Sinatra::Event.new(:get, 404) do
|
36
|
+
body 'custom 404'
|
37
|
+
end
|
38
|
+
|
39
|
+
get_it('/laksdjf').should.equal 'custom 404'
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should reload app files unless in production" do
|
43
|
+
Sinatra::Event.new(:get, '/') {}
|
44
|
+
|
45
|
+
Sinatra::Options.expects(:environment).returns(:production)
|
46
|
+
Sinatra::Loader.expects(:reload!).never
|
47
|
+
get_it '/'
|
48
|
+
|
49
|
+
Sinatra::Options.expects(:environment).returns(:development)
|
50
|
+
Sinatra::Loader.expects(:reload!)
|
51
|
+
get_it '/'
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should not register not_found (otherwise we'll have a newone in the array for every error)" do
|
55
|
+
Sinatra::EventManager.events.size.should.equal 0
|
56
|
+
get_it '/blake'
|
57
|
+
Sinatra::EventManager.events.size.should.equal 0
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should return blocks result if body not called" do
|
61
|
+
event = Sinatra::Event.new(:get, '/return_block') do
|
62
|
+
'no body called'
|
63
|
+
end
|
64
|
+
|
65
|
+
get_it '/return_block'
|
66
|
+
|
67
|
+
status.should.equal 200
|
68
|
+
html.should.equal 'no body called'
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should recognize pretty urls" do
|
72
|
+
Sinatra::Event.new(:get, '/test/:name') do
|
73
|
+
params[:name]
|
74
|
+
end
|
75
|
+
|
76
|
+
get_it '/test/blake'
|
77
|
+
body.should.equal 'blake'
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should respond to DELETE and PUT" do
|
81
|
+
Sinatra::Event.new(:delete, '/') do
|
82
|
+
request.request_method
|
83
|
+
end
|
84
|
+
|
85
|
+
# Browser only know GET and POST. DELETE and PUT are signaled by passing in a _method paramater
|
86
|
+
post_it '/', :_method => 'DELETE'
|
87
|
+
status.should.equal 200
|
88
|
+
text.should.equal 'DELETE'
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|