mugshot 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -14,13 +14,13 @@ begin
14
14
  gem.homepage = "http://github.com/timebeta/mugshot"
15
15
  gem.authors = ["Cainã Nunes", "Fabrício Lopes", "Fernando Meyer", "Guilherme Cirne", "José Peleteiro"]
16
16
 
17
- ## depedencies
17
+ ## dependencies
18
18
  gems = YAML.load_file 'gems.yml'
19
19
  gems.each do |depgem|
20
20
  gem.add_dependency(depgem[:name], depgem[:version])
21
21
  end
22
22
 
23
- ## developments depedencies
23
+ ## developments dependencies
24
24
  gems = YAML.load_file 'gems_dev.yml'
25
25
  gems.each do |depgem|
26
26
  gem.add_development_dependency(depgem[:name], depgem[:version])
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -2,11 +2,11 @@ Feature: Retrieve resized image
2
2
 
3
3
  Scenario: Successful retrieval of resized image
4
4
  When I upload an image
5
- And I ask for the resized image
5
+ And I ask for the 200x200 resized image
6
6
 
7
- Then I should get the resized image
7
+ Then I should get the 200x200 resized image
8
8
 
9
9
  Scenario: Image doesn't exist
10
- When I ask for a resized image that doesn't exist
10
+ When I ask for a 200x200 resized image that doesn't exist
11
11
 
12
12
  Then I should get a 404 response
@@ -0,0 +1,22 @@
1
+ Feature: Retrieve resized image keeping aspect ratio
2
+
3
+ Scenario: Successful retrieval of resized image from given width
4
+ When I upload an image
5
+ And I ask for the 200x resized image
6
+
7
+ Then I should get the 200x resized image keeping the aspect ratio
8
+
9
+ Scenario: Successful retrieval of resized image from given height
10
+ When I upload an image
11
+ And I ask for the x200 resized image
12
+
13
+ Then I should get the x200 resized image keeping the aspect ratio
14
+
15
+ Scenario: Image doesn't exist
16
+ When I ask for a 200x resized image that doesn't exist
17
+
18
+ Then I should get a 404 response
19
+
20
+ When I ask for a x200 resized image that doesn't exist
21
+
22
+ Then I should get a 404 response
@@ -3,6 +3,15 @@ When /^I upload an image$/ do
3
3
  @image_id = last_response.body
4
4
  end
5
5
 
6
+ When /^I ask for the (.*) resized image$/ do |size|
7
+ get "/#{size}/#{@image_id}.jpg"
8
+ @retrieved_image = last_response.body
9
+ end
10
+
11
+ When /^I ask for a (.*) resized image that doesn't exist$/ do |size|
12
+ get "/#{size}/nonexistant.jpg"
13
+ end
14
+
6
15
  Then /^I should get a (\d+) response$/ do |response_code|
7
16
  last_response.status.should == response_code.to_i
8
17
  end
@@ -0,0 +1,10 @@
1
+ Then /^I should get the (.*) resized image keeping the aspect ratio$/ do |size|
2
+ dimension = Mugshot::Dimension.parse!(size)
3
+
4
+ image = Magick::Image.read('features/support/files/test.jpg').first
5
+ image.resize_to_fit!(*dimension.size)
6
+ resized_image = image.to_blob
7
+
8
+ @retrieved_image.should == resized_image
9
+ last_response.status.should == 200
10
+ end
@@ -1,14 +1,10 @@
1
- When /^I ask for the resized image$/ do
2
- get "/200x200/#{@image_id}.jpg"
3
- @retrieved_image = last_response.body
4
- end
1
+ Then /^I should get the (.*) resized image$/ do |size|
2
+ dimension = Mugshot::Dimension.parse!(size)
5
3
 
6
- When /^I ask for a resized image that doesn't exist$/ do
7
- get '/200x200/nonexistant.jpg'
8
- end
4
+ image = Magick::Image.read('features/support/files/test.jpg').first
5
+ image.resize!(*dimension.size)
6
+ resized_image = image.to_blob
9
7
 
10
- Then /^I should get the resized image$/ do
11
- resized_image = Magick::Image.read('features/support/files/test.jpg').first.resize!(200, 200).to_blob
12
8
  @retrieved_image.should == resized_image
13
9
  last_response.status.should == 200
14
10
  end
data/gems.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  - :name: activesupport
2
- :version: = 2.3.4
2
+ :version: = 2.3.5
3
3
 
4
4
  - :name: rmagick
5
5
  :version: = 2.12.2
data/gems_dev.yml CHANGED
@@ -1,14 +1,11 @@
1
- - :name: activesupport
2
- :version: = 2.3.4
3
-
4
1
  - :name: rspec
5
2
  :version: = 1.2.9
6
3
 
7
4
  - :name: cucumber
8
- :version: = 0.4.3
5
+ :version: = 0.4.4
9
6
 
10
7
  - :name: rack-test
11
- :version: = 0.5.0
8
+ :version: = 0.5.1
12
9
 
13
10
  - :name: yard
14
11
  :version: >= 0
@@ -2,6 +2,9 @@ require 'sinatra/base'
2
2
 
3
3
  class Mugshot::Application < Sinatra::Base
4
4
 
5
+ set :static, true
6
+ set :public, ::File.expand_path(::File.join(::File.dirname(__FILE__), "public"))
7
+
5
8
  before do
6
9
  content_type :jpg
7
10
  end
@@ -13,12 +16,11 @@ class Mugshot::Application < Sinatra::Base
13
16
 
14
17
  get '/:size/:id.:ext' do |size, id, ext|
15
18
  image = @storage.read(id)
19
+
16
20
  halt 404 if image.nil?
17
21
 
18
22
  dimm = Mugshot::Dimension.parse!(size)
19
-
20
- image.resize_to_fit! *dimm.size if dimm.will_keep_aspect?
21
- image.resize! *dimm.size unless dimm.will_keep_aspect?
23
+ image.resize! dimm
22
24
  image.to_blob
23
25
  end
24
26
 
@@ -28,11 +30,6 @@ class Mugshot::Application < Sinatra::Base
28
30
  image.to_blob
29
31
  end
30
32
 
31
- get '/_status' do
32
- content_type :html
33
- "OK"
34
- end
35
-
36
33
  protected
37
34
 
38
35
  def initialize(storage)
@@ -1,9 +1,11 @@
1
1
  class Mugshot::Dimension
2
2
  attr_reader :width, :height
3
3
 
4
- def self.parse!(str)
5
- data = /(\d*)x(\d*)/.match(str)
6
- new(data[1].to_i,data[2].to_i)
4
+ def self.parse!(size)
5
+ size = /(\d*)x(\d*)/.match(size)
6
+ width = size[1].to_i if size[1].present?
7
+ height = size[2].to_i if size[2].present?
8
+ new(width, height)
7
9
  end
8
10
 
9
11
  def to_s
@@ -15,7 +17,7 @@ class Mugshot::Dimension
15
17
  end
16
18
 
17
19
  def will_keep_aspect?
18
- (@width == 0) || (@height == 0)
20
+ (@width == nil) || (@height == nil)
19
21
  end
20
22
 
21
23
  def initialize (width, height)
data/lib/mugshot/image.rb CHANGED
@@ -1,11 +1,7 @@
1
1
  class Mugshot::Image
2
- def resize!(width, height = nil)
3
- height ||= width
4
- @image.resize! width, height
5
- end
6
-
7
- def resize_to_fit!(width, height = nil)
8
- @image.resize_to_fit!(width)
2
+ def resize!(dimension)
3
+ return @image.resize_to_fit! *dimension.size if dimension.will_keep_aspect?
4
+ @image.resize! dimension.width, dimension.height
9
5
  end
10
6
 
11
7
  def to_blob
@@ -13,7 +9,8 @@ class Mugshot::Image
13
9
  end
14
10
 
15
11
  protected
12
+
16
13
  def initialize(file)
17
14
  @image = Magick::Image.read(file).first
18
15
  end
19
- end
16
+ end
@@ -0,0 +1,4 @@
1
+ <?xml version=”1.0″?>
2
+ <cross-domain-policy>
3
+ <allow-access-from domain=”*” />
4
+ </cross-domain-policy>
data/mugshot.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Cain\303\243 Nunes", "Fabr\303\255cio Lopes", "Fernando Meyer", "Guilherme Cirne", "Jos\303\251 Peleteiro"]
12
- s.date = %q{2009-11-10}
12
+ s.date = %q{2009-11-30}
13
13
  s.description = %q{Image server}
14
14
  s.email = ["cainanunes@gmail.com", "fabriciolopesvital@gmail.com", "fmcamargo@gmail.com", "gcirne@gmail.com", "jose@peleteiro.net"]
15
15
  s.extra_rdoc_files = [
@@ -26,8 +26,10 @@ Gem::Specification.new do |s|
26
26
  "config.ru",
27
27
  "features/retrieve_original_image.feature",
28
28
  "features/retrieve_resized_image.feature",
29
+ "features/retrieve_resized_image_keeping_aspect_ratio.feature",
29
30
  "features/step_definitions/general_steps.rb",
30
31
  "features/step_definitions/retrieve_original_image_steps.rb",
32
+ "features/step_definitions/retrieve_resized_image_keeping_aspect_ratio_steps.rb",
31
33
  "features/step_definitions/retrieve_resized_image_steps.rb",
32
34
  "features/support/env.rb",
33
35
  "features/support/files/test.jpg",
@@ -40,6 +42,7 @@ Gem::Specification.new do |s|
40
42
  "lib/mugshot/image.rb",
41
43
  "lib/mugshot/storage.rb",
42
44
  "mugshot.gemspec",
45
+ "public/crossdomain.xml",
43
46
  "spec/files/test.jpg",
44
47
  "spec/mugshot/application_spec.rb",
45
48
  "spec/mugshot/dimension_spec.rb",
@@ -67,35 +70,32 @@ Gem::Specification.new do |s|
67
70
  s.specification_version = 3
68
71
 
69
72
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
70
- s.add_runtime_dependency(%q<activesupport>, ["= 2.3.4"])
73
+ s.add_runtime_dependency(%q<activesupport>, ["= 2.3.5"])
71
74
  s.add_runtime_dependency(%q<rmagick>, ["= 2.12.2"])
72
75
  s.add_runtime_dependency(%q<sinatra>, ["= 0.9.4"])
73
76
  s.add_runtime_dependency(%q<uuid>, ["= 2.0.2"])
74
- s.add_development_dependency(%q<activesupport>, ["= 2.3.4"])
75
77
  s.add_development_dependency(%q<rspec>, ["= 1.2.9"])
76
- s.add_development_dependency(%q<cucumber>, ["= 0.4.3"])
77
- s.add_development_dependency(%q<rack-test>, ["= 0.5.0"])
78
+ s.add_development_dependency(%q<cucumber>, ["= 0.4.4"])
79
+ s.add_development_dependency(%q<rack-test>, ["= 0.5.1"])
78
80
  s.add_development_dependency(%q<yard>, [">= 0"])
79
81
  else
80
- s.add_dependency(%q<activesupport>, ["= 2.3.4"])
82
+ s.add_dependency(%q<activesupport>, ["= 2.3.5"])
81
83
  s.add_dependency(%q<rmagick>, ["= 2.12.2"])
82
84
  s.add_dependency(%q<sinatra>, ["= 0.9.4"])
83
85
  s.add_dependency(%q<uuid>, ["= 2.0.2"])
84
- s.add_dependency(%q<activesupport>, ["= 2.3.4"])
85
86
  s.add_dependency(%q<rspec>, ["= 1.2.9"])
86
- s.add_dependency(%q<cucumber>, ["= 0.4.3"])
87
- s.add_dependency(%q<rack-test>, ["= 0.5.0"])
87
+ s.add_dependency(%q<cucumber>, ["= 0.4.4"])
88
+ s.add_dependency(%q<rack-test>, ["= 0.5.1"])
88
89
  s.add_dependency(%q<yard>, [">= 0"])
89
90
  end
90
91
  else
91
- s.add_dependency(%q<activesupport>, ["= 2.3.4"])
92
+ s.add_dependency(%q<activesupport>, ["= 2.3.5"])
92
93
  s.add_dependency(%q<rmagick>, ["= 2.12.2"])
93
94
  s.add_dependency(%q<sinatra>, ["= 0.9.4"])
94
95
  s.add_dependency(%q<uuid>, ["= 2.0.2"])
95
- s.add_dependency(%q<activesupport>, ["= 2.3.4"])
96
96
  s.add_dependency(%q<rspec>, ["= 1.2.9"])
97
- s.add_dependency(%q<cucumber>, ["= 0.4.3"])
98
- s.add_dependency(%q<rack-test>, ["= 0.5.0"])
97
+ s.add_dependency(%q<cucumber>, ["= 0.4.4"])
98
+ s.add_dependency(%q<rack-test>, ["= 0.5.1"])
99
99
  s.add_dependency(%q<yard>, [">= 0"])
100
100
  end
101
101
  end
@@ -8,12 +8,6 @@ describe Mugshot::Application do
8
8
  end
9
9
  end
10
10
 
11
- describe 'GET /_status' do
12
- get '/_status'
13
- last_response.status.should == 200
14
- last_response.body.should == 'OK'
15
- end
16
-
17
11
  describe 'POST /' do
18
12
  it "should create image" do
19
13
  file_read = nil
@@ -36,9 +30,12 @@ describe Mugshot::Application do
36
30
 
37
31
  describe 'GET /:size/:id.:ext' do
38
32
  it 'should return resized image' do
39
- image = mock('image')
33
+ dimension = mock(Mugshot::Dimension)
34
+ Mugshot::Dimension.stub!(:parse!).with('200x200').and_return(dimension)
35
+
36
+ image = mock(Mugshot::Image)
40
37
  image.stub!(:to_blob).and_return('image data')
41
- image.should_receive(:resize!).with(200, 200)
38
+ image.should_receive(:resize!).with(dimension)
42
39
  @storage.stub!(:read).with('batata').and_return(image)
43
40
 
44
41
  get '/200x200/batata.jpg'
@@ -60,7 +57,7 @@ describe Mugshot::Application do
60
57
 
61
58
  describe "GET /:id" do
62
59
  it "should return original image" do
63
- image = mock('image')
60
+ image = mock(Mugshot::Image)
64
61
  image.stub!(:to_blob).and_return('image data')
65
62
  @storage.stub!(:read).with('batata').and_return(image)
66
63
 
@@ -6,16 +6,16 @@ describe Mugshot::Dimension do
6
6
  end
7
7
 
8
8
  it "should parse a single left value" do
9
- Mugshot::Dimension.parse!("100x").size.should == [100, 0]
9
+ Mugshot::Dimension.parse!("100x").size.should == [100, nil]
10
10
  end
11
11
 
12
12
  it "should parse a single right value" do
13
- Mugshot::Dimension.parse!("x100").size.should == [0, 100]
13
+ Mugshot::Dimension.parse!("x100").size.should == [nil, 100]
14
14
  end
15
15
 
16
16
  it "should keep aspect" do
17
- Mugshot::Dimension.parse!("x100").will_keep_aspect?.should == true
18
- Mugshot::Dimension.parse!("100x").will_keep_aspect?.should == true
17
+ Mugshot::Dimension.parse!("x100").will_keep_aspect?.should be_true
18
+ Mugshot::Dimension.parse!("100x").will_keep_aspect?.should be_true
19
19
  end
20
20
 
21
21
  it "should parse and convert" do
@@ -13,23 +13,22 @@ describe Mugshot::Image do
13
13
  @magick_image.stub!(:to_blob).and_return(blob_data)
14
14
  @image.to_blob.should == blob_data
15
15
  end
16
-
17
- it 'should resize image' do
18
- width = 300
19
- height = 200
20
- @magick_image.should_receive(:resize!).with(width, height)
21
- @image.resize! width, height
22
- end
23
16
 
24
- it "should resize image with dimension" do
25
- @magick_image.should_receive(:resize!).with(300, 200)
17
+ it "should resize image to given width and height" do
18
+ @magick_image.should_receive(:resize!).with(300, 200)
26
19
  dim = Mugshot::Dimension.parse!("300x200")
27
- @image.resize! *dim.size
20
+ @image.resize! dim
28
21
  end
29
22
 
30
- it "should resize image fixed dimension" do
31
- @magick_image.should_receive(:resize_to_fit!).with(300)
23
+ it 'should resize image to fit given width' do
24
+ @magick_image.should_receive(:resize_to_fit!).with(300, nil)
32
25
  dim = Mugshot::Dimension.parse!("300x")
33
- @image.resize_to_fit! *dim.size
34
- end
26
+ @image.resize! dim
27
+ end
28
+
29
+ it 'should resize image to fit given height' do
30
+ @magick_image.should_receive(:resize_to_fit!).with(nil, 200)
31
+ dim = Mugshot::Dimension.parse!("x200")
32
+ @image.resize! dim
33
+ end
35
34
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mugshot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Cain\xC3\xA3 Nunes"
@@ -13,7 +13,7 @@ autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
15
 
16
- date: 2009-11-10 00:00:00 -02:00
16
+ date: 2009-12-04 00:00:00 -02:00
17
17
  default_executable:
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
@@ -24,7 +24,7 @@ dependencies:
24
24
  requirements:
25
25
  - - "="
26
26
  - !ruby/object:Gem::Version
27
- version: 2.3.4
27
+ version: 2.3.5
28
28
  version:
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: rmagick
@@ -56,16 +56,6 @@ dependencies:
56
56
  - !ruby/object:Gem::Version
57
57
  version: 2.0.2
58
58
  version:
59
- - !ruby/object:Gem::Dependency
60
- name: activesupport
61
- type: :development
62
- version_requirement:
63
- version_requirements: !ruby/object:Gem::Requirement
64
- requirements:
65
- - - "="
66
- - !ruby/object:Gem::Version
67
- version: 2.3.4
68
- version:
69
59
  - !ruby/object:Gem::Dependency
70
60
  name: rspec
71
61
  type: :development
@@ -84,7 +74,7 @@ dependencies:
84
74
  requirements:
85
75
  - - "="
86
76
  - !ruby/object:Gem::Version
87
- version: 0.4.3
77
+ version: 0.4.4
88
78
  version:
89
79
  - !ruby/object:Gem::Dependency
90
80
  name: rack-test
@@ -94,7 +84,7 @@ dependencies:
94
84
  requirements:
95
85
  - - "="
96
86
  - !ruby/object:Gem::Version
97
- version: 0.5.0
87
+ version: 0.5.1
98
88
  version:
99
89
  - !ruby/object:Gem::Dependency
100
90
  name: yard
@@ -130,8 +120,10 @@ files:
130
120
  - config.ru
131
121
  - features/retrieve_original_image.feature
132
122
  - features/retrieve_resized_image.feature
123
+ - features/retrieve_resized_image_keeping_aspect_ratio.feature
133
124
  - features/step_definitions/general_steps.rb
134
125
  - features/step_definitions/retrieve_original_image_steps.rb
126
+ - features/step_definitions/retrieve_resized_image_keeping_aspect_ratio_steps.rb
135
127
  - features/step_definitions/retrieve_resized_image_steps.rb
136
128
  - features/support/env.rb
137
129
  - features/support/files/test.jpg
@@ -142,6 +134,7 @@ files:
142
134
  - lib/mugshot/dimension.rb
143
135
  - lib/mugshot/fs_storage.rb
144
136
  - lib/mugshot/image.rb
137
+ - lib/mugshot/public/crossdomain.xml
145
138
  - lib/mugshot/storage.rb
146
139
  - mugshot.gemspec
147
140
  - spec/files/test.jpg