rack-conneg 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.rdoc +9 -1
  2. data/lib/rack/conneg.rb +22 -20
  3. metadata +26 -11
data/README.rdoc CHANGED
@@ -1,4 +1,5 @@
1
1
  = Description
2
+
2
3
  Content negotiation for Rack applications, including a Rails-style respond_to block.
3
4
 
4
5
  = Features
@@ -7,7 +8,7 @@ Content negotiation for Rack applications, including a Rails-style respond_to bl
7
8
  * Allows certain routes to pass through without negotiation (useful for static files, etc.)
8
9
  * Falls back to a pre-set type if negotiation fails
9
10
  * Injects a respond_to method with default handler into the application's namespace
10
- * Injects negotiated_type and negotiated_ext methods both into the application and into Rack::Request
11
+ * Injects negotiated_type, negotiated_ext, and negotiated? methods both into the application and into Rack::Request
11
12
 
12
13
  = Sinatra Example
13
14
 
@@ -39,3 +40,10 @@ Content negotiation for Rack applications, including a Rails-style respond_to bl
39
40
  }
40
41
  end
41
42
  end
43
+
44
+ = Release History
45
+
46
+ <b>0.1.2</b> - Initial release
47
+ <b>0.1.3</b> - Added proper RegExp escaping to match content types with + in them
48
+ <b>0.1.4</b> - Added ignore_contents_of() to recursively ignore directory contents and negotiated? method to determine if negotiation took place
49
+ <b>0.1.5</b> - Allow negotiation to fall back if no Accept: header supplied
data/lib/rack/conneg.rb CHANGED
@@ -5,7 +5,7 @@ module Rack #:nodoc:#
5
5
 
6
6
  class Conneg
7
7
 
8
- VERSION = '0.1.4'
8
+ VERSION = '0.1.5'
9
9
 
10
10
  attr :ignores
11
11
 
@@ -56,26 +56,28 @@ module Rack #:nodoc:#
56
56
  else
57
57
  # Create an array of types out of the HTTP_ACCEPT header, sorted
58
58
  # by q value and original order
59
- accept_types = env['HTTP_ACCEPT'].split(/,/)
60
- accept_types.each_with_index { |t,i|
61
- (accept_type,weight) = t.split(/;/)
62
- weight = weight.nil? ? 1.0 : weight.split(/\=/).last.to_f
63
- accept_types[i] = { :type => accept_type, :weight => weight, :order => i }
64
- }
65
- accept_types.sort! { |a,b|
66
- ord = b[:weight] <=> a[:weight]
67
- if ord == 0
68
- ord = a[:order] <=> b[:order]
69
- end
70
- ord
71
- }
59
+ if env['HTTP_ACCEPT']
60
+ accept_types = env['HTTP_ACCEPT'].split(/,/)
61
+ accept_types.each_with_index { |t,i|
62
+ (accept_type,weight) = t.split(/;/)
63
+ weight = weight.nil? ? 1.0 : weight.split(/\=/).last.to_f
64
+ accept_types[i] = { :type => accept_type, :weight => weight, :order => i }
65
+ }
66
+ accept_types.sort! { |a,b|
67
+ ord = b[:weight] <=> a[:weight]
68
+ if ord == 0
69
+ ord = a[:order] <=> b[:order]
70
+ end
71
+ ord
72
+ }
72
73
 
73
- # Find the first item in accept_types that matches a registered
74
- # content type
75
- accept_types.find { |t|
76
- re = %r{^#{Regexp.escape(t[:type].gsub(/\*/,'.+'))}$}
77
- @types.find { |type| re.match(type) ? mime_type = type : nil }
78
- }
74
+ # Find the first item in accept_types that matches a registered
75
+ # content type
76
+ accept_types.find { |t|
77
+ re = %r{^#{Regexp.escape(t[:type].gsub(/\*/,'.+'))}$}
78
+ @types.find { |type| re.match(type) ? mime_type = type : nil }
79
+ }
80
+ end
79
81
  end
80
82
 
81
83
  mime_type ||= fallback
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-conneg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ hash: 17
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 5
10
+ version: 0.1.5
5
11
  platform: ruby
6
12
  authors:
7
13
  - Michael B. Klein
@@ -9,19 +15,23 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2010-03-11 00:00:00 -08:00
13
- default_executable:
18
+ date: 2011-09-27 00:00:00 Z
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: rack
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
20
25
  requirements:
21
26
  - - ">="
22
27
  - !ruby/object:Gem::Version
28
+ hash: 15
29
+ segments:
30
+ - 1
31
+ - 0
23
32
  version: "1.0"
24
- version:
33
+ type: :runtime
34
+ version_requirements: *id001
25
35
  description: Middleware that provides both file extension and HTTP_ACCEPT-type content negotiation for Rack applications
26
36
  email: Michael.Klein@oregonstate.edu
27
37
  executables: []
@@ -33,7 +43,6 @@ extra_rdoc_files:
33
43
  files:
34
44
  - README.rdoc
35
45
  - lib/rack/conneg.rb
36
- has_rdoc: true
37
46
  homepage:
38
47
  licenses: []
39
48
 
@@ -44,21 +53,27 @@ rdoc_options:
44
53
  require_paths:
45
54
  - lib
46
55
  required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
47
57
  requirements:
48
58
  - - ">="
49
59
  - !ruby/object:Gem::Version
60
+ hash: 3
61
+ segments:
62
+ - 0
50
63
  version: "0"
51
- version:
52
64
  required_rubygems_version: !ruby/object:Gem::Requirement
65
+ none: false
53
66
  requirements:
54
67
  - - ">="
55
68
  - !ruby/object:Gem::Version
69
+ hash: 3
70
+ segments:
71
+ - 0
56
72
  version: "0"
57
- version:
58
73
  requirements: []
59
74
 
60
75
  rubyforge_project:
61
- rubygems_version: 1.3.5
76
+ rubygems_version: 1.8.6
62
77
  signing_key:
63
78
  specification_version: 3
64
79
  summary: Content Negotiation middleware for Rack applications