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,37 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../helper'
|
2
|
+
|
3
|
+
describe "Event" do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
Sinatra::EventManager.reset!
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should return 500 if exception thrown" do
|
10
|
+
Sinatra::Environment.prepare_loggers stub_everything
|
11
|
+
|
12
|
+
event = Sinatra::Event.new(:get, '/') do
|
13
|
+
raise 'whaaaa!'
|
14
|
+
end
|
15
|
+
|
16
|
+
result = event.attend(stub_everything(:params => {}, :path_info => '/'))
|
17
|
+
|
18
|
+
result.status.should.equal 500
|
19
|
+
end
|
20
|
+
|
21
|
+
it "custom error if present" do
|
22
|
+
Sinatra::Environment.prepare_loggers stub_everything
|
23
|
+
|
24
|
+
event = Sinatra::Event.new(:get, '404') do
|
25
|
+
body 'custom 404'
|
26
|
+
end
|
27
|
+
|
28
|
+
Sinatra::EventManager.expects(:not_found).never
|
29
|
+
Sinatra::EventManager.determine_event(:get, '/sdf')
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should show default 404 if custom not present" do
|
33
|
+
Sinatra::EventManager.expects(:not_found)
|
34
|
+
Sinatra::EventManager.determine_event(:get, '/asdfsasd')
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../helper'
|
2
|
+
|
3
|
+
class Sinatra::EventContext # :nodoc:
|
4
|
+
|
5
|
+
def render_foo(template)
|
6
|
+
require 'erb'
|
7
|
+
ERB.new(template).result(binding)
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "Renderer" do
|
13
|
+
|
14
|
+
before(:each) do
|
15
|
+
Layouts.clear
|
16
|
+
@context = Sinatra::EventContext.new(stub())
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should render render a tempalate" do
|
20
|
+
@context.render('foo', :foo).should.equal 'foo'
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should render with a layout if given" do
|
24
|
+
result = @context.render('content', :foo) do
|
25
|
+
'X <%= yield %> X'
|
26
|
+
end
|
27
|
+
|
28
|
+
result.should.equal 'X content X'
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should render default layout if it exists and layout if no layout name given" do
|
32
|
+
Layouts[:layout] = 'X <%= yield %> Y'
|
33
|
+
@context.render('foo', :foo).should.equal 'X foo Y'
|
34
|
+
|
35
|
+
Layouts[:foo] = 'Foo <%= yield %> Layout'
|
36
|
+
@context.render('bar', :foo, :layout => :foo).should.equal 'Foo bar Layout'
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should read template from a file if exists" do
|
40
|
+
File.expects(:read).with('views/bar.foo').returns('foo content')
|
41
|
+
@context.render(:bar, :foo).should.equal 'foo content'
|
42
|
+
|
43
|
+
File.expects(:read).with('views2/bar.foo').returns('foo content')
|
44
|
+
@context.render(:bar, :foo, :views_directory => 'views2').should.equal 'foo content'
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../helper'
|
2
|
+
|
3
|
+
describe "Rack::Request" do
|
4
|
+
it "should return PUT and DELETE based on _method param" do
|
5
|
+
env = {'REQUEST_METHOD' => 'POST', 'rack.input' => StringIO.new('_method=DELETE')}
|
6
|
+
Rack::Request.new(env).request_method.should.equal 'DELETE'
|
7
|
+
|
8
|
+
env = {'REQUEST_METHOD' => 'POST', 'rack.input' => StringIO.new('_method=PUT')}
|
9
|
+
Rack::Request.new(env).request_method.should.equal 'PUT'
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should not allow faking" do
|
13
|
+
env = {'REQUEST_METHOD' => 'POST', 'rack.input' => StringIO.new('_method=GET')}
|
14
|
+
Rack::Request.new(env).request_method.should.equal 'POST'
|
15
|
+
|
16
|
+
env = {'REQUEST_METHOD' => 'GET', 'rack.input' => StringIO.new('_method=POST')}
|
17
|
+
Rack::Request.new(env).request_method.should.equal 'GET'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../helper'
|
2
|
+
|
3
|
+
describe "Route" do
|
4
|
+
it "gives :format for free" do
|
5
|
+
route = Sinatra::Route.new('/foo/:test/:blake')
|
6
|
+
|
7
|
+
route.recognize('/foo/bar/baz').should.equal true
|
8
|
+
route.params.should.equal :test => 'bar', :blake => 'baz', :format => 'html'
|
9
|
+
|
10
|
+
route.recognize('/foo/bar/baz.xml').should.equal true
|
11
|
+
route.params.should.equal :test => 'bar', :blake => 'baz', :format => 'xml'
|
12
|
+
end
|
13
|
+
|
14
|
+
it "doesn't auto add :format for routes with explicit formats" do
|
15
|
+
route = Sinatra::Route.new('/foo/:test.xml')
|
16
|
+
route.recognize('/foo/bar').should.equal false
|
17
|
+
route.recognize('/foo/bar.xml').should.equal true
|
18
|
+
route.params.should.equal :test => 'bar', :format => 'xml'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
You found foo!
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../helper'
|
2
|
+
require 'stringio'
|
3
|
+
|
4
|
+
context "StaticEvent" do
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
Sinatra::EventManager.reset!
|
8
|
+
end
|
9
|
+
|
10
|
+
specify "recognizes paths prefixed with it's path" do
|
11
|
+
File.expects(:exists?).with('/x/bar/test.jpg').returns(true)
|
12
|
+
Sinatra::StaticEvent.new('/foo', '/x/bar').recognize('/foo/test.jpg').should.equal true
|
13
|
+
|
14
|
+
File.expects(:exists?).with('/x/bar/test.jpg').returns(false)
|
15
|
+
Sinatra::StaticEvent.new('/foo', '/x/bar').recognize('/foo/test.jpg').should.equal false
|
16
|
+
end
|
17
|
+
|
18
|
+
specify "sets headers for file type" do
|
19
|
+
File.expects(:open).with('/x/bar/test.jpg', 'rb').returns(StringIO.new)
|
20
|
+
File.expects(:size).with('/x/bar/test.jpg').returns(255)
|
21
|
+
result = Sinatra::StaticEvent.new('/foo', '/x/bar').attend(stub(:path_info => '/foo/test.jpg'))
|
22
|
+
result.headers.should.equal 'Content-Type' => 'image/jpeg', 'Content-Length' => '255'
|
23
|
+
result.body.each { }
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
context "StaticEvent (In full context)" do
|
29
|
+
|
30
|
+
specify "should serve a static file" do
|
31
|
+
e = static '/x', root = File.dirname(__FILE__) + '/static_files'
|
32
|
+
|
33
|
+
File.read(e.physical_path_for('/x/foo.txt')).should.equal 'You found foo!'
|
34
|
+
|
35
|
+
get_it '/x/foo.txt'
|
36
|
+
|
37
|
+
status.should.equal 200
|
38
|
+
body.should.equal 'You found foo!'
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../helper'
|
2
|
+
|
3
|
+
describe "Route" do
|
4
|
+
it "should recognize params in urls" do
|
5
|
+
route = Sinatra::Route.new('/foo/:test/:blake')
|
6
|
+
|
7
|
+
route.recognize('/foo/bar/baz').should.equal true
|
8
|
+
route.params.should.equal :test => 'bar', :blake => 'baz', :format => 'html'
|
9
|
+
|
10
|
+
route.recognize('/foo/bar/baz.xml').should.equal true
|
11
|
+
route.params.should.equal :test => 'bar', :blake => 'baz', :format => 'xml'
|
12
|
+
end
|
13
|
+
|
14
|
+
# it "test" do
|
15
|
+
# p /^(\w)$|^(\w\.\w)$/.match('b').captures rescue 'NOTHING'
|
16
|
+
# end
|
17
|
+
end
|
18
|
+
|
data/vendor/erb/init.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
module Sinatra
|
2
|
+
|
3
|
+
module Erb # :nodoc:
|
4
|
+
|
5
|
+
module EventContext
|
6
|
+
|
7
|
+
# Renders raw erb in within the events context.
|
8
|
+
#
|
9
|
+
# This can be use to if you already have the template on hand and don't
|
10
|
+
# need a layout. This is speedier than using erb
|
11
|
+
#
|
12
|
+
def render_erb(content)
|
13
|
+
require 'erb'
|
14
|
+
body ERB.new(content).result(binding)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Renders erb within an event.
|
18
|
+
#
|
19
|
+
# Inline example:
|
20
|
+
#
|
21
|
+
# get '/foo' do
|
22
|
+
# erb 'The time is <%= Time.now %>'
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# Template example:
|
26
|
+
#
|
27
|
+
# get '/foo' do
|
28
|
+
# erb :foo #=> reads and renders view/foo.erb
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# For options, see Sinatra::Renderer
|
32
|
+
#
|
33
|
+
# See also: Sinatra::Renderer
|
34
|
+
def erb(template, options = {}, &layout)
|
35
|
+
render(template, :erb, options, &layout)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
data/vendor/haml/init.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
module Sinatra
|
2
|
+
|
3
|
+
module Haml # :nodoc:
|
4
|
+
|
5
|
+
module EventContext
|
6
|
+
|
7
|
+
# Renders raw haml in within the events context.
|
8
|
+
#
|
9
|
+
# This can be use to if you already have the template on hand and don't
|
10
|
+
# need a layout. This is speedier than using haml
|
11
|
+
#
|
12
|
+
def render_haml(template)
|
13
|
+
require 'haml'
|
14
|
+
body ::Haml::Engine.new(template).render(self)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Renders Haml within an event.
|
18
|
+
#
|
19
|
+
# Inline example:
|
20
|
+
#
|
21
|
+
# get '/foo' do
|
22
|
+
# haml '== The time is #{Time.now}'
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# Template example:
|
26
|
+
#
|
27
|
+
# get '/foo' do
|
28
|
+
# haml :foo #=> reads and renders view/foo.haml
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# For options, see Sinatra::Renderer
|
32
|
+
#
|
33
|
+
# See also: Sinatra::Renderer
|
34
|
+
def haml(template, options = {}, &layout)
|
35
|
+
render(template, :haml, options, &layout)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
metadata
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.4
|
3
|
+
specification_version: 1
|
4
|
+
name: sinatra
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.1.0
|
7
|
+
date: 2007-10-04 00:00:00 -07:00
|
8
|
+
summary: Sinatra is a classy web-framework dressed in a DSL
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: blake.mizerany@gmail.com
|
12
|
+
homepage: http://sinatra.rubyforge.org/
|
13
|
+
rubyforge_project: bmizerany
|
14
|
+
description: Sinatra is a classy web-framework dressed in a DSL
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- Blake Mizerany
|
31
|
+
files:
|
32
|
+
- CHANGELOG
|
33
|
+
- examples/hello/hello.rb
|
34
|
+
- examples/hello/views/hello.erb
|
35
|
+
- examples/todo/todo.rb
|
36
|
+
- files/default_index.erb
|
37
|
+
- files/error.erb
|
38
|
+
- files/logo.png
|
39
|
+
- files/not_found.erb
|
40
|
+
- lib/sinatra/context/renderer.rb
|
41
|
+
- lib/sinatra/context.rb
|
42
|
+
- lib/sinatra/core_ext/array.rb
|
43
|
+
- lib/sinatra/core_ext/class.rb
|
44
|
+
- lib/sinatra/core_ext/hash.rb
|
45
|
+
- lib/sinatra/core_ext/kernel.rb
|
46
|
+
- lib/sinatra/core_ext/metaid.rb
|
47
|
+
- lib/sinatra/core_ext/module.rb
|
48
|
+
- lib/sinatra/core_ext/symbol.rb
|
49
|
+
- lib/sinatra/dispatcher.rb
|
50
|
+
- lib/sinatra/dsl.rb
|
51
|
+
- lib/sinatra/environment.rb
|
52
|
+
- lib/sinatra/event.rb
|
53
|
+
- lib/sinatra/irb.rb
|
54
|
+
- lib/sinatra/loader.rb
|
55
|
+
- lib/sinatra/logger.rb
|
56
|
+
- lib/sinatra/options.rb
|
57
|
+
- lib/sinatra/rack_ext/request.rb
|
58
|
+
- lib/sinatra/route.rb
|
59
|
+
- lib/sinatra/server.rb
|
60
|
+
- lib/sinatra/sessions.rb
|
61
|
+
- lib/sinatra/test_methods.rb
|
62
|
+
- lib/sinatra.rb
|
63
|
+
- LICENSE
|
64
|
+
- RakeFile
|
65
|
+
- README
|
66
|
+
- sinatra.gemspec
|
67
|
+
- site/index.htm
|
68
|
+
- site/index.html
|
69
|
+
- site/logo.png
|
70
|
+
- test/helper.rb
|
71
|
+
- test/sinatra/dispatcher_test.rb
|
72
|
+
- test/sinatra/event_test.rb
|
73
|
+
- test/sinatra/renderer_test.rb
|
74
|
+
- test/sinatra/request_test.rb
|
75
|
+
- test/sinatra/route_test.rb
|
76
|
+
- test/sinatra/static_files/foo.txt
|
77
|
+
- test/sinatra/static_files_test.rb
|
78
|
+
- test/sinatra/url_test.rb
|
79
|
+
- vendor/erb/init.rb
|
80
|
+
- vendor/erb/lib/erb.rb
|
81
|
+
- vendor/haml/init.rb
|
82
|
+
- vendor/haml/lib/haml.rb
|
83
|
+
- Rakefile
|
84
|
+
- Manifest
|
85
|
+
test_files:
|
86
|
+
- test/sinatra/dispatcher_test.rb
|
87
|
+
- test/sinatra/event_test.rb
|
88
|
+
- test/sinatra/renderer_test.rb
|
89
|
+
- test/sinatra/request_test.rb
|
90
|
+
- test/sinatra/route_test.rb
|
91
|
+
- test/sinatra/static_files_test.rb
|
92
|
+
- test/sinatra/url_test.rb
|
93
|
+
rdoc_options: []
|
94
|
+
|
95
|
+
extra_rdoc_files: []
|
96
|
+
|
97
|
+
executables: []
|
98
|
+
|
99
|
+
extensions: []
|
100
|
+
|
101
|
+
requirements: []
|
102
|
+
|
103
|
+
dependencies:
|
104
|
+
- !ruby/object:Gem::Dependency
|
105
|
+
name: mongrel
|
106
|
+
version_requirement:
|
107
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: 1.0.1
|
112
|
+
version:
|
113
|
+
- !ruby/object:Gem::Dependency
|
114
|
+
name: rack
|
115
|
+
version_requirement:
|
116
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: 0.2.0
|
121
|
+
version:
|