rack-gridfs-thumb 0.1.0 → 0.2.0
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.
- data/README.md +3 -5
- data/lib/rack/gridfs-thumb.rb +18 -6
- data/lib/rack/version.rb +1 -1
- data/rack-gridfs-thumb.gemspec +1 -1
- data/test/test_gridfs_thumb.rb +27 -5
- metadata +11 -11
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Rack::GridFSThumb
|
2
2
|
=================
|
3
3
|
|
4
|
-
Rack::
|
4
|
+
Rack::GridFSThumb is Rack middleware for resizing images served via [Rack::GridFS](https://github.com/skinandbones/rack-gridfs). Resizing is done via [MiniMagick](https://github.com/probablycorey/mini_magick) and all the usual [geometry arguments](http://www.imagemagick.org/script/command-line-processing.php#geometry) are accepted.
|
5
5
|
|
6
6
|
For example:
|
7
7
|
|
@@ -15,10 +15,8 @@ Installation
|
|
15
15
|
Usage
|
16
16
|
-----
|
17
17
|
|
18
|
-
require 'rack/gridfs'
|
19
18
|
require 'rack/gridfs-thumb'
|
20
19
|
|
21
|
-
prefix
|
20
|
+
use Rack::GridFSThumb, :prefix => 'gridfs', :hostname => 'localhost', :port => 27017, :database => 'test'
|
22
21
|
|
23
|
-
|
24
|
-
use Rack::GridFSThumb, :prefix => prefix
|
22
|
+
See the Rack::GridFS README for all available options.
|
data/lib/rack/gridfs-thumb.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
require 'mini_magick'
|
2
|
+
require 'rack/gridfs'
|
2
3
|
|
3
4
|
module Rack
|
4
5
|
class GridFSThumb
|
5
6
|
def initialize(app, options = {})
|
6
7
|
@app = app
|
7
|
-
@options = options
|
8
|
-
@options[:
|
8
|
+
@options = default_options.merge(options)
|
9
|
+
@gridfs = @options[:gridfs] || Rack::GridFS::Endpoint.new(@options)
|
9
10
|
end
|
10
11
|
|
11
12
|
def call(env)
|
@@ -14,8 +15,12 @@ module Rack
|
|
14
15
|
response = catch(:respond) do
|
15
16
|
match(@request.path_info) do |path, geometry|
|
16
17
|
status, @headers, image = request_image(path)
|
17
|
-
thumb = thumbnail(image, geometry)
|
18
18
|
|
19
|
+
if geometry.nil?
|
20
|
+
throw :respond, [status, @headers, image]
|
21
|
+
end
|
22
|
+
|
23
|
+
thumb = thumbnail(image, geometry)
|
19
24
|
response_for(thumb)
|
20
25
|
end
|
21
26
|
end
|
@@ -23,10 +28,17 @@ module Rack
|
|
23
28
|
response || @app.call(env)
|
24
29
|
end
|
25
30
|
|
31
|
+
def route
|
32
|
+
%r{(/#{@options[:prefix]}/[^/]+)/?([^/]+)?/?$}
|
33
|
+
end
|
34
|
+
|
26
35
|
private
|
27
36
|
|
28
|
-
def
|
29
|
-
|
37
|
+
def default_options
|
38
|
+
{
|
39
|
+
:prefix => 'gridfs',
|
40
|
+
:mapper => lambda { |path| %r!^/#{@options[:prefix]}/([^/]+)/?!.match(path)[1] }
|
41
|
+
}
|
30
42
|
end
|
31
43
|
|
32
44
|
def match(path_info)
|
@@ -47,7 +59,7 @@ module Rack
|
|
47
59
|
|
48
60
|
def request_image(path_info)
|
49
61
|
env = @request.env.merge('PATH_INFO' => path_info)
|
50
|
-
status, headers, body = @
|
62
|
+
status, headers, body = @gridfs.call(env)
|
51
63
|
|
52
64
|
unless status >= 200 && status < 300
|
53
65
|
throw :respond, [status, headers, body]
|
data/lib/rack/version.rb
CHANGED
data/rack-gridfs-thumb.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.summary = "rack-gridfs-thumb-#{s.version}"
|
13
13
|
s.description = 'Rack middleware for resizing images served via Rack::GridFS'
|
14
14
|
|
15
|
-
s.add_dependency('rack')
|
15
|
+
s.add_dependency('rack-gridfs', '>= 0.4.1')
|
16
16
|
s.add_dependency('mini_magick', '>= 3.3')
|
17
17
|
|
18
18
|
s.add_development_dependency('rack-test')
|
data/test/test_gridfs_thumb.rb
CHANGED
@@ -13,8 +13,30 @@ class Rack::GridFSThumbTest < Test::Unit::TestCase
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def app
|
16
|
-
@app ||=
|
17
|
-
Rack::GridFSThumb.new(@app, :prefix => 'gridfs')
|
16
|
+
@app ||= gridfs_stub
|
17
|
+
Rack::GridFSThumb.new(@app, :prefix => 'gridfs', :gridfs => @app)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_route_regex
|
21
|
+
route = app.route
|
22
|
+
|
23
|
+
match = "/gridfs/#{@id}".match(route)
|
24
|
+
assert_equal "/gridfs/#{@id}", match[1]
|
25
|
+
assert_nil match[2]
|
26
|
+
|
27
|
+
match = "/gridfs/#{@id}/".match(route)
|
28
|
+
assert_equal "/gridfs/#{@id}", match[1]
|
29
|
+
assert_nil match[2]
|
30
|
+
|
31
|
+
match = "/gridfs/#{@id}/100x100".match(route)
|
32
|
+
assert_equal "/gridfs/#{@id}", match[1]
|
33
|
+
assert_equal '100x100', match[2]
|
34
|
+
|
35
|
+
match = "/gridfs/#{@id}/100x100/".match(route)
|
36
|
+
assert_equal "/gridfs/#{@id}", match[1]
|
37
|
+
assert_equal '100x100', match[2]
|
38
|
+
|
39
|
+
assert_nil "/gridfs/#{@id}/100x100/extra".match(route)
|
18
40
|
end
|
19
41
|
|
20
42
|
def test_not_called_without_geometry
|
@@ -26,7 +48,7 @@ class Rack::GridFSThumbTest < Test::Unit::TestCase
|
|
26
48
|
end
|
27
49
|
|
28
50
|
def test_not_called_when_not_found
|
29
|
-
@app =
|
51
|
+
@app = notfound_stub
|
30
52
|
|
31
53
|
get "/gridfs/#{@id}/100x100"
|
32
54
|
|
@@ -58,7 +80,7 @@ class Rack::GridFSThumbTest < Test::Unit::TestCase
|
|
58
80
|
|
59
81
|
private
|
60
82
|
|
61
|
-
def
|
83
|
+
def gridfs_stub
|
62
84
|
image = File.new(@image_path, 'rb')
|
63
85
|
headers = { 'Content-Length' => image.size.to_s }
|
64
86
|
Proc.new do |env|
|
@@ -66,7 +88,7 @@ class Rack::GridFSThumbTest < Test::Unit::TestCase
|
|
66
88
|
end
|
67
89
|
end
|
68
90
|
|
69
|
-
def
|
91
|
+
def notfound_stub
|
70
92
|
Proc.new do |env|
|
71
93
|
[404, { 'Content-Length' => 9 }, ['Not Found']]
|
72
94
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-gridfs-thumb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,22 +9,22 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-10-
|
12
|
+
date: 2011-10-15 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name: rack
|
16
|
-
requirement: &
|
15
|
+
name: rack-gridfs
|
16
|
+
requirement: &2152258380 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
21
|
+
version: 0.4.1
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2152258380
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: mini_magick
|
27
|
-
requirement: &
|
27
|
+
requirement: &2152257420 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '3.3'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2152257420
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rack-test
|
38
|
-
requirement: &
|
38
|
+
requirement: &2152256820 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2152256820
|
47
47
|
description: Rack middleware for resizing images served via Rack::GridFS
|
48
48
|
email:
|
49
49
|
- scottbnel@gmail.com
|
@@ -82,7 +82,7 @@ rubyforge_project:
|
|
82
82
|
rubygems_version: 1.8.10
|
83
83
|
signing_key:
|
84
84
|
specification_version: 3
|
85
|
-
summary: rack-gridfs-thumb-0.
|
85
|
+
summary: rack-gridfs-thumb-0.2.0
|
86
86
|
test_files:
|
87
87
|
- test/image.png
|
88
88
|
- test/test_gridfs_thumb.rb
|