sinatra-sinatra 0.8.9
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +40 -0
- data/CHANGES +174 -0
- data/LICENSE +22 -0
- data/README.rdoc +545 -0
- data/Rakefile +180 -0
- data/compat/app_test.rb +300 -0
- data/compat/application_test.rb +334 -0
- data/compat/builder_test.rb +101 -0
- data/compat/custom_error_test.rb +62 -0
- data/compat/erb_test.rb +136 -0
- data/compat/events_test.rb +78 -0
- data/compat/filter_test.rb +30 -0
- data/compat/haml_test.rb +233 -0
- data/compat/helper.rb +30 -0
- data/compat/mapped_error_test.rb +72 -0
- data/compat/pipeline_test.rb +71 -0
- data/compat/public/foo.xml +1 -0
- data/compat/sass_test.rb +57 -0
- data/compat/sessions_test.rb +39 -0
- data/compat/streaming_test.rb +121 -0
- data/compat/sym_params_test.rb +19 -0
- data/compat/template_test.rb +30 -0
- data/compat/use_in_file_templates_test.rb +47 -0
- data/compat/views/foo.builder +1 -0
- data/compat/views/foo.erb +1 -0
- data/compat/views/foo.haml +1 -0
- data/compat/views/foo.sass +2 -0
- data/compat/views/foo_layout.erb +2 -0
- data/compat/views/foo_layout.haml +2 -0
- data/compat/views/layout_test/foo.builder +1 -0
- data/compat/views/layout_test/foo.erb +1 -0
- data/compat/views/layout_test/foo.haml +1 -0
- data/compat/views/layout_test/foo.sass +2 -0
- data/compat/views/layout_test/layout.builder +3 -0
- data/compat/views/layout_test/layout.erb +1 -0
- data/compat/views/layout_test/layout.haml +1 -0
- data/compat/views/layout_test/layout.sass +2 -0
- data/compat/views/no_layout/no_layout.builder +1 -0
- data/compat/views/no_layout/no_layout.haml +1 -0
- data/lib/sinatra/base.rb +818 -0
- data/lib/sinatra/compat.rb +239 -0
- data/lib/sinatra/images/404.png +0 -0
- data/lib/sinatra/images/500.png +0 -0
- data/lib/sinatra/main.rb +48 -0
- data/lib/sinatra/test/bacon.rb +17 -0
- data/lib/sinatra/test/rspec.rb +9 -0
- data/lib/sinatra/test/spec.rb +9 -0
- data/lib/sinatra/test/unit.rb +11 -0
- data/lib/sinatra/test.rb +109 -0
- data/lib/sinatra.rb +4 -0
- data/sinatra.gemspec +109 -0
- data/test/base_test.rb +68 -0
- data/test/builder_test.rb +64 -0
- data/test/data/reload_app_file.rb +3 -0
- data/test/erb_test.rb +50 -0
- data/test/filter_test.rb +35 -0
- data/test/haml_test.rb +68 -0
- data/test/helper.rb +20 -0
- data/test/helpers_test.rb +361 -0
- data/test/mapped_error_test.rb +160 -0
- data/test/middleware_test.rb +58 -0
- data/test/options_test.rb +97 -0
- data/test/reload_test.rb +61 -0
- data/test/request_test.rb +9 -0
- data/test/result_test.rb +88 -0
- data/test/routing_test.rb +334 -0
- data/test/sass_test.rb +36 -0
- data/test/sinatra_test.rb +13 -0
- data/test/static_test.rb +57 -0
- data/test/templates_test.rb +88 -0
- data/test/views/hello.builder +1 -0
- data/test/views/hello.erb +1 -0
- data/test/views/hello.haml +1 -0
- data/test/views/hello.sass +2 -0
- data/test/views/hello.test +1 -0
- data/test/views/layout2.builder +3 -0
- data/test/views/layout2.erb +2 -0
- data/test/views/layout2.haml +2 -0
- data/test/views/layout2.test +1 -0
- metadata +161 -0
data/test/static_test.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
describe 'Static' do
|
4
|
+
F = ::File
|
5
|
+
|
6
|
+
before do
|
7
|
+
mock_app {
|
8
|
+
set :static, true
|
9
|
+
set :public, F.dirname(__FILE__)
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'serves GET requests for files in the public directory' do
|
14
|
+
get "/#{F.basename(__FILE__)}"
|
15
|
+
assert ok?
|
16
|
+
assert_equal File.read(__FILE__), body
|
17
|
+
assert_equal File.size(__FILE__).to_s, response['Content-Length']
|
18
|
+
assert response.headers.include?('Last-Modified')
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'serves HEAD requests for files in the public directory' do
|
22
|
+
head "/#{F.basename(__FILE__)}"
|
23
|
+
assert ok?
|
24
|
+
assert_equal '', body
|
25
|
+
assert_equal File.size(__FILE__).to_s, response['Content-Length']
|
26
|
+
assert response.headers.include?('Last-Modified')
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'serves files in preference to custom routes' do
|
30
|
+
@app.get("/#{F.basename(__FILE__)}") { 'Hello World' }
|
31
|
+
get "/#{F.basename(__FILE__)}"
|
32
|
+
assert ok?
|
33
|
+
assert body != 'Hello World'
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'does not serve directories' do
|
37
|
+
get "/"
|
38
|
+
assert not_found?
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'passes to the next handler when the static option is disabled' do
|
42
|
+
@app.set :static, false
|
43
|
+
get "/#{F.basename(__FILE__)}"
|
44
|
+
assert not_found?
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'passes to the next handler when the public option is nil' do
|
48
|
+
@app.set :public, nil
|
49
|
+
get "/#{F.basename(__FILE__)}"
|
50
|
+
assert not_found?
|
51
|
+
end
|
52
|
+
|
53
|
+
it '404s when a file is not found' do
|
54
|
+
get "/foobarbaz.txt"
|
55
|
+
assert not_found?
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
describe 'Templating' do
|
4
|
+
def render_app(&block)
|
5
|
+
mock_app {
|
6
|
+
def render_test(template, data, options, &block)
|
7
|
+
inner = block ? block.call : ''
|
8
|
+
data + inner
|
9
|
+
end
|
10
|
+
set :views, File.dirname(__FILE__) + '/views'
|
11
|
+
get '/', &block
|
12
|
+
template(:layout3) { "Layout 3!\n" }
|
13
|
+
}
|
14
|
+
get '/'
|
15
|
+
end
|
16
|
+
|
17
|
+
def with_default_layout
|
18
|
+
layout = File.dirname(__FILE__) + '/views/layout.test'
|
19
|
+
File.open(layout, 'wb') { |io| io.write "Layout!\n" }
|
20
|
+
yield
|
21
|
+
ensure
|
22
|
+
File.unlink(layout) rescue nil
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'renders String templates directly' do
|
26
|
+
render_app { render :test, 'Hello World' }
|
27
|
+
assert ok?
|
28
|
+
assert_equal 'Hello World', body
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'renders Proc templates using the call result' do
|
32
|
+
render_app { render :test, Proc.new {'Hello World'} }
|
33
|
+
assert ok?
|
34
|
+
assert_equal 'Hello World', body
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'looks up Symbol templates in views directory' do
|
38
|
+
render_app { render :test, :hello }
|
39
|
+
assert ok?
|
40
|
+
assert_equal "Hello World!\n", body
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'uses the default layout template if not explicitly overridden' do
|
44
|
+
with_default_layout do
|
45
|
+
render_app { render :test, :hello }
|
46
|
+
assert ok?
|
47
|
+
assert_equal "Layout!\nHello World!\n", body
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'uses the default layout template if not really overriden' do
|
52
|
+
with_default_layout do
|
53
|
+
render_app { render :test, :hello, :layout => true }
|
54
|
+
assert ok?
|
55
|
+
assert_equal "Layout!\nHello World!\n", body
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'uses the layout template specified' do
|
60
|
+
render_app { render :test, :hello, :layout => :layout2 }
|
61
|
+
assert ok?
|
62
|
+
assert_equal "Layout 2!\nHello World!\n", body
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'uses layout templates defined with the #template method' do
|
66
|
+
render_app { render :test, :hello, :layout => :layout3 }
|
67
|
+
assert ok?
|
68
|
+
assert_equal "Layout 3!\nHello World!\n", body
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'loads templates from source file with use_in_file_templates!' do
|
72
|
+
mock_app {
|
73
|
+
use_in_file_templates!
|
74
|
+
}
|
75
|
+
assert_equal "this is foo\n\n", @app.templates[:foo]
|
76
|
+
assert_equal "X\n= yield\nX\n", @app.templates[:layout]
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
__END__
|
81
|
+
|
82
|
+
@@ foo
|
83
|
+
this is foo
|
84
|
+
|
85
|
+
@@ layout
|
86
|
+
X
|
87
|
+
= yield
|
88
|
+
X
|
@@ -0,0 +1 @@
|
|
1
|
+
xml.exclaim "You're my boy, #{@name}!"
|
@@ -0,0 +1 @@
|
|
1
|
+
Hello <%= 'World' %>
|
@@ -0,0 +1 @@
|
|
1
|
+
%h1 Hello From Haml
|
@@ -0,0 +1 @@
|
|
1
|
+
Hello World!
|
@@ -0,0 +1 @@
|
|
1
|
+
Layout 2!
|
metadata
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sinatra-sinatra
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.8.9
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Blake Mizerany
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-01-14 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rack
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.9.0
|
23
|
+
version:
|
24
|
+
description: Classy web-development dressed in a DSL
|
25
|
+
email:
|
26
|
+
executables: []
|
27
|
+
|
28
|
+
extensions: []
|
29
|
+
|
30
|
+
extra_rdoc_files:
|
31
|
+
- README.rdoc
|
32
|
+
- LICENSE
|
33
|
+
files:
|
34
|
+
- AUTHORS
|
35
|
+
- CHANGES
|
36
|
+
- LICENSE
|
37
|
+
- README.rdoc
|
38
|
+
- Rakefile
|
39
|
+
- compat/app_test.rb
|
40
|
+
- compat/application_test.rb
|
41
|
+
- compat/builder_test.rb
|
42
|
+
- compat/custom_error_test.rb
|
43
|
+
- compat/erb_test.rb
|
44
|
+
- compat/events_test.rb
|
45
|
+
- compat/filter_test.rb
|
46
|
+
- compat/haml_test.rb
|
47
|
+
- compat/helper.rb
|
48
|
+
- compat/mapped_error_test.rb
|
49
|
+
- compat/pipeline_test.rb
|
50
|
+
- compat/public/foo.xml
|
51
|
+
- compat/sass_test.rb
|
52
|
+
- compat/sessions_test.rb
|
53
|
+
- compat/streaming_test.rb
|
54
|
+
- compat/sym_params_test.rb
|
55
|
+
- compat/template_test.rb
|
56
|
+
- compat/use_in_file_templates_test.rb
|
57
|
+
- compat/views/foo.builder
|
58
|
+
- compat/views/foo.erb
|
59
|
+
- compat/views/foo.haml
|
60
|
+
- compat/views/foo.sass
|
61
|
+
- compat/views/foo_layout.erb
|
62
|
+
- compat/views/foo_layout.haml
|
63
|
+
- compat/views/layout_test/foo.builder
|
64
|
+
- compat/views/layout_test/foo.erb
|
65
|
+
- compat/views/layout_test/foo.haml
|
66
|
+
- compat/views/layout_test/foo.sass
|
67
|
+
- compat/views/layout_test/layout.builder
|
68
|
+
- compat/views/layout_test/layout.erb
|
69
|
+
- compat/views/layout_test/layout.haml
|
70
|
+
- compat/views/layout_test/layout.sass
|
71
|
+
- compat/views/no_layout/no_layout.builder
|
72
|
+
- compat/views/no_layout/no_layout.haml
|
73
|
+
- lib/sinatra.rb
|
74
|
+
- lib/sinatra/base.rb
|
75
|
+
- lib/sinatra/compat.rb
|
76
|
+
- lib/sinatra/images/404.png
|
77
|
+
- lib/sinatra/images/500.png
|
78
|
+
- lib/sinatra/main.rb
|
79
|
+
- lib/sinatra/test.rb
|
80
|
+
- lib/sinatra/test/bacon.rb
|
81
|
+
- lib/sinatra/test/rspec.rb
|
82
|
+
- lib/sinatra/test/spec.rb
|
83
|
+
- lib/sinatra/test/unit.rb
|
84
|
+
- sinatra.gemspec
|
85
|
+
- test/base_test.rb
|
86
|
+
- test/builder_test.rb
|
87
|
+
- test/data/reload_app_file.rb
|
88
|
+
- test/erb_test.rb
|
89
|
+
- test/filter_test.rb
|
90
|
+
- test/haml_test.rb
|
91
|
+
- test/helper.rb
|
92
|
+
- test/helpers_test.rb
|
93
|
+
- test/mapped_error_test.rb
|
94
|
+
- test/middleware_test.rb
|
95
|
+
- test/options_test.rb
|
96
|
+
- test/reload_test.rb
|
97
|
+
- test/request_test.rb
|
98
|
+
- test/result_test.rb
|
99
|
+
- test/routing_test.rb
|
100
|
+
- test/sass_test.rb
|
101
|
+
- test/sinatra_test.rb
|
102
|
+
- test/static_test.rb
|
103
|
+
- test/templates_test.rb
|
104
|
+
- test/views/hello.builder
|
105
|
+
- test/views/hello.erb
|
106
|
+
- test/views/hello.haml
|
107
|
+
- test/views/hello.sass
|
108
|
+
- test/views/hello.test
|
109
|
+
- test/views/layout2.builder
|
110
|
+
- test/views/layout2.erb
|
111
|
+
- test/views/layout2.haml
|
112
|
+
- test/views/layout2.test
|
113
|
+
has_rdoc: true
|
114
|
+
homepage: http://sinatra.rubyforge.org
|
115
|
+
post_install_message:
|
116
|
+
rdoc_options:
|
117
|
+
- --line-numbers
|
118
|
+
- --inline-source
|
119
|
+
- --title
|
120
|
+
- Sinatra
|
121
|
+
- --main
|
122
|
+
- README.rdoc
|
123
|
+
require_paths:
|
124
|
+
- lib
|
125
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: "0"
|
130
|
+
version:
|
131
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: "0"
|
136
|
+
version:
|
137
|
+
requirements: []
|
138
|
+
|
139
|
+
rubyforge_project: sinatra
|
140
|
+
rubygems_version: 1.2.0
|
141
|
+
signing_key:
|
142
|
+
specification_version: 2
|
143
|
+
summary: Classy web-development dressed in a DSL
|
144
|
+
test_files:
|
145
|
+
- test/base_test.rb
|
146
|
+
- test/builder_test.rb
|
147
|
+
- test/erb_test.rb
|
148
|
+
- test/filter_test.rb
|
149
|
+
- test/haml_test.rb
|
150
|
+
- test/helpers_test.rb
|
151
|
+
- test/mapped_error_test.rb
|
152
|
+
- test/middleware_test.rb
|
153
|
+
- test/options_test.rb
|
154
|
+
- test/reload_test.rb
|
155
|
+
- test/request_test.rb
|
156
|
+
- test/result_test.rb
|
157
|
+
- test/routing_test.rb
|
158
|
+
- test/sass_test.rb
|
159
|
+
- test/sinatra_test.rb
|
160
|
+
- test/static_test.rb
|
161
|
+
- test/templates_test.rb
|