shutterbug 0.2.5 → 0.4.3

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.
Files changed (41) hide show
  1. checksums.yaml +8 -8
  2. data/.travis.yml +3 -3
  3. data/README.md +6 -0
  4. data/bower.json +1 -1
  5. data/demo/The_Scream.jpg +0 -0
  6. data/demo/canvas_example.html +36 -0
  7. data/demo/index.html +1 -0
  8. data/lib/shutterbug.rb +1 -1
  9. data/lib/shutterbug/cache_manager.rb +2 -2
  10. data/lib/shutterbug/configuration.rb +4 -8
  11. data/lib/shutterbug/handlers.rb +5 -4
  12. data/lib/shutterbug/handlers/convert_handler.rb +38 -16
  13. data/lib/shutterbug/handlers/direct_upload_handler.rb +30 -0
  14. data/lib/shutterbug/handlers/file_handler.rb +30 -0
  15. data/lib/shutterbug/handlers/js_file_handler.rb +13 -10
  16. data/lib/shutterbug/handlers/shutterbug.js +123 -32
  17. data/lib/shutterbug/phantom_job.rb +11 -10
  18. data/lib/shutterbug/rackapp.rb +15 -18
  19. data/lib/shutterbug/rasterize.js +4 -4
  20. data/lib/shutterbug/storage.rb +1 -1
  21. data/lib/shutterbug/storage/file_storage.rb +21 -8
  22. data/lib/shutterbug/storage/s3_storage.rb +26 -31
  23. data/shutterbug.gemspec +0 -1
  24. data/spec/shared_examples_for_handlers.rb +13 -9
  25. data/spec/shared_examples_for_storage.rb +14 -10
  26. data/spec/shutterbug/configuration_spec.rb +1 -11
  27. data/spec/shutterbug/convert_handler_spec.rb +5 -4
  28. data/spec/shutterbug/direct_upload_handler_spec.rb +7 -0
  29. data/spec/shutterbug/file_handler_spec.rb +7 -0
  30. data/spec/shutterbug/file_storage_spec.rb +2 -1
  31. data/spec/shutterbug/js_file_handler_spec.rb +2 -1
  32. data/spec/shutterbug/rackapp_spec.rb +14 -28
  33. data/spec/shutterbug/s3_storage_spec.rb +1 -1
  34. metadata +10 -12
  35. data/lib/shutterbug/handlers/file_handlers.rb +0 -9
  36. data/lib/shutterbug/handlers/file_handlers/base.rb +0 -39
  37. data/lib/shutterbug/handlers/file_handlers/html_file.rb +0 -22
  38. data/lib/shutterbug/handlers/file_handlers/png_file.rb +0 -23
  39. data/spec/shared_examples_for_file_handlers.rb +0 -16
  40. data/spec/shutterbug/html_file_handler_spec.rb +0 -10
  41. data/spec/shutterbug/png_file_handler_spec.rb +0 -10
@@ -0,0 +1,7 @@
1
+ require 'shared_examples_for_handlers'
2
+
3
+ describe Shutterbug::Handlers::DirectUploadHandler do
4
+ it_behaves_like "a request handler" do
5
+ let(:req) { mock(:GET => {}) }
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ require 'shared_examples_for_handlers'
2
+
3
+ describe Shutterbug::Handlers::FileHandler do
4
+ it_behaves_like "a request handler" do
5
+ let(:req) { mock(:path => "/shutterbug/get_file/foobar.png") }
6
+ end
7
+ end
@@ -1,5 +1,6 @@
1
1
  require 'shared_examples_for_storage'
2
+
2
3
  describe Shutterbug::Storage::FileStorage do
3
4
  it_behaves_like "a storage provider" do
4
5
  end
5
- end
6
+ end
@@ -1,4 +1,5 @@
1
1
  require 'shared_examples_for_handlers'
2
+
2
3
  describe Shutterbug::Handlers::JsFileHandler do
3
4
  it_behaves_like "a request handler"
4
- end
5
+ end
@@ -16,8 +16,6 @@ end
16
16
  describe Shutterbug::Rackapp do
17
17
  include Rack::Test::Methods
18
18
 
19
- let(:config) { Shutterbug::Configuration.instance }
20
-
21
19
  let(:post_data) do
22
20
  {
23
21
  'content' => "<div class='foo'>foo!</div>",
@@ -29,31 +27,31 @@ describe Shutterbug::Rackapp do
29
27
  end
30
28
 
31
29
  let(:app) do
32
- Shutterbug::Rackapp.new do |config|
33
- config.uri_prefix = "http://localhost:9292"
34
- config.path_prefix = "/shutterbug"
30
+ Shutterbug::Rackapp.new do |config|
31
+ config.uri_prefix = "http://localhost:9292"
32
+ config.path_prefix = "/shutterbug"
35
33
  end
36
34
  end
37
35
 
38
- let(:filename) { "filename" }
39
- let(:url) { "url_to_file" }
36
+ let(:filename) { "filename" }
37
+ let(:url) { "url_to_file" }
40
38
 
41
- let(:mock_file) do
39
+ let(:mock_file) do
42
40
  mock({
43
41
  :get_content => "content",
42
+ :mime_type => "image/png",
44
43
  :filename => filename,
45
44
  :url => url
46
45
  })
47
46
  end
48
47
 
49
- let(:test_storage) { mock({ :new => mock_file })}
48
+ let(:test_storage) { mock({ :new => mock_file })}
50
49
 
51
50
  before(:each) do
52
- config.stub!(:storage => test_storage)
51
+ Shutterbug::Configuration.instance.stub!(:storage => test_storage)
53
52
  end
54
53
 
55
54
  describe "routing requests in #call" do
56
-
57
55
  describe "do_convert route" do
58
56
  it "should return a valid image url" do
59
57
  get "/shutterbug/make_snapshot/", post_data
@@ -63,32 +61,20 @@ describe Shutterbug::Rackapp do
63
61
  end
64
62
  end
65
63
 
66
- describe "get png route" do
67
- it "should route #do_get_png" do
68
- Shutterbug::Configuration.instance.stub!(:storage => test_storage)
69
- get "/shutterbug/get_png/filename.png"
64
+ describe "get file route" do
65
+ it "should return without errors" do
66
+ get "/shutterbug/get_file/foobar.png"
70
67
  last_response.should be_ok
71
68
  last_response.headers['Content-Type'].should match 'image/png'
72
69
  end
73
70
  end
74
71
 
75
- describe "get html route" do
76
- it "should route #do_get_html" do
77
-
78
- get "/shutterbug/get_html/filename.html"
79
- last_response.should be_ok
80
- last_response.headers['Content-Type'].should match 'text/html'
81
- end
82
- end
83
-
84
72
  describe "get shutterbug.js javascipt route" do
85
- it "should route #do_get_shutterbug" do
73
+ it "should return js file" do
86
74
  get "/shutterbug/shutterbug.js"
87
75
  last_response.should be_ok
88
76
  last_response.headers['Content-Type'].should match 'application/javascript'
89
77
  end
90
78
  end
91
-
92
79
  end
93
-
94
- end
80
+ end
@@ -9,4 +9,4 @@ describe Shutterbug::Storage::S3Storage do
9
9
 
10
10
  it_behaves_like "a storage provider" do
11
11
  end
12
- end
12
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shutterbug
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Noah Paessel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-12 00:00:00.000000000 Z
11
+ date: 2014-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -158,6 +158,8 @@ files:
158
158
  - Rakefile
159
159
  - bower.json
160
160
  - config.ru
161
+ - demo/The_Scream.jpg
162
+ - demo/canvas_example.html
161
163
  - demo/iframe.html
162
164
  - demo/iframe2.html
163
165
  - demo/iframe3.html
@@ -180,10 +182,8 @@ files:
180
182
  - lib/shutterbug/configuration.rb
181
183
  - lib/shutterbug/handlers.rb
182
184
  - lib/shutterbug/handlers/convert_handler.rb
183
- - lib/shutterbug/handlers/file_handlers.rb
184
- - lib/shutterbug/handlers/file_handlers/base.rb
185
- - lib/shutterbug/handlers/file_handlers/html_file.rb
186
- - lib/shutterbug/handlers/file_handlers/png_file.rb
185
+ - lib/shutterbug/handlers/direct_upload_handler.rb
186
+ - lib/shutterbug/handlers/file_handler.rb
187
187
  - lib/shutterbug/handlers/js_file_handler.rb
188
188
  - lib/shutterbug/handlers/shutterbug.js
189
189
  - lib/shutterbug/phantom_job.rb
@@ -193,15 +193,14 @@ files:
193
193
  - lib/shutterbug/storage/file_storage.rb
194
194
  - lib/shutterbug/storage/s3_storage.rb
195
195
  - shutterbug.gemspec
196
- - spec/shared_examples_for_file_handlers.rb
197
196
  - spec/shared_examples_for_handlers.rb
198
197
  - spec/shared_examples_for_storage.rb
199
198
  - spec/shutterbug/configuration_spec.rb
200
199
  - spec/shutterbug/convert_handler_spec.rb
200
+ - spec/shutterbug/direct_upload_handler_spec.rb
201
+ - spec/shutterbug/file_handler_spec.rb
201
202
  - spec/shutterbug/file_storage_spec.rb
202
- - spec/shutterbug/html_file_handler_spec.rb
203
203
  - spec/shutterbug/js_file_handler_spec.rb
204
- - spec/shutterbug/png_file_handler_spec.rb
205
204
  - spec/shutterbug/rackapp_spec.rb
206
205
  - spec/shutterbug/s3_storage_spec.rb
207
206
  - spec/spec_helper.rb
@@ -230,15 +229,14 @@ signing_key:
230
229
  specification_version: 4
231
230
  summary: use Shutterbug::Rackapp
232
231
  test_files:
233
- - spec/shared_examples_for_file_handlers.rb
234
232
  - spec/shared_examples_for_handlers.rb
235
233
  - spec/shared_examples_for_storage.rb
236
234
  - spec/shutterbug/configuration_spec.rb
237
235
  - spec/shutterbug/convert_handler_spec.rb
236
+ - spec/shutterbug/direct_upload_handler_spec.rb
237
+ - spec/shutterbug/file_handler_spec.rb
238
238
  - spec/shutterbug/file_storage_spec.rb
239
- - spec/shutterbug/html_file_handler_spec.rb
240
239
  - spec/shutterbug/js_file_handler_spec.rb
241
- - spec/shutterbug/png_file_handler_spec.rb
242
240
  - spec/shutterbug/rackapp_spec.rb
243
241
  - spec/shutterbug/s3_storage_spec.rb
244
242
  - spec/spec_helper.rb
@@ -1,9 +0,0 @@
1
- module Shutterbug
2
- module Handlers
3
- module FileHandlers
4
- require "shutterbug/handlers/file_handlers/base"
5
- require "shutterbug/handlers/file_handlers/html_file"
6
- require "shutterbug/handlers/file_handlers/png_file"
7
- end
8
- end
9
- end
@@ -1,39 +0,0 @@
1
- require 'tmpdir'
2
- module Shutterbug
3
- module Handlers
4
- module FileHandlers
5
- class Base
6
- attr_accessor :config
7
-
8
- def self.instance
9
- return @instance || self.new
10
- end
11
-
12
- def initialize(_config = Configuration.instance)
13
- self.config = _config
14
- end
15
-
16
- def urlify(name)
17
- "#{self.config.uri_prefix}#{self.path_prefix}/#{name}"
18
- end
19
-
20
- def path_prefix
21
- "#{self.config.path_prefix}/get_#{file_extension}"
22
- end
23
-
24
- def filename_matcher
25
- "(([^\/|\.]+)\.?([^\/]+))?"
26
- end
27
-
28
- def regex
29
- /#{path_prefix}\/#{filename_matcher}/
30
- end
31
-
32
- def filename(base)
33
- "#{base}.#{file_extension}"
34
- end
35
-
36
- end
37
- end
38
- end
39
- end
@@ -1,22 +0,0 @@
1
- module Shutterbug
2
- module Handlers
3
- module FileHandlers
4
- class HtmlFile < Base
5
-
6
- def file_extension
7
- "html"
8
- end
9
-
10
- def mime_type
11
- "text/html"
12
- end
13
-
14
- def handle(helper, req, env)
15
- sha = regex.match(req.path)[1]
16
- file = @config.storage.new(filename(sha),self)
17
- helper.good_response(file.get_content, self.mime_type)
18
- end
19
- end
20
- end
21
- end
22
- end
@@ -1,23 +0,0 @@
1
- module Shutterbug
2
- module Handlers
3
- module FileHandlers
4
- class PngFile < Base
5
-
6
- def file_extension
7
- "png"
8
- end
9
-
10
- def mime_type
11
- "image/png"
12
- end
13
-
14
- def handle(helper, req, env)
15
- local_filename = regex.match(req.path)[1]
16
- file = @config.storage.new(local_filename,self)
17
- helper.good_response(file.get_content, self.mime_type)
18
- end
19
- end
20
- end
21
- end
22
-
23
- end
@@ -1,16 +0,0 @@
1
- require 'shared_examples_for_handlers'
2
- shared_examples "a file handler" do
3
- let(:config) { Shutterbug::Configuration.instance}
4
- let(:rackapp) { mock }
5
- let(:req) { mock }
6
- let(:env) { mock }
7
- let(:handler) { described_class.new(config) }
8
-
9
-
10
- it "should have a file extension" do
11
- handler.should respond_to :file_extension
12
- end
13
- it "should have a mime type" do
14
- handler.should respond_to :mime_type
15
- end
16
- end
@@ -1,10 +0,0 @@
1
- require 'shared_examples_for_file_handlers'
2
- require 'shared_examples_for_handlers'
3
- describe Shutterbug::Handlers::FileHandlers::HtmlFile do
4
- it_behaves_like "a file handler" do
5
- let(:req) { mock(:path => "/shutterbug/get_html/foobar.html") }
6
- end
7
- it_behaves_like "a request handler" do
8
- let(:req) { mock(:path => "/shutterbug/get_html/foobar.html") }
9
- end
10
- end
@@ -1,10 +0,0 @@
1
- require 'shared_examples_for_file_handlers'
2
- require 'shared_examples_for_handlers'
3
- describe Shutterbug::Handlers::FileHandlers::PngFile do
4
- it_behaves_like "a file handler" do
5
- let(:req) { mock(:path => "/shutterbug/get_png/foobar.png") }
6
- end
7
- it_behaves_like "a request handler" do
8
- let(:req) { mock(:path => "/shutterbug/get_png/foobar.png") }
9
- end
10
- end