mynyml-rack-respond_to 0.9.4 → 0.9.5

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -18,7 +18,6 @@ requested mime type. Standalone version of the equivalent Rails functionality.
18
18
 
19
19
  def call(env)
20
20
  # Pass in the env, and RespondTo will retrieve the requested mime type
21
- # from the HTTP_ACCEPT header
22
21
  Rack::RespondTo.env = env
23
22
 
24
23
  # Alternatively, to use standalone you can also assign the mime type
data/Rakefile CHANGED
@@ -22,7 +22,7 @@ end
22
22
 
23
23
  spec = Gem::Specification.new do |s|
24
24
  s.name = 'rack-respond_to'
25
- s.version = '0.9.4'
25
+ s.version = '0.9.5'
26
26
  s.summary = "Rack middleware port of Rails's respond_to feature"
27
27
  s.description = "Rack middleware port of Rails's respond_to feature"
28
28
  s.author = "Martin Aumont"
@@ -31,6 +31,8 @@ spec = Gem::Specification.new do |s|
31
31
  s.has_rdoc = true
32
32
  s.require_path = "lib"
33
33
  s.files = all_except([/doc/, /pkg/])
34
+
35
+ s.add_dependency 'mynyml-rack-accept-media-types', '>= 0.6'
34
36
  end
35
37
 
36
38
  Rake::GemPackageTask.new(spec) do |p|
data/TODO CHANGED
@@ -1,2 +1,27 @@
1
1
  o handle wildcard content-types?
2
- - */*;q=0.8
2
+ e.g. */* matches first format block
3
+
4
+ Rack::RespondTo.mime_type = '*/*'
5
+
6
+ body = respond_to do |format|
7
+ format.html { 'html' }
8
+ format.xml { 'xml' }
9
+ end
10
+ body #=> 'html'
11
+
12
+ body = respond_to do |format|
13
+ format.xml { 'xml' }
14
+ format.html { 'html' }
15
+ end
16
+ body #=> 'xml'
17
+
18
+ o cascade down accept types priority instead of only responding to prefered
19
+ type. e.g:
20
+
21
+ env['HTTP_ACCEPT'] #=> 'text/plain,text/html;q=0.9,application/xml;q=0.8'
22
+
23
+ body = respond_to do |format|
24
+ format.html { 'html' }
25
+ format.xml { 'xml' }
26
+ end
27
+ body #=> 'html'
@@ -1,8 +1,7 @@
1
1
  # install required dependencies:
2
- #
3
2
  # $sudo gem install mynyml-rack-abstract-format --source=http://gems.github.com/
4
3
  #
5
- # and run me with:
4
+ # run with:
6
5
  # $rackup examples/recommended_use.ru -p 8080
7
6
  #
8
7
  # and request:
@@ -1,3 +1,5 @@
1
+ require 'rack/accept_media_types'
2
+
1
3
  module Rack
2
4
 
3
5
  # Based on Rails's API, and sinatra-respond_to (http://github.com/cehoffman/sinatra-respond_to)
@@ -34,18 +36,13 @@ module Rack
34
36
  end
35
37
  end
36
38
 
37
- # Convenience method that returns the mime type of the given format
38
- # (similar to Rack::Mime.mime_type).
39
+ # Mime type requested.
39
40
  #
40
- # If format argument is omitted, will return the mime type for
41
- # RespondTo.format (i.e. equivelent to RespondTo.mime_type(RespondTo.format)).
42
41
  # Useful for setting content type:
43
42
  #
44
- # ===== Example
45
- #
46
43
  # [200, {'Content-Type' => Rack::RespondTo.mime_type}, [body]]
47
44
  #
48
- def mime_type(format = nil)
45
+ def mime_type
49
46
  @mime_type || accept
50
47
  end
51
48
 
@@ -66,7 +63,7 @@ module Rack
66
63
  # String:: first mime type from header's list or nil if none
67
64
  #
68
65
  def accept
69
- self.env['HTTP_ACCEPT'].split(',').first.split(';').first if env && env['HTTP_ACCEPT'] && !env['HTTP_ACCEPT'].empty?
66
+ Rack::AcceptMediaTypes.new(self.env['HTTP_ACCEPT'] || '').prefered unless self.env.nil?
70
67
  end
71
68
  end
72
69
 
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-respond_to
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.4
4
+ version: 0.9.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Aumont
@@ -9,10 +9,19 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-03 00:00:00 -04:00
12
+ date: 2009-06-08 00:00:00 -04:00
13
13
  default_executable:
14
- dependencies: []
15
-
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: mynyml-rack-accept-media-types
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0.6"
24
+ version:
16
25
  description: Rack middleware port of Rails's respond_to feature
17
26
  email: mynyml@gmail.com
18
27
  executables: []
@@ -69,11 +69,6 @@ class TestRespondTo < Test::Unit::TestCase
69
69
  end
70
70
  end
71
71
 
72
- test "mime type ignores content-type arguments" do
73
- Rack::RespondTo.env = {'HTTP_ACCEPT' => 'application/xml;q=0.9,text/html'}
74
- assert_equal 'application/xml', Rack::RespondTo.mime_type
75
- end
76
-
77
72
  test "explicitly specified mime type takes precedence over env's" do
78
73
  Rack::RespondTo.env = {'HTTP_ACCEPT' => 'text/html'}
79
74
  Rack::RespondTo.mime_type = 'text/plain'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mynyml-rack-respond_to
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.4
4
+ version: 0.9.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Aumont
@@ -9,10 +9,19 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-02 21:00:00 -07:00
12
+ date: 2009-06-07 21:00:00 -07:00
13
13
  default_executable:
14
- dependencies: []
15
-
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: mynyml-rack-accept-media-types
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0.6"
24
+ version:
16
25
  description: Rack middleware port of Rails's respond_to feature
17
26
  email: mynyml@gmail.com
18
27
  executables: []