mynyml-rack-abstract-format 0.9 → 0.9.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README +2 -0
- data/Rakefile +1 -1
- data/examples/{app.rb → app.ru} +2 -2
- data/lib/rack/abstract_format.rb +6 -1
- data/{simple_router.gemspec → rack-abstract-format.gemspec} +8 -5
- data/test/test_abstract_format.rb +6 -6
- data/test/test_helper.rb +1 -0
- metadata +4 -4
data/README
CHANGED
data/Rakefile
CHANGED
@@ -22,7 +22,7 @@ end
|
|
22
22
|
|
23
23
|
spec = Gem::Specification.new do |s|
|
24
24
|
s.name = 'rack-abstract-format'
|
25
|
-
s.version = '0.9'
|
25
|
+
s.version = '0.9.4'
|
26
26
|
s.summary = "Rack middleware that abstracts format (extension) away from the path (into env)"
|
27
27
|
s.description = "Rack middleware that abstracts format (extension) away from the path (into env)"
|
28
28
|
s.author = "Martin Aumont"
|
data/examples/{app.rb → app.ru}
RENAMED
@@ -1,5 +1,5 @@
|
|
1
1
|
# run me with:
|
2
|
-
# $rackup examples/app.
|
2
|
+
# $rackup examples/app.ru -p 3000
|
3
3
|
#
|
4
4
|
require 'rubygems'
|
5
5
|
require 'rack'
|
@@ -11,7 +11,7 @@ class App
|
|
11
11
|
env['PATH_INFO'] #=> #{env['PATH_INFO'].inspect}
|
12
12
|
env['request.format'] #=> #{env['request.format'].inspect}
|
13
13
|
TXT
|
14
|
-
[200, {'Content-Type' => 'text/plain'}, [body]]
|
14
|
+
[200, {'Content-Type' => 'text/plain'}, [body]]
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
data/lib/rack/abstract_format.rb
CHANGED
@@ -10,8 +10,13 @@ module Rack
|
|
10
10
|
def call(env)
|
11
11
|
path = Pathname(env['PATH_INFO'])
|
12
12
|
env['PATH_INFO'] = path.to_s.sub(/#{path.extname}$/,'')
|
13
|
-
env['
|
13
|
+
env['Accept'] = concat(env['Accept'], Rack::Mime.mime_type(path.extname))
|
14
14
|
@app.call(env)
|
15
15
|
end
|
16
|
+
|
17
|
+
private
|
18
|
+
def concat(accept, type)
|
19
|
+
(accept || '').split(',').unshift(type).join(',')
|
20
|
+
end
|
16
21
|
end
|
17
22
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
name:
|
2
|
+
name: rack-abstract-format
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Aumont
|
@@ -9,11 +9,11 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-06-02 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
16
|
-
description: Rack middleware that abstracts format
|
16
|
+
description: Rack middleware that abstracts format (extension) away from the path (into env)
|
17
17
|
email: mynyml@gmail.com
|
18
18
|
executables: []
|
19
19
|
|
@@ -26,6 +26,9 @@ files:
|
|
26
26
|
- test
|
27
27
|
- test/test_abstract_format.rb
|
28
28
|
- test/test_helper.rb
|
29
|
+
- examples
|
30
|
+
- examples/app.ru
|
31
|
+
- rack-abstract-format.gemspec
|
29
32
|
- lib
|
30
33
|
- lib/rack
|
31
34
|
- lib/rack/abstract_format.rb
|
@@ -58,6 +61,6 @@ rubyforge_project:
|
|
58
61
|
rubygems_version: 1.3.3
|
59
62
|
signing_key:
|
60
63
|
specification_version: 3
|
61
|
-
summary: Rack middleware that abstracts format
|
64
|
+
summary: Rack middleware that abstracts format (extension) away from the path (into env)
|
62
65
|
test_files: []
|
63
66
|
|
@@ -8,9 +8,9 @@ App = Rack::Builder.new {
|
|
8
8
|
|
9
9
|
class AbstractFormatTest < Test::Unit::TestCase
|
10
10
|
|
11
|
-
def get(path)
|
12
|
-
env = Rack::MockRequest.env_for(path)
|
13
|
-
App.call(env)
|
11
|
+
def get(path, opts={})
|
12
|
+
env = Rack::MockRequest.env_for(path, opts)
|
13
|
+
App.call(env)
|
14
14
|
env
|
15
15
|
end
|
16
16
|
|
@@ -24,8 +24,8 @@ class AbstractFormatTest < Test::Unit::TestCase
|
|
24
24
|
assert_equal '/path.to/resource', env['PATH_INFO']
|
25
25
|
end
|
26
26
|
|
27
|
-
test "
|
28
|
-
env = get('/path
|
29
|
-
assert_equal 'xml', env['
|
27
|
+
test "prepends requested media type to Accept header" do
|
28
|
+
env = get('/path/resource.html', 'Accept' => 'application/xml')
|
29
|
+
assert_equal 'text/html,application/xml' , env['Accept']
|
30
30
|
end
|
31
31
|
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mynyml-rack-abstract-format
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.9.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Aumont
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-06-01 21:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -27,8 +27,8 @@ files:
|
|
27
27
|
- test/test_abstract_format.rb
|
28
28
|
- test/test_helper.rb
|
29
29
|
- examples
|
30
|
-
- examples/app.
|
31
|
-
-
|
30
|
+
- examples/app.ru
|
31
|
+
- rack-abstract-format.gemspec
|
32
32
|
- lib
|
33
33
|
- lib/rack
|
34
34
|
- lib/rack/abstract_format.rb
|