scale_down 0.5.0 → 0.5.2
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/CHANGES +7 -0
- data/README.rdoc +7 -0
- data/lib/scale_down/controller.rb +3 -0
- data/lib/scale_down/dispatcher.rb +6 -2
- data/lib/scale_down/version.rb +1 -1
- data/test/scale_down/controller_test.rb +9 -1
- data/test/scale_down/dispatcher_test.rb +18 -0
- data/test/scale_down_test.rb +0 -1
- metadata +65 -73
- data/.bundle/config +0 -1
data/CHANGES
CHANGED
data/README.rdoc
CHANGED
@@ -79,6 +79,13 @@ HMAC requires a shared key between the application generating the URL and the Sc
|
|
79
79
|
return [global.$FD.assetHost, absolute_path, '/scaled', "/", geometry, "/",escape(filename)].join("") + "?"+ signature
|
80
80
|
}
|
81
81
|
|
82
|
+
== Images: PNGs, JPGs, Tiffs and others
|
83
|
+
|
84
|
+
ScaleDown will handle any image that Image Magick can process. But there are some rules:
|
85
|
+
|
86
|
+
* PNGs remain PNGs and JPGs remain JPGS
|
87
|
+
* All other images are converted to JPG and issued a 301 redirect
|
88
|
+
|
82
89
|
== Installation and Configuration
|
83
90
|
|
84
91
|
gem install scale_down
|
@@ -33,6 +33,9 @@ class ScaleDown::Controller < Sinatra::Application
|
|
33
33
|
|
34
34
|
ScaleDown.logger.info "Controller#get #{path} #{status}"
|
35
35
|
case status
|
36
|
+
when 301 then
|
37
|
+
# original is not a png/jpg redirect to jpg
|
38
|
+
redirect URI.encode(path), status
|
36
39
|
when 302 then
|
37
40
|
# File is found or scaled, use Sinatra's built in send file method
|
38
41
|
static!
|
@@ -10,12 +10,12 @@ class ScaleDown::Dispatcher
|
|
10
10
|
ScaleDown.logger.info "Dipatcher#process #{dispatcher.root_path}"
|
11
11
|
|
12
12
|
return ["Missing file", 404] unless dispatcher.root_file_exists?
|
13
|
-
return [dispatcher.redirect_path,
|
13
|
+
return [dispatcher.redirect_path, dispatcher.redirect_code] if dispatcher.scaled_file_exists?
|
14
14
|
|
15
15
|
return ["Invalid HMAC signature", 403] unless dispatcher.valid_hmac?
|
16
16
|
return ["File failed to scale. The file may be corrupt.", 500] unless dispatcher.scale
|
17
17
|
|
18
|
-
[dispatcher.redirect_path,
|
18
|
+
[dispatcher.redirect_path, dispatcher.redirect_code]
|
19
19
|
end
|
20
20
|
|
21
21
|
# TODO return a JSON response with a full set of image details
|
@@ -54,6 +54,10 @@ class ScaleDown::Dispatcher
|
|
54
54
|
ScaleDown.valid_hmac?(@params)
|
55
55
|
end
|
56
56
|
|
57
|
+
def redirect_code
|
58
|
+
@params[:filename].match(/(png|jpg)$/) ? 302 : 301
|
59
|
+
end
|
60
|
+
|
57
61
|
def redirect_path
|
58
62
|
["/"+@params[:path], @params[:geometry], scaled_filename].join("/")
|
59
63
|
end
|
data/lib/scale_down/version.rb
CHANGED
@@ -21,12 +21,20 @@ class ScaleDown::Controller::Test < Test::Unit::TestCase
|
|
21
21
|
end
|
22
22
|
|
23
23
|
context "a valid request" do
|
24
|
-
should "
|
24
|
+
should "send the file" do
|
25
25
|
ScaleDown::Dispatcher.expects(:process).returns ["/image-path", 302]
|
26
26
|
get "/path/geo/filename?hmac"
|
27
27
|
|
28
28
|
assert_equal 200, last_response.status
|
29
29
|
end
|
30
|
+
|
31
|
+
should "redirect to the image path for non png or jpg original imags" do
|
32
|
+
ScaleDown::Dispatcher.expects(:process).returns ["/image-path", 301]
|
33
|
+
get "/path/geo/filename?hmac"
|
34
|
+
|
35
|
+
assert_equal 301, last_response.status
|
36
|
+
assert_equal "http://example.org/image-path", last_response["Location"]
|
37
|
+
end
|
30
38
|
end
|
31
39
|
|
32
40
|
context "an invalid request" do
|
@@ -67,6 +67,24 @@ class ScaleDown::Dispatcher::Test < Test::Unit::TestCase
|
|
67
67
|
dispatcher = ScaleDown::Dispatcher.new @params.merge(:filename => "test.png")
|
68
68
|
assert_match /\.png$/, dispatcher.scaled_file_path
|
69
69
|
end
|
70
|
+
|
71
|
+
should "use a jpeg for all non png images" do
|
72
|
+
dispatcher = ScaleDown::Dispatcher.new @params.merge(:filename => "test.tif")
|
73
|
+
assert_match /\.jpg$/, dispatcher.scaled_file_path
|
74
|
+
assert_match /\.jpg$/, dispatcher.redirect_path
|
75
|
+
end
|
76
|
+
|
77
|
+
context "redirect_code" do
|
78
|
+
should "be 302 for png and jpgs" do
|
79
|
+
dispatcher = ScaleDown::Dispatcher.new @params
|
80
|
+
assert_equal 302, dispatcher.redirect_code
|
81
|
+
end
|
82
|
+
|
83
|
+
should "be 301 for non png or jpgs " do
|
84
|
+
dispatcher = ScaleDown::Dispatcher.new @params.merge(:filename => "test.tif")
|
85
|
+
assert_equal 301, dispatcher.redirect_code
|
86
|
+
end
|
87
|
+
end
|
70
88
|
end
|
71
89
|
|
72
90
|
context "process response" do
|
data/test/scale_down_test.rb
CHANGED
@@ -62,7 +62,6 @@ class ScaleDown::Test < Test::Unit::TestCase
|
|
62
62
|
valid_get '/test_images/example_1/scaled/400x300-cropped/graphic.png'
|
63
63
|
assert_equal 200, last_response.status
|
64
64
|
assert File.exists?("/tmp/scale_down/test_images/example_1/scaled/400x300-cropped/graphic.png")
|
65
|
-
assert_match "/test_images/example_1/scaled/400x300-cropped/graphic.png", last_response["Location"]
|
66
65
|
end
|
67
66
|
|
68
67
|
should "get a nonexistant image and return a 404" do
|
metadata
CHANGED
@@ -1,94 +1,89 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: scale_down
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.2
|
4
5
|
prerelease:
|
5
|
-
version: 0.5.0
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- John Weir
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2011-12-15 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
16
15
|
name: rmagick
|
17
|
-
|
18
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &2165822980 !ruby/object:Gem::Requirement
|
19
17
|
none: false
|
20
|
-
requirements:
|
21
|
-
- -
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version:
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '2.1'
|
24
22
|
type: :runtime
|
25
|
-
version_requirements: *id001
|
26
|
-
- !ruby/object:Gem::Dependency
|
27
|
-
name: sinatra
|
28
23
|
prerelease: false
|
29
|
-
|
24
|
+
version_requirements: *2165822980
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: sinatra
|
27
|
+
requirement: &2165822480 !ruby/object:Gem::Requirement
|
30
28
|
none: false
|
31
|
-
requirements:
|
32
|
-
- -
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version:
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '1.0'
|
35
33
|
type: :runtime
|
36
|
-
version_requirements: *id002
|
37
|
-
- !ruby/object:Gem::Dependency
|
38
|
-
name: ruby-hmac
|
39
34
|
prerelease: false
|
40
|
-
|
35
|
+
version_requirements: *2165822480
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: ruby-hmac
|
38
|
+
requirement: &2165822020 !ruby/object:Gem::Requirement
|
41
39
|
none: false
|
42
|
-
requirements:
|
43
|
-
- -
|
44
|
-
- !ruby/object:Gem::Version
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
45
43
|
version: 0.4.0
|
46
44
|
type: :runtime
|
47
|
-
version_requirements: *id003
|
48
|
-
- !ruby/object:Gem::Dependency
|
49
|
-
name: contest
|
50
45
|
prerelease: false
|
51
|
-
|
46
|
+
version_requirements: *2165822020
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: contest
|
49
|
+
requirement: &2165821560 !ruby/object:Gem::Requirement
|
52
50
|
none: false
|
53
|
-
requirements:
|
54
|
-
- -
|
55
|
-
- !ruby/object:Gem::Version
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
56
54
|
version: 0.1.2
|
57
55
|
type: :development
|
58
|
-
version_requirements: *id004
|
59
|
-
- !ruby/object:Gem::Dependency
|
60
|
-
name: mocha
|
61
56
|
prerelease: false
|
62
|
-
|
57
|
+
version_requirements: *2165821560
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: mocha
|
60
|
+
requirement: &2165851280 !ruby/object:Gem::Requirement
|
63
61
|
none: false
|
64
|
-
requirements:
|
65
|
-
- -
|
66
|
-
- !ruby/object:Gem::Version
|
62
|
+
requirements:
|
63
|
+
- - =
|
64
|
+
- !ruby/object:Gem::Version
|
67
65
|
version: 0.9.8
|
68
66
|
type: :development
|
69
|
-
version_requirements: *id005
|
70
|
-
- !ruby/object:Gem::Dependency
|
71
|
-
name: rack-test
|
72
67
|
prerelease: false
|
73
|
-
|
68
|
+
version_requirements: *2165851280
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rack-test
|
71
|
+
requirement: &2165850820 !ruby/object:Gem::Requirement
|
74
72
|
none: false
|
75
|
-
requirements:
|
76
|
-
- -
|
77
|
-
- !ruby/object:Gem::Version
|
73
|
+
requirements:
|
74
|
+
- - =
|
75
|
+
- !ruby/object:Gem::Version
|
78
76
|
version: 0.5.6
|
79
77
|
type: :development
|
80
|
-
|
81
|
-
|
82
|
-
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *2165850820
|
80
|
+
description: ''
|
81
|
+
email:
|
83
82
|
- john@famedriver.com
|
84
83
|
executables: []
|
85
|
-
|
86
84
|
extensions: []
|
87
|
-
|
88
85
|
extra_rdoc_files: []
|
89
|
-
|
90
|
-
files:
|
91
|
-
- .bundle/config
|
86
|
+
files:
|
92
87
|
- .gitignore
|
93
88
|
- CHANGES
|
94
89
|
- Gemfile
|
@@ -119,32 +114,29 @@ files:
|
|
119
114
|
- test/test_helper.rb
|
120
115
|
homepage: http://github.com/jweir/ScaleDown
|
121
116
|
licenses: []
|
122
|
-
|
123
117
|
post_install_message:
|
124
118
|
rdoc_options: []
|
125
|
-
|
126
|
-
require_paths:
|
119
|
+
require_paths:
|
127
120
|
- lib
|
128
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
129
122
|
none: false
|
130
|
-
requirements:
|
131
|
-
- -
|
132
|
-
- !ruby/object:Gem::Version
|
133
|
-
version:
|
134
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ! '>='
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
128
|
none: false
|
136
|
-
requirements:
|
137
|
-
- -
|
138
|
-
- !ruby/object:Gem::Version
|
139
|
-
version:
|
129
|
+
requirements:
|
130
|
+
- - ! '>='
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
140
133
|
requirements: []
|
141
|
-
|
142
134
|
rubyforge_project: scale_down
|
143
135
|
rubygems_version: 1.8.8
|
144
136
|
signing_key:
|
145
137
|
specification_version: 3
|
146
138
|
summary: A Sinatra based server for quickly scaling and serving images. Nothing more.
|
147
|
-
test_files:
|
139
|
+
test_files:
|
148
140
|
- test/files/cmyk.tif
|
149
141
|
- test/files/cmyk_gray.jpg
|
150
142
|
- test/files/graphic.png
|
data/.bundle/config
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--- {}
|