dragonfly 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of dragonfly might be problematic. Click here for more details.
- data/README.markdown +6 -24
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/dragonfly-rails.gemspec +5 -2
- data/dragonfly.gemspec +9 -2
- data/lib/dragonfly/data_storage/base64_data_store.rb +23 -0
- data/lib/dragonfly/data_storage/transparent_data_store.rb +21 -0
- data/lib/dragonfly/middleware.rb +2 -2
- data/lib/dragonfly/middleware_with_cache.rb +26 -0
- data/lib/dragonfly/parameters.rb +9 -4
- data/lib/dragonfly/processing/r_magick_processor.rb +14 -0
- data/lib/dragonfly/r_magick_configuration.rb +15 -0
- data/spec/dragonfly/middleware_spec.rb +4 -34
- data/spec/dragonfly/middleware_with_cache_spec.rb +14 -0
- data/spec/dragonfly/parameters_spec.rb +22 -7
- data/spec/dragonfly/processing/rmagick_processor_spec.rb +28 -0
- data/spec/dragonfly/shared_middleware_spec.rb +44 -0
- data/spec/image_matchers.rb +5 -1
- metadata +9 -2
data/README.markdown
CHANGED
@@ -10,9 +10,7 @@ For the lazy rails user
|
|
10
10
|
In environment.rb:
|
11
11
|
|
12
12
|
config.gem 'dragonfly-rails', :lib => 'dragonfly/rails/images'
|
13
|
-
config.middleware.use 'Dragonfly::
|
14
|
-
|
15
|
-
IMPORTANT: see 'Caching' below to add caching (recommended!)
|
13
|
+
config.middleware.use 'Dragonfly::MiddlewareWithCache', :images
|
16
14
|
|
17
15
|
Migration:
|
18
16
|
|
@@ -38,6 +36,8 @@ Model:
|
|
38
36
|
validates_mime_type_of :cover_image, :in => %w(image/jpeg image/png image/gif)
|
39
37
|
|
40
38
|
image_accessor :cover_image # This provides the reader/writer for cover_image
|
39
|
+
|
40
|
+
image_accessor :some_other_image # have as many as you like - each needs a xxxx_uid column as per migration above
|
41
41
|
|
42
42
|
end
|
43
43
|
|
@@ -53,30 +53,12 @@ View (for uploading via a file field):
|
|
53
53
|
View (to display):
|
54
54
|
|
55
55
|
<%= image_tag @album.cover_image.url('400x200') %>
|
56
|
-
<%= image_tag @album.cover_image.url('100x100!') %>
|
56
|
+
<%= image_tag @album.cover_image.url('100x100!', :png) %>
|
57
57
|
<%= image_tag @album.cover_image.url('100x100#') %>
|
58
|
-
<%= image_tag @album.cover_image.url('50x50+30+30sw') %>
|
58
|
+
<%= image_tag @album.cover_image.url('50x50+30+30sw', :tif) %>
|
59
|
+
<%= image_tag @album.cover_image.url(:rotate, 15) %>
|
59
60
|
...etc.
|
60
61
|
|
61
|
-
|
62
|
-
Caching
|
63
|
-
-------
|
64
|
-
|
65
|
-
All this processing and encoding on the fly is pretty expensive to perform on every page request.
|
66
|
-
Thankfully, HTTP caching comes to the rescue.
|
67
|
-
You could use any HTTP caching component such as Varnish, Squid, etc., but the quickest and easiest way is to use the excellent Rack::Cache, which should be adequate for most websites.
|
68
|
-
|
69
|
-
In that case, rather than the above, your `environment.rb` should contain something like this:
|
70
|
-
|
71
|
-
config.gem 'dragonfly-rails', :lib => 'dragonfly/rails/images'
|
72
|
-
config.gem 'rack-cache', :lib => 'rack/cache'
|
73
|
-
config.middleware.use 'Rack::Cache',
|
74
|
-
:verbose => true,
|
75
|
-
:metastore => 'file:/var/cache/rack/meta',
|
76
|
-
:entitystore => 'file:/var/cache/rack/body'
|
77
|
-
config.middleware.use 'Dragonfly::Middleware', :images
|
78
|
-
|
79
|
-
|
80
62
|
Using outside of rails, custom storage/processing/encoding/analysis, and more...
|
81
63
|
------------------------------------------------------------------------
|
82
64
|
Dragonfly is primarily a Rack app, the Rails part of it being nothing more than a separate layer on top of the main code, which means you can use it as a standalone app, or with Sinatra, Merb, etc.
|
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/dragonfly-rails.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{dragonfly-rails}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Mark Evans"]
|
12
|
-
s.date = %q{2009-11-
|
12
|
+
s.date = %q{2009-11-14}
|
13
13
|
s.email = %q{mark@new-bamboo.co.uk}
|
14
14
|
s.homepage = %q{http://github.com/markevans/dragonfly}
|
15
15
|
s.rdoc_options = ["--charset=UTF-8"]
|
@@ -24,17 +24,20 @@ Gem::Specification.new do |s|
|
|
24
24
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
25
25
|
s.add_runtime_dependency(%q<dragonfly>, [">= 0"])
|
26
26
|
s.add_runtime_dependency(%q<rack>, [">= 0"])
|
27
|
+
s.add_runtime_dependency(%q<rack-cache>, [">= 0"])
|
27
28
|
s.add_runtime_dependency(%q<mime-types>, [">= 0"])
|
28
29
|
s.add_runtime_dependency(%q<rmagick>, [">= 0"])
|
29
30
|
else
|
30
31
|
s.add_dependency(%q<dragonfly>, [">= 0"])
|
31
32
|
s.add_dependency(%q<rack>, [">= 0"])
|
33
|
+
s.add_dependency(%q<rack-cache>, [">= 0"])
|
32
34
|
s.add_dependency(%q<mime-types>, [">= 0"])
|
33
35
|
s.add_dependency(%q<rmagick>, [">= 0"])
|
34
36
|
end
|
35
37
|
else
|
36
38
|
s.add_dependency(%q<dragonfly>, [">= 0"])
|
37
39
|
s.add_dependency(%q<rack>, [">= 0"])
|
40
|
+
s.add_dependency(%q<rack-cache>, [">= 0"])
|
38
41
|
s.add_dependency(%q<mime-types>, [">= 0"])
|
39
42
|
s.add_dependency(%q<rmagick>, [">= 0"])
|
40
43
|
end
|
data/dragonfly.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{dragonfly}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Mark Evans"]
|
12
|
-
s.date = %q{2009-11-
|
12
|
+
s.date = %q{2009-11-14}
|
13
13
|
s.email = %q{mark@new-bamboo.co.uk}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"LICENSE",
|
@@ -51,11 +51,14 @@ Gem::Specification.new do |s|
|
|
51
51
|
"lib/dragonfly/core_ext/object.rb",
|
52
52
|
"lib/dragonfly/data_storage.rb",
|
53
53
|
"lib/dragonfly/data_storage/base.rb",
|
54
|
+
"lib/dragonfly/data_storage/base64_data_store.rb",
|
54
55
|
"lib/dragonfly/data_storage/file_data_store.rb",
|
56
|
+
"lib/dragonfly/data_storage/transparent_data_store.rb",
|
55
57
|
"lib/dragonfly/encoding/base.rb",
|
56
58
|
"lib/dragonfly/encoding/r_magick_encoder.rb",
|
57
59
|
"lib/dragonfly/extended_temp_object.rb",
|
58
60
|
"lib/dragonfly/middleware.rb",
|
61
|
+
"lib/dragonfly/middleware_with_cache.rb",
|
59
62
|
"lib/dragonfly/parameters.rb",
|
60
63
|
"lib/dragonfly/processing/processor.rb",
|
61
64
|
"lib/dragonfly/processing/r_magick_processor.rb",
|
@@ -82,8 +85,10 @@ Gem::Specification.new do |s|
|
|
82
85
|
"spec/dragonfly/data_storage/file_data_store_spec.rb",
|
83
86
|
"spec/dragonfly/extended_temp_object_spec.rb",
|
84
87
|
"spec/dragonfly/middleware_spec.rb",
|
88
|
+
"spec/dragonfly/middleware_with_cache_spec.rb",
|
85
89
|
"spec/dragonfly/parameters_spec.rb",
|
86
90
|
"spec/dragonfly/processing/rmagick_processor_spec.rb",
|
91
|
+
"spec/dragonfly/shared_middleware_spec.rb",
|
87
92
|
"spec/dragonfly/temp_object_spec.rb",
|
88
93
|
"spec/dragonfly/url_handler_spec.rb",
|
89
94
|
"spec/dragonfly_spec.rb",
|
@@ -112,8 +117,10 @@ Gem::Specification.new do |s|
|
|
112
117
|
"spec/dragonfly/data_storage/file_data_store_spec.rb",
|
113
118
|
"spec/dragonfly/extended_temp_object_spec.rb",
|
114
119
|
"spec/dragonfly/middleware_spec.rb",
|
120
|
+
"spec/dragonfly/middleware_with_cache_spec.rb",
|
115
121
|
"spec/dragonfly/parameters_spec.rb",
|
116
122
|
"spec/dragonfly/processing/rmagick_processor_spec.rb",
|
123
|
+
"spec/dragonfly/shared_middleware_spec.rb",
|
117
124
|
"spec/dragonfly/temp_object_spec.rb",
|
118
125
|
"spec/dragonfly/url_handler_spec.rb",
|
119
126
|
"spec/dragonfly_spec.rb",
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "base64"
|
2
|
+
|
3
|
+
module Dragonfly
|
4
|
+
module DataStorage
|
5
|
+
|
6
|
+
class Base64DataStore < Base
|
7
|
+
|
8
|
+
def store(temp_object)
|
9
|
+
Base64.encode64(temp_object.data)
|
10
|
+
end
|
11
|
+
|
12
|
+
def retrieve(uid)
|
13
|
+
Base64.decode64(uid)
|
14
|
+
end
|
15
|
+
|
16
|
+
def destroy(uid)
|
17
|
+
# Nothing to destroy!
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Dragonfly
|
2
|
+
module DataStorage
|
3
|
+
|
4
|
+
class TransparentDataStore < Base
|
5
|
+
|
6
|
+
def store(temp_object)
|
7
|
+
temp_object.data
|
8
|
+
end
|
9
|
+
|
10
|
+
def retrieve(uid)
|
11
|
+
uid
|
12
|
+
end
|
13
|
+
|
14
|
+
def destroy(uid)
|
15
|
+
# Nothing to destroy!
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
data/lib/dragonfly/middleware.rb
CHANGED
@@ -8,7 +8,7 @@ module Dragonfly
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def call(env)
|
11
|
-
response =
|
11
|
+
response = endpoint.call(env)
|
12
12
|
if response[0] == 404
|
13
13
|
@app.call(env)
|
14
14
|
else
|
@@ -18,7 +18,7 @@ module Dragonfly
|
|
18
18
|
|
19
19
|
private
|
20
20
|
|
21
|
-
def
|
21
|
+
def endpoint
|
22
22
|
App[@dragonfly_app_name]
|
23
23
|
end
|
24
24
|
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rack/cache'
|
2
|
+
|
3
|
+
module Dragonfly
|
4
|
+
class MiddlewareWithCache < Middleware
|
5
|
+
|
6
|
+
def initialize(app, dragonfly_app_name, rack_cache_opts={})
|
7
|
+
super(app, dragonfly_app_name)
|
8
|
+
@rack_cache_opts = {
|
9
|
+
:verbose => true,
|
10
|
+
:metastore => 'file:/var/cache/rack/meta',
|
11
|
+
:entitystore => 'file:/var/cache/rack/body'
|
12
|
+
}.merge(rack_cache_opts)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def endpoint
|
18
|
+
rack_cache_opts = @rack_cache_opts
|
19
|
+
@endpoint ||= Rack::Builder.new do
|
20
|
+
use Rack::Cache, rack_cache_opts
|
21
|
+
run super
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
data/lib/dragonfly/parameters.rb
CHANGED
@@ -19,7 +19,7 @@ module Dragonfly
|
|
19
19
|
|
20
20
|
def add_shortcut(*args, &block)
|
21
21
|
if block
|
22
|
-
block_shortcuts_of_length(args.length)
|
22
|
+
block_shortcuts_of_length(args.length).unshift([args, block])
|
23
23
|
else
|
24
24
|
shortcut_name, attributes = args
|
25
25
|
simple_shortcuts[shortcut_name] = attributes
|
@@ -27,15 +27,20 @@ module Dragonfly
|
|
27
27
|
end
|
28
28
|
configuration_method :add_shortcut
|
29
29
|
|
30
|
-
def
|
30
|
+
def hash_from_shortcut(*args)
|
31
31
|
if attributes = matching_simple_shortcut(args)
|
32
|
-
|
32
|
+
attributes
|
33
33
|
elsif attributes = matching_block_shortcut(args)
|
34
|
-
|
34
|
+
attributes
|
35
35
|
else
|
36
36
|
raise InvalidShortcut, "No shortcut was found matching (#{args.map{|a| a.inspect }.join(', ')})"
|
37
37
|
end
|
38
38
|
end
|
39
|
+
configuration_method :hash_from_shortcut
|
40
|
+
|
41
|
+
def from_shortcut(*args)
|
42
|
+
new(hash_from_shortcut(*args))
|
43
|
+
end
|
39
44
|
|
40
45
|
def from_args(*args)
|
41
46
|
if args.empty? then new
|
@@ -50,6 +50,20 @@ module Dragonfly
|
|
50
50
|
image.resize_to_fill(width, height, gravity).to_blob
|
51
51
|
end
|
52
52
|
|
53
|
+
def rotate(temp_object, opts={})
|
54
|
+
if opts[:amount]
|
55
|
+
args = [opts[:amount].to_f]
|
56
|
+
args << opts[:qualifier] if opts[:qualifier]
|
57
|
+
image = rmagick_image(temp_object)
|
58
|
+
image.background_color = opts[:background_colour] if opts[:background_colour]
|
59
|
+
image.background_color = opts[:background_color] if opts[:background_color]
|
60
|
+
rotated_image = image.rotate(*args)
|
61
|
+
rotated_image ? rotated_image.to_blob : temp_object
|
62
|
+
else
|
63
|
+
temp_object
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
53
67
|
def vignette(temp_object, opts={})
|
54
68
|
x = opts[:x].to_f || temp_object.width * 0.1
|
55
69
|
y = opts[:y].to_f || temp_object.height * 0.1
|
@@ -14,6 +14,9 @@ module Dragonfly
|
|
14
14
|
c.parameters do |p|
|
15
15
|
p.default_format = :jpg
|
16
16
|
# Standard resizing like '30x40!', etc.
|
17
|
+
p.add_shortcut(Symbol) do |format|
|
18
|
+
{:format => format}
|
19
|
+
end
|
17
20
|
p.add_shortcut(/^\d*x\d*[><%^!]?$|^\d+@$/) do |geometry, match_data|
|
18
21
|
{
|
19
22
|
:processing_method => :resize,
|
@@ -40,6 +43,18 @@ module Dragonfly
|
|
40
43
|
}
|
41
44
|
}
|
42
45
|
end
|
46
|
+
p.add_shortcut(/^\d*x/, Symbol) do |geometry, format|
|
47
|
+
p.hash_from_shortcut(geometry).merge(:format => format)
|
48
|
+
end
|
49
|
+
p.add_shortcut(:rotate, Numeric) do |_, amount|
|
50
|
+
{
|
51
|
+
:processing_method => :rotate,
|
52
|
+
:processing_options => {:amount => amount, :background_colour => '#0000'}
|
53
|
+
}
|
54
|
+
end
|
55
|
+
p.add_shortcut(:rotate, Numeric, Symbol) do |a, b, format|
|
56
|
+
p.hash_from_shortcut(a,b).merge(:format => format)
|
57
|
+
end
|
43
58
|
end
|
44
59
|
end
|
45
60
|
end
|
@@ -1,44 +1,14 @@
|
|
1
|
-
require File.dirname(__FILE__) + '
|
2
|
-
require 'rack'
|
1
|
+
require File.dirname(__FILE__) + '/shared_middleware_spec'
|
3
2
|
|
4
3
|
describe Dragonfly::Middleware do
|
5
4
|
|
6
|
-
def make_request(app, url)
|
7
|
-
Rack::MockRequest.new(app).get(url)
|
8
|
-
end
|
9
|
-
|
10
5
|
before(:each) do
|
11
6
|
@stack = Rack::Builder.new do
|
12
7
|
use Dragonfly::Middleware, :images
|
13
|
-
run
|
8
|
+
run dummy_rack_app
|
14
9
|
end
|
15
10
|
end
|
16
11
|
|
17
|
-
|
18
|
-
Dragonfly::App[:images].should_receive(:call).and_return(
|
19
|
-
[404, {"Content-Type" => 'text/plain'}, ['Not found']]
|
20
|
-
)
|
21
|
-
response = make_request(@stack, 'hello.png?howare=you')
|
22
|
-
response.status.should == 200
|
23
|
-
response.body.should == 'hello.png, howare=you'
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should return as per the dragonfly app if the app returns a 200" do
|
27
|
-
Dragonfly::App[:images].should_receive(:call).and_return(
|
28
|
-
[200, {"Content-Type" => 'text/plain'}, ['ABCD']]
|
29
|
-
)
|
30
|
-
response = make_request(@stack, 'hello.png?howare=you')
|
31
|
-
response.status.should == 200
|
32
|
-
response.body.should == 'ABCD'
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should return as per the dragonfly app if the app returns a 400" do
|
36
|
-
Dragonfly::App[:images].should_receive(:call).and_return(
|
37
|
-
[400, {"Content-Type" => 'text/plain'}, ['ABCD']]
|
38
|
-
)
|
39
|
-
response = make_request(@stack, 'hello.png?howare=you')
|
40
|
-
response.status.should == 400
|
41
|
-
response.body.should == 'ABCD'
|
42
|
-
end
|
12
|
+
it_should_behave_like 'dragonfly middleware'
|
43
13
|
|
44
|
-
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/shared_middleware_spec'
|
2
|
+
|
3
|
+
describe Dragonfly::MiddlewareWithCache do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@stack = Rack::Builder.new do
|
7
|
+
use Dragonfly::MiddlewareWithCache, :images
|
8
|
+
run dummy_rack_app
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
it_should_behave_like 'dragonfly middleware'
|
13
|
+
|
14
|
+
end
|
@@ -168,12 +168,12 @@ describe Dragonfly::Parameters do
|
|
168
168
|
:encoding => {:doogie => :howser}
|
169
169
|
}
|
170
170
|
@parameters_class.add_shortcut(:doobie, attributes)
|
171
|
-
@parameters_class.
|
171
|
+
@parameters_class.hash_from_shortcut(:doobie).should == attributes
|
172
172
|
end
|
173
173
|
|
174
174
|
it "should raise an error if the shortcut doesn't exist" do
|
175
175
|
lambda{
|
176
|
-
@parameters_class.
|
176
|
+
@parameters_class.hash_from_shortcut(:idontexist)
|
177
177
|
}.should raise_error(Dragonfly::Parameters::InvalidShortcut)
|
178
178
|
end
|
179
179
|
|
@@ -186,22 +186,28 @@ describe Dragonfly::Parameters do
|
|
186
186
|
end
|
187
187
|
|
188
188
|
it "should allow for more complex shortcuts by using a block and matching args" do
|
189
|
-
|
190
|
-
@parameters_class.from_shortcut('hellothere', :tif).should == parameters
|
189
|
+
@parameters_class.hash_from_shortcut('hellothere', :tif).should == {:processing_method => 'hellothere', :format => :tif}
|
191
190
|
end
|
192
191
|
|
193
192
|
it "should raise an error if the shortcut doesn't match properly" do
|
194
193
|
lambda{
|
195
|
-
@parameters_class.
|
194
|
+
@parameters_class.hash_from_shortcut('hellothere', 'tif')
|
196
195
|
}.should raise_error(Dragonfly::Parameters::InvalidShortcut)
|
197
196
|
end
|
198
197
|
|
199
198
|
it "should raise an error if the shortcut matches but has the wrong number of args" do
|
200
199
|
lambda{
|
201
|
-
@parameters_class.
|
200
|
+
@parameters_class.hash_from_shortcut('hellothere', :tif, 'YO')
|
202
201
|
}.should raise_error(Dragonfly::Parameters::InvalidShortcut)
|
203
202
|
end
|
204
203
|
|
204
|
+
it "should let later shortcuts have priority over earlier ones" do
|
205
|
+
@parameters_class.add_shortcut(/hello/, :tif) do |a, b|
|
206
|
+
{:processing_method => :bumble}
|
207
|
+
end
|
208
|
+
@parameters_class.hash_from_shortcut('hellothere', :tif).should == {:processing_method => :bumble}
|
209
|
+
end
|
210
|
+
|
205
211
|
end
|
206
212
|
|
207
213
|
describe "single regexp shortcuts" do
|
@@ -210,7 +216,7 @@ describe Dragonfly::Parameters do
|
|
210
216
|
@parameters_class.add_shortcut(/^hello(.*)$/) do |arg, match_data|
|
211
217
|
{:processing_options => {:arg => arg, :match_data => match_data}}
|
212
218
|
end
|
213
|
-
processing_options = @parameters_class.
|
219
|
+
processing_options = @parameters_class.hash_from_shortcut('hellothere')[:processing_options]
|
214
220
|
processing_options[:arg].should == 'hellothere'
|
215
221
|
processing_options[:match_data].should be_a(MatchData)
|
216
222
|
processing_options[:match_data][1].should == 'there'
|
@@ -218,6 +224,15 @@ describe Dragonfly::Parameters do
|
|
218
224
|
|
219
225
|
end
|
220
226
|
|
227
|
+
describe ".from_shortcut" do
|
228
|
+
it "should just be the parameters equivalent of 'hash_from_shortcut'" do
|
229
|
+
@parameters_class.add_shortcut(/^hello.*$/, Symbol) do |processing_method, format, matches|
|
230
|
+
{:processing_method => processing_method, :format => format}
|
231
|
+
end
|
232
|
+
@parameters_class.from_shortcut('hellothere', :tif).should == @parameters_class.new(@parameters_class.hash_from_shortcut('hellothere', :tif))
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
221
236
|
end
|
222
237
|
|
223
238
|
describe ".from_args" do
|
@@ -145,4 +145,32 @@ describe Dragonfly::Processing::RMagickProcessor do
|
|
145
145
|
|
146
146
|
end
|
147
147
|
|
148
|
+
describe "rotate" do
|
149
|
+
|
150
|
+
it "should rotate by 90 degrees" do
|
151
|
+
image = @processor.rotate(@image, :amount => '90')
|
152
|
+
image.should have_width(355)
|
153
|
+
image.should have_height(280)
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should not rotate given a larger height and the '>' qualifier" do
|
157
|
+
image = @processor.rotate(@image, :amount => 90, :qualifier => '>')
|
158
|
+
image.should have_width(280)
|
159
|
+
image.should have_height(355)
|
160
|
+
end
|
161
|
+
|
162
|
+
it "should rotate given a larger height and the '<' qualifier" do
|
163
|
+
image = @processor.rotate(@image, :amount => 90, :qualifier => '<')
|
164
|
+
image.should have_width(355)
|
165
|
+
image.should have_height(280)
|
166
|
+
end
|
167
|
+
|
168
|
+
it "should do nothing if no amount given" do
|
169
|
+
image = @processor.rotate(@image)
|
170
|
+
image.should have_width(280)
|
171
|
+
image.should have_height(355)
|
172
|
+
end
|
173
|
+
|
174
|
+
end
|
175
|
+
|
148
176
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
require 'rack'
|
3
|
+
|
4
|
+
def dummy_rack_app
|
5
|
+
lambda{|env| [200, {"Content-Type" => "text/html"}, ["#{env['PATH_INFO']}, #{env['QUERY_STRING']}"]] }
|
6
|
+
end
|
7
|
+
|
8
|
+
|
9
|
+
describe "dragonfly middleware", :shared => true do
|
10
|
+
|
11
|
+
# REQUIRES THAT @stack and Dragonfly::App[:images] IS DEFINED
|
12
|
+
|
13
|
+
def make_request(app, url)
|
14
|
+
Rack::MockRequest.new(app).get(url)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should continue the calling chain if the app returns a 404 for that url" do
|
18
|
+
Dragonfly::App[:images].should_receive(:call).and_return(
|
19
|
+
[404, {"Content-Type" => 'text/plain'}, ['Not found']]
|
20
|
+
)
|
21
|
+
response = make_request(@stack, 'hello.png?howare=you')
|
22
|
+
response.status.should == 200
|
23
|
+
response.body.should == 'hello.png, howare=you'
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should return as per the dragonfly app if the app returns a 200" do
|
27
|
+
Dragonfly::App[:images].should_receive(:call).and_return(
|
28
|
+
[200, {"Content-Type" => 'text/plain'}, ['ABCD']]
|
29
|
+
)
|
30
|
+
response = make_request(@stack, 'hello.png?howare=you')
|
31
|
+
response.status.should == 200
|
32
|
+
response.body.should == 'ABCD'
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should return as per the dragonfly app if the app returns a 400" do
|
36
|
+
Dragonfly::App[:images].should_receive(:call).and_return(
|
37
|
+
[400, {"Content-Type" => 'text/plain'}, ['ABCD']]
|
38
|
+
)
|
39
|
+
response = make_request(@stack, 'hello.png?howare=you')
|
40
|
+
response.status.should == 400
|
41
|
+
response.body.should == 'ABCD'
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
data/spec/image_matchers.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dragonfly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Evans
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11-
|
12
|
+
date: 2009-11-14 00:00:00 +00:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -67,11 +67,14 @@ files:
|
|
67
67
|
- lib/dragonfly/core_ext/object.rb
|
68
68
|
- lib/dragonfly/data_storage.rb
|
69
69
|
- lib/dragonfly/data_storage/base.rb
|
70
|
+
- lib/dragonfly/data_storage/base64_data_store.rb
|
70
71
|
- lib/dragonfly/data_storage/file_data_store.rb
|
72
|
+
- lib/dragonfly/data_storage/transparent_data_store.rb
|
71
73
|
- lib/dragonfly/encoding/base.rb
|
72
74
|
- lib/dragonfly/encoding/r_magick_encoder.rb
|
73
75
|
- lib/dragonfly/extended_temp_object.rb
|
74
76
|
- lib/dragonfly/middleware.rb
|
77
|
+
- lib/dragonfly/middleware_with_cache.rb
|
75
78
|
- lib/dragonfly/parameters.rb
|
76
79
|
- lib/dragonfly/processing/processor.rb
|
77
80
|
- lib/dragonfly/processing/r_magick_processor.rb
|
@@ -98,8 +101,10 @@ files:
|
|
98
101
|
- spec/dragonfly/data_storage/file_data_store_spec.rb
|
99
102
|
- spec/dragonfly/extended_temp_object_spec.rb
|
100
103
|
- spec/dragonfly/middleware_spec.rb
|
104
|
+
- spec/dragonfly/middleware_with_cache_spec.rb
|
101
105
|
- spec/dragonfly/parameters_spec.rb
|
102
106
|
- spec/dragonfly/processing/rmagick_processor_spec.rb
|
107
|
+
- spec/dragonfly/shared_middleware_spec.rb
|
103
108
|
- spec/dragonfly/temp_object_spec.rb
|
104
109
|
- spec/dragonfly/url_handler_spec.rb
|
105
110
|
- spec/dragonfly_spec.rb
|
@@ -150,8 +155,10 @@ test_files:
|
|
150
155
|
- spec/dragonfly/data_storage/file_data_store_spec.rb
|
151
156
|
- spec/dragonfly/extended_temp_object_spec.rb
|
152
157
|
- spec/dragonfly/middleware_spec.rb
|
158
|
+
- spec/dragonfly/middleware_with_cache_spec.rb
|
153
159
|
- spec/dragonfly/parameters_spec.rb
|
154
160
|
- spec/dragonfly/processing/rmagick_processor_spec.rb
|
161
|
+
- spec/dragonfly/shared_middleware_spec.rb
|
155
162
|
- spec/dragonfly/temp_object_spec.rb
|
156
163
|
- spec/dragonfly/url_handler_spec.rb
|
157
164
|
- spec/dragonfly_spec.rb
|