padrino-core 0.9.22 → 0.9.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -132,6 +132,7 @@ module Padrino
|
|
132
132
|
set :reload, true if development?
|
133
133
|
set :logging, false
|
134
134
|
set :padrino_logging, true
|
135
|
+
set :method_override, true
|
135
136
|
set :sessions, false
|
136
137
|
set :public, Proc.new { Padrino.root('public', self.uri_root) }
|
137
138
|
# Padrino specific
|
@@ -170,8 +170,8 @@ module Padrino
|
|
170
170
|
|
171
171
|
# Resolve view path and options
|
172
172
|
options.reverse_merge!(DEFAULT_RENDERING_OPTIONS)
|
173
|
-
view_path = options.delete(:views) || settings.views ||
|
174
|
-
target_extension = File.extname(template_path)[1..-1] || "none" #
|
173
|
+
view_path = options.delete(:views) || settings.views || "./views"
|
174
|
+
target_extension = File.extname(template_path)[1..-1] || "none" # explicit template extension
|
175
175
|
template_path = template_path.chomp(".#{target_extension}")
|
176
176
|
|
177
177
|
# Generate potential template candidates
|
@@ -181,20 +181,20 @@ module Padrino
|
|
181
181
|
[template_file, template_engine] unless IGNORE_FILE_PATTERN.any? { |pattern| template_engine.to_s =~ pattern }
|
182
182
|
end
|
183
183
|
|
184
|
-
# Check if we have a
|
185
|
-
|
184
|
+
# Check if we have a simple content type
|
185
|
+
simple_content_type = [:html, :plain].include?(content_type)
|
186
186
|
|
187
187
|
# Resolve final template to render
|
188
188
|
located_template =
|
189
189
|
templates.find { |file, e| file.to_s == "#{template_path}.#{locale}.#{content_type}" } ||
|
190
|
-
templates.find { |file, e| file.to_s == "#{template_path}.#{locale}" &&
|
190
|
+
templates.find { |file, e| file.to_s == "#{template_path}.#{locale}" && simple_content_type } ||
|
191
191
|
templates.find { |file, e| File.extname(file.to_s) == ".#{target_extension}" or e.to_s == target_extension.to_s } ||
|
192
192
|
templates.find { |file, e| file.to_s == "#{template_path}.#{content_type}" } ||
|
193
|
-
templates.find { |file, e| file.to_s == "#{template_path}" &&
|
194
|
-
|
193
|
+
templates.find { |file, e| file.to_s == "#{template_path}" && simple_content_type } ||
|
194
|
+
(!options[:strict_format] && templates.first) # If not strict, fall back to the first located template
|
195
195
|
|
196
|
+
raise TemplateNotFound, "Template '#{template_path}' not found in '#{view_path}'!" if !located_template && options[:raise_exceptions]
|
196
197
|
settings.cache_template_file!(located_template, rendering_options) unless settings.reload_templates?
|
197
|
-
raise TemplateNotFound, "Template path '#{template_path}' could not be located in '#{view_path}'!" if !located_template && options[:raise_exceptions]
|
198
198
|
located_template
|
199
199
|
end
|
200
200
|
|
@@ -246,9 +246,8 @@ module Padrino
|
|
246
246
|
# ==== Examples
|
247
247
|
#
|
248
248
|
# url(:show, :id => 1)
|
249
|
+
# url(:show, :name => 'test', :id => 24)
|
249
250
|
# url(:show, 1)
|
250
|
-
# url(:show, :name => :test)
|
251
|
-
# url("/show/:id/:name", :id => 1, :name => foo)
|
252
251
|
#
|
253
252
|
def url(*args)
|
254
253
|
params = args.extract_options! # parameters is hash at end
|
@@ -496,7 +495,31 @@ module Padrino
|
|
496
495
|
end
|
497
496
|
|
498
497
|
##
|
499
|
-
#
|
498
|
+
# Allows routing by MIME-types specified in the URL or ACCEPT header.
|
499
|
+
#
|
500
|
+
# By default, if a non-provided mime-type is specified in a URL, the
|
501
|
+
# route will not match an thus return a 404.
|
502
|
+
#
|
503
|
+
# Setting the :treat_format_as_accept option to true allows treating
|
504
|
+
# missing mime types specified in the URL as if they were specified
|
505
|
+
# in the ACCEPT header and thus return 406.
|
506
|
+
#
|
507
|
+
# If no type is specified, the first in the provides-list will be
|
508
|
+
# returned.
|
509
|
+
#
|
510
|
+
# ==== Examples
|
511
|
+
# get "/a", :provides => [:html, :js]
|
512
|
+
# # => GET /a => :html
|
513
|
+
# # => GET /a.js => :js
|
514
|
+
# # => GET /a.xml => 404
|
515
|
+
#
|
516
|
+
# get "/b", :provides => [:html]
|
517
|
+
# # => GET /b; ACCEPT: html => html
|
518
|
+
# # => GET /b; ACCEPT: js => 406
|
519
|
+
#
|
520
|
+
# enable :treat_format_as_accept
|
521
|
+
# get "/c", :provides => [:html, :js]
|
522
|
+
# # => GET /c.xml => 406
|
500
523
|
#
|
501
524
|
def provides(*types)
|
502
525
|
@_use_format = true
|
@@ -505,7 +528,7 @@ module Padrino
|
|
505
528
|
request.path_info =~ /\.([^\.\/]+)$/
|
506
529
|
url_format = $1.to_sym if $1
|
507
530
|
accepts = request.accept.map { |a| a.split(";")[0].strip }
|
508
|
-
|
531
|
+
|
509
532
|
# per rfc2616-sec14:
|
510
533
|
# Assume */* if no ACCEPT header is given.
|
511
534
|
if accepts.empty? || accepts.any? { |a| a == "*/*" }
|
@@ -532,7 +555,13 @@ module Padrino
|
|
532
555
|
if !url_format && !accepts.empty? && !matched_format
|
533
556
|
halt 406
|
534
557
|
end
|
535
|
-
|
558
|
+
|
559
|
+
if settings.respond_to?(:treat_format_as_accept) && settings.treat_format_as_accept
|
560
|
+
if url_format && !matched_format
|
561
|
+
halt 406
|
562
|
+
end
|
563
|
+
end
|
564
|
+
|
536
565
|
if matched_format
|
537
566
|
@_content_type = url_format || accept_format || :html
|
538
567
|
content_type(@_content_type, :charset => 'utf-8')
|
@@ -551,9 +580,14 @@ module Padrino
|
|
551
580
|
#
|
552
581
|
# url(:show, :id => 1)
|
553
582
|
# url(:show, :name => :test)
|
554
|
-
# url(
|
583
|
+
# url(:show, 1)
|
584
|
+
# url("/foo")
|
555
585
|
#
|
556
586
|
def url(*args)
|
587
|
+
# Delegate to Sinatra 1.2 for simple url("/foo")
|
588
|
+
# http://www.sinatrarb.com/intro#Generating%20URLs
|
589
|
+
return super if args.first.is_a?(String) && !args[1].is_a?(Hash)
|
590
|
+
# Delegate to Padrino named route url generation
|
557
591
|
self.class.url(*args)
|
558
592
|
end
|
559
593
|
alias :url_for :url
|
data/lib/padrino-core/version.rb
CHANGED
data/padrino-core.gemspec
CHANGED
@@ -17,9 +17,9 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.files = %w(.document .gitignore LICENSE README.rdoc Rakefile padrino-core.gemspec) + Dir.glob("{bin,lib,test}/**/*")
|
18
18
|
s.rdoc_options = ["--charset=UTF-8"]
|
19
19
|
s.require_path = "lib"
|
20
|
-
s.add_dependency("sinatra", "~> 1.
|
20
|
+
s.add_dependency("sinatra", "~> 1.2.0")
|
21
21
|
s.add_dependency("http_router", "~> 0.5.4")
|
22
22
|
s.add_dependency("thor", ">=0.14.3")
|
23
23
|
s.add_dependency("activesupport", ">= 3.0.0")
|
24
24
|
s.add_dependency("tzinfo")
|
25
|
-
end
|
25
|
+
end
|
data/test/test_routing.rb
CHANGED
@@ -4,6 +4,11 @@ class FooError < RuntimeError; end
|
|
4
4
|
|
5
5
|
|
6
6
|
class TestRouting < Test::Unit::TestCase
|
7
|
+
should 'use padrinos url method' do
|
8
|
+
mock_app { }
|
9
|
+
assert_equal @app.method(:url).owner, Padrino::Routing::ClassMethods
|
10
|
+
end
|
11
|
+
|
7
12
|
should 'ignore trailing delimiters for basic route' do
|
8
13
|
mock_app do
|
9
14
|
get("/foo"){ "okey" }
|
@@ -20,16 +25,33 @@ class TestRouting < Test::Unit::TestCase
|
|
20
25
|
end
|
21
26
|
|
22
27
|
should 'fail with unrecognized route exception when not found' do
|
23
|
-
|
28
|
+
mock_app do
|
24
29
|
get(:index){ "okey" }
|
25
30
|
end
|
26
|
-
assert_nothing_raised { get
|
31
|
+
assert_nothing_raised { get @app.url_for(:index) }
|
27
32
|
assert_equal "okey", body
|
28
33
|
assert_raises(Padrino::Routing::UnrecognizedException) {
|
29
|
-
get
|
34
|
+
get @app.url_for(:fake)
|
30
35
|
}
|
31
36
|
end
|
32
37
|
|
38
|
+
should_eventually 'generate a url using route string with params' do
|
39
|
+
mock_app do
|
40
|
+
get("/show/:id/:name"){ "okey" }
|
41
|
+
end
|
42
|
+
|
43
|
+
assert_equal "/show/1/foo", @app.url_for("/show/:id/:name", :id => 1, :name => "foo")
|
44
|
+
end
|
45
|
+
|
46
|
+
should 'work correctly with sinatra redirects' do
|
47
|
+
mock_app do
|
48
|
+
get(:index){ redirect url(:index) }
|
49
|
+
end
|
50
|
+
|
51
|
+
get "/"
|
52
|
+
assert_equal "http://example.org/", headers['Location']
|
53
|
+
end
|
54
|
+
|
33
55
|
should 'accept regexp routes' do
|
34
56
|
mock_app do
|
35
57
|
get(%r{/fob|/baz}) { "regexp" }
|
@@ -170,6 +192,29 @@ class TestRouting < Test::Unit::TestCase
|
|
170
192
|
assert_equal 404, status
|
171
193
|
end
|
172
194
|
|
195
|
+
should 'use padrino url method' do
|
196
|
+
mock_app do
|
197
|
+
end
|
198
|
+
|
199
|
+
assert_equal @app.method(:url).owner, Padrino::Routing::ClassMethods
|
200
|
+
end
|
201
|
+
|
202
|
+
should 'work correctly with sinatra redirects' do
|
203
|
+
mock_app do
|
204
|
+
get(:index) { redirect url(:index) }
|
205
|
+
get(:google) { redirect "http://google.com" }
|
206
|
+
get("/foo") { redirect "/bar" }
|
207
|
+
get("/bar") { "Bar" }
|
208
|
+
end
|
209
|
+
|
210
|
+
get "/"
|
211
|
+
assert_equal "http://example.org/", headers['Location']
|
212
|
+
get "/google"
|
213
|
+
assert_equal "http://google.com", headers['Location']
|
214
|
+
get "/foo"
|
215
|
+
assert_equal "http://example.org/bar", headers['Location']
|
216
|
+
end
|
217
|
+
|
173
218
|
should "return 406 on Accept-Headers it does not provide" do
|
174
219
|
mock_app do
|
175
220
|
get(:a, :provides => [:html, :js]){ content_type }
|
@@ -178,16 +223,35 @@ class TestRouting < Test::Unit::TestCase
|
|
178
223
|
get "/a", {}, {"HTTP_ACCEPT" => "application/yaml"}
|
179
224
|
assert_equal 406, status
|
180
225
|
end
|
181
|
-
|
226
|
+
|
227
|
+
should "return 406 on file extensions it does not provide and flag is set" do
|
228
|
+
mock_app do
|
229
|
+
enable :treat_format_as_accept
|
230
|
+
get(:a, :provides => [:html, :js]){ content_type }
|
231
|
+
end
|
232
|
+
|
233
|
+
get "/a.xml", {}, {}
|
234
|
+
assert_equal 406, status
|
235
|
+
end
|
236
|
+
|
237
|
+
should "return 404 on file extensions it does not provide and flag is not set" do
|
238
|
+
mock_app do
|
239
|
+
get(:a, :provides => [:html, :js]){ content_type }
|
240
|
+
end
|
241
|
+
|
242
|
+
get "/a.xml", {}, {}
|
243
|
+
assert_equal 404, status
|
244
|
+
end
|
245
|
+
|
182
246
|
should "not set content_type to :html if Accept */* and html not in provides" do
|
183
247
|
mock_app do
|
184
248
|
get("/foo", :provides => [:json, :xml]) { content_type.to_s }
|
185
249
|
end
|
186
|
-
|
250
|
+
|
187
251
|
get '/foo', {}, { 'HTTP_ACCEPT' => '*/*;q=0.5' }
|
188
252
|
assert_equal 'json', body
|
189
253
|
end
|
190
|
-
|
254
|
+
|
191
255
|
should "return the first content type in provides if accept header is empty" do
|
192
256
|
mock_app do
|
193
257
|
get(:a, :provides => [:js]){ content_type.to_s }
|
@@ -769,7 +833,7 @@ class TestRouting < Test::Unit::TestCase
|
|
769
833
|
assert_equal 'Foo in xml', body
|
770
834
|
get '/foo'
|
771
835
|
assert_equal 'Foo in xml', body
|
772
|
-
|
836
|
+
|
773
837
|
get '/bar', {}, { 'HTTP_ACCEPT' => 'application/xml' }
|
774
838
|
assert_equal 'Bar in html', body
|
775
839
|
end
|
@@ -1257,4 +1321,13 @@ class TestRouting < Test::Unit::TestCase
|
|
1257
1321
|
assert_equal 500, status
|
1258
1322
|
assert_equal 'Foo!', body
|
1259
1323
|
end
|
1324
|
+
|
1325
|
+
should 'have MethodOverride middleware' do
|
1326
|
+
mock_app do
|
1327
|
+
put('/') { 'okay' }
|
1328
|
+
end
|
1329
|
+
post '/', {'_method'=>'PUT'}, {}
|
1330
|
+
assert_equal 200, status
|
1331
|
+
assert_equal 'okay', body
|
1332
|
+
end
|
1260
1333
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: padrino-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 9
|
9
|
-
-
|
10
|
-
version: 0.9.
|
9
|
+
- 23
|
10
|
+
version: 0.9.23
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Padrino Team
|
@@ -18,7 +18,7 @@ autorequire:
|
|
18
18
|
bindir: bin
|
19
19
|
cert_chain: []
|
20
20
|
|
21
|
-
date: 2011-03-
|
21
|
+
date: 2011-03-07 00:00:00 +01:00
|
22
22
|
default_executable: padrino
|
23
23
|
dependencies:
|
24
24
|
- !ruby/object:Gem::Dependency
|
@@ -29,12 +29,12 @@ dependencies:
|
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
hash:
|
32
|
+
hash: 31
|
33
33
|
segments:
|
34
34
|
- 1
|
35
|
-
-
|
35
|
+
- 2
|
36
36
|
- 0
|
37
|
-
version: 1.
|
37
|
+
version: 1.2.0
|
38
38
|
type: :runtime
|
39
39
|
version_requirements: *id001
|
40
40
|
- !ruby/object:Gem::Dependency
|
@@ -205,7 +205,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
205
205
|
requirements: []
|
206
206
|
|
207
207
|
rubyforge_project: padrino-core
|
208
|
-
rubygems_version: 1.
|
208
|
+
rubygems_version: 1.5.2
|
209
209
|
signing_key:
|
210
210
|
specification_version: 3
|
211
211
|
summary: The required Padrino core gem
|