padrino-core 0.9.21 → 0.9.22

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010 Padrino
1
+ Copyright (c) 2011 Padrino
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -291,4 +291,4 @@ For a complete overview of Padrino terminal commands, check out the
291
291
 
292
292
  == Copyright
293
293
 
294
- Copyright (c) 2010 Padrino. See LICENSE for details.
294
+ Copyright (c) 2011 Padrino. See LICENSE for details.
@@ -6,7 +6,7 @@ module Padrino
6
6
  # Subclasses of this become independent Padrino applications (stemming from Sinatra::Application)
7
7
  # These subclassed applications can be easily mounted into other Padrino applications as well.
8
8
  #
9
- class Application < Sinatra::Application
9
+ class Application < Sinatra::Base
10
10
  register Padrino::Routing # Support for advanced routing, controllers, url_for
11
11
  register Padrino::Rendering # Support for enhanced rendering with template detection
12
12
 
@@ -131,6 +131,7 @@ module Padrino
131
131
  set :raise_errors, true if development?
132
132
  set :reload, true if development?
133
133
  set :logging, false
134
+ set :padrino_logging, true
134
135
  set :sessions, false
135
136
  set :public, Proc.new { Padrino.root('public', self.uri_root) }
136
137
  # Padrino specific
@@ -196,7 +197,7 @@ module Padrino
196
197
  # Requires the Padrino middleware
197
198
  #
198
199
  def register_initializers
199
- use Padrino::Logger::Rack if Padrino.logger && Padrino.logger.level == 0
200
+ use Padrino::Logger::Rack if Padrino.logger && (Padrino.logger.level == 0 && padrino_logging?)
200
201
  use Padrino::Reloader::Rack if reload?
201
202
  use Rack::Flash if flash? && sessions?
202
203
  end
@@ -234,4 +235,4 @@ module Padrino
234
235
  }.map! { |line| line.gsub(/^\.\//, '') }
235
236
  end
236
237
  end # Application
237
- end # Padrino
238
+ end # Padrino
@@ -502,10 +502,17 @@ module Padrino
502
502
  @_use_format = true
503
503
  condition do
504
504
  mime_types = types.map { |t| mime_type(t) }
505
- accepts = request.accept.map { |a| a.split(";")[0].strip }
506
- matching_types = (accepts & mime_types)
507
505
  request.path_info =~ /\.([^\.\/]+)$/
508
506
  url_format = $1.to_sym if $1
507
+ accepts = request.accept.map { |a| a.split(";")[0].strip }
508
+
509
+ # per rfc2616-sec14:
510
+ # Assume */* if no ACCEPT header is given.
511
+ if accepts.empty? || accepts.any? { |a| a == "*/*" }
512
+ matching_types = mime_types.slice(0,1)
513
+ else
514
+ matching_types = (accepts & mime_types)
515
+ end
509
516
 
510
517
  if params[:format]
511
518
  accept_format = params[:format]
@@ -517,9 +524,15 @@ module Padrino
517
524
  matched_format = types.include?(:any) ||
518
525
  types.include?(accept_format) ||
519
526
  types.include?(url_format) ||
520
- accepts.any? { |a| a == "*/*" } ||
521
527
  ((!url_format) && request.accept.empty? && types.include?(:html))
522
528
 
529
+ # per rfc2616-sec14:
530
+ # answer with 406 if accept is given but types to not match any
531
+ # provided type
532
+ if !url_format && !accepts.empty? && !matched_format
533
+ halt 406
534
+ end
535
+
523
536
  if matched_format
524
537
  @_content_type = url_format || accept_format || :html
525
538
  content_type(@_content_type, :charset => 'utf-8')
@@ -0,0 +1,30 @@
1
+ ja:
2
+ date:
3
+ formats:
4
+ # Use the strftime parameters for formats.
5
+ # When no format has been given, it uses default.
6
+ # You can provide other formats here if you like!
7
+ default: "%Y/%m/%d"
8
+ short: "%m/%d"
9
+ long: "%Y年%m月%d日"
10
+
11
+ day_names: [日曜日, 月曜日, 火曜日, 水曜日, 木曜日, 金曜日, 土曜日]
12
+ abbr_day_names: [日, 月, 火, 水, 木, 金, 土]
13
+ month_names: [~, 一月, 二月, 三月, 四月, 五月, 六月, 七月, 八月, 九月, 十月, 十一月, 十二月]
14
+ abbr_month_names: [~, 一月, 二月, 三月, 四月, 五月, 六月, 七月, 八月, 九月, 十月, 十一月, 十二月]
15
+ order: [ :year, :month, :day ]
16
+
17
+ time:
18
+ formats:
19
+ default: "%Y/%m/%d %H:%M:%S"
20
+ short: "%m/%d %H:%M"
21
+ long: "%Y年%m月%d日 %H時%M分%S秒"
22
+ am: "午前"
23
+ pm: "午後"
24
+
25
+ # Used in array.to_sentence.
26
+ support:
27
+ array:
28
+ words_connector: ", "
29
+ two_words_connector: " と "
30
+ last_word_connector: ", と "
@@ -5,7 +5,7 @@
5
5
  # without include full padrino core.
6
6
  #
7
7
  module Padrino
8
- VERSION = '0.9.21' unless defined?(Padrino::VERSION)
8
+ VERSION = '0.9.22' unless defined?(Padrino::VERSION)
9
9
  ##
10
10
  # Return the current Padrino version
11
11
  #
@@ -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.1.0")
20
+ s.add_dependency("sinatra", "~> 1.1.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
@@ -20,6 +20,7 @@ class TestApplication < Test::Unit::TestCase
20
20
  assert_equal Padrino.root("views"), PadrinoTestApp.views
21
21
  assert PadrinoTestApp.raise_errors
22
22
  assert !PadrinoTestApp.logging
23
+ assert PadrinoTestApp.padrino_logging
23
24
  assert !PadrinoTestApp.sessions
24
25
  end
25
26
 
@@ -45,10 +46,10 @@ class TestApplication < Test::Unit::TestCase
45
46
  get '/foo', {}, { 'HTTP_ACCEPT' => 'application/xml' }
46
47
  assert_equal 'Foo in xml', body
47
48
  get '/foo'
48
- assert not_found?
49
+ assert_equal 'Foo in xml', body
49
50
 
50
51
  get '/bar', {}, { 'HTTP_ACCEPT' => 'application/xml' }
51
52
  assert_equal "Foo in html", body
52
53
  end
53
54
  end
54
- end
55
+ end
@@ -170,13 +170,31 @@ class TestRouting < Test::Unit::TestCase
170
170
  assert_equal 404, status
171
171
  end
172
172
 
173
- should "not allow Accept-Headers it does not provide" do
173
+ should "return 406 on Accept-Headers it does not provide" do
174
174
  mock_app do
175
175
  get(:a, :provides => [:html, :js]){ content_type }
176
176
  end
177
177
 
178
178
  get "/a", {}, {"HTTP_ACCEPT" => "application/yaml"}
179
- assert_equal 404, status
179
+ assert_equal 406, status
180
+ end
181
+
182
+ should "not set content_type to :html if Accept */* and html not in provides" do
183
+ mock_app do
184
+ get("/foo", :provides => [:json, :xml]) { content_type.to_s }
185
+ end
186
+
187
+ get '/foo', {}, { 'HTTP_ACCEPT' => '*/*;q=0.5' }
188
+ assert_equal 'json', body
189
+ end
190
+
191
+ should "return the first content type in provides if accept header is empty" do
192
+ mock_app do
193
+ get(:a, :provides => [:js]){ content_type.to_s }
194
+ end
195
+
196
+ get "/a", {}, {}
197
+ assert_equal "js", body
180
198
  end
181
199
 
182
200
  should "not default to HTML if HTML is not provided and no type is given" do
@@ -185,7 +203,7 @@ class TestRouting < Test::Unit::TestCase
185
203
  end
186
204
 
187
205
  get "/a", {}, {}
188
- assert_equal 404, status
206
+ assert_equal "application/javascript;charset=utf-8", content_type
189
207
  end
190
208
 
191
209
  should "not match routes if url_format and http_accept is provided but not included" do
@@ -345,14 +363,16 @@ class TestRouting < Test::Unit::TestCase
345
363
  get(:d, :provides => [:html, :js]){ "html,js"}
346
364
  end
347
365
  get "/a"
348
- assert_equal 404, status
366
+ assert_equal 200, status
367
+ assert_equal "js", body
349
368
  get "/a.js"
350
369
  assert_equal "js", body
351
370
  get "/b"
352
371
  assert_equal "any", body
353
372
  assert_raise(RuntimeError) { get "/b.foo" }
354
373
  get "/c"
355
- assert_equal 404, status
374
+ assert_equal 200, status
375
+ assert_equal "js,json", body
356
376
  get "/c.js"
357
377
  assert_equal "js,json", body
358
378
  get "/c.json"
@@ -733,8 +753,8 @@ class TestRouting < Test::Unit::TestCase
733
753
  assert ok?
734
754
  assert_equal 'application/javascript;charset=utf-8', response.headers['Content-Type']
735
755
 
736
- get '/foo', {}, { :accept => 'text/html' }
737
- assert not_found?
756
+ get '/foo', {}, { "HTTP_ACCEPT" => 'text/html' }
757
+ assert_equal 406, status
738
758
  end
739
759
 
740
760
  should "works allow global provides" do
@@ -748,8 +768,8 @@ class TestRouting < Test::Unit::TestCase
748
768
  get '/foo', {}, { 'HTTP_ACCEPT' => 'application/xml' }
749
769
  assert_equal 'Foo in xml', body
750
770
  get '/foo'
751
- assert not_found?
752
-
771
+ assert_equal 'Foo in xml', body
772
+
753
773
  get '/bar', {}, { 'HTTP_ACCEPT' => 'application/xml' }
754
774
  assert_equal 'Bar in html', body
755
775
  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: 17
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 21
10
- version: 0.9.21
9
+ - 22
10
+ version: 0.9.22
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-02-28 00:00:00 -08:00
21
+ date: 2011-03-04 00:00:00 -08:00
22
22
  default_executable: padrino
23
23
  dependencies:
24
24
  - !ruby/object:Gem::Dependency
@@ -27,7 +27,7 @@ dependencies:
27
27
  requirement: &id001 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
- - - ">="
30
+ - - ~>
31
31
  - !ruby/object:Gem::Version
32
32
  hash: 19
33
33
  segments:
@@ -135,6 +135,7 @@ files:
135
135
  - lib/padrino-core/locale/es.yml
136
136
  - lib/padrino-core/locale/fr.yml
137
137
  - lib/padrino-core/locale/it.yml
138
+ - lib/padrino-core/locale/ja.yml
138
139
  - lib/padrino-core/locale/nl.yml
139
140
  - lib/padrino-core/locale/no.yml
140
141
  - lib/padrino-core/locale/pl.yml
@@ -204,7 +205,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
204
205
  requirements: []
205
206
 
206
207
  rubyforge_project: padrino-core
207
- rubygems_version: 1.5.2
208
+ rubygems_version: 1.6.0
208
209
  signing_key:
209
210
  specification_version: 3
210
211
  summary: The required Padrino core gem