citrusbyte-milton 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,11 +5,24 @@ module Milton
5
5
  class Thumbnail < Derivative
6
6
  def process
7
7
  raise "target size must be specified for resizing" unless options.has_key?(:size)
8
-
9
- temp_dst = File.join(settings[:tempfile_path], Milton::Tempfile.from(source.filename))
10
- temp_src = File.join(settings[:tempfile_path], Milton::Tempfile.from(source.filename))
11
8
 
12
- source.copy(temp_src)
9
+ temp_dst = File.join(settings[:tempfile_path], Milton::Tempfile.from(@source.filename))
10
+ temp_src = File.join(settings[:tempfile_path], Milton::Tempfile.from(@source.filename))
11
+
12
+ @source.copy(temp_src)
13
+ image = Image.from_path(temp_src)
14
+
15
+ # TODO: this really only makes sense for processing recipes, reimplement
16
+ # once it's setup to build all derivatives then push to storage
17
+ #
18
+ # For speed, any derivatives less than 640-wide are made from a
19
+ # 640-wide version of the image (so you're not generating tiny
20
+ # thumbnails from an 8-megapixel upload)
21
+ # source = if image.width > 640 && Image.from_geometry(options[:size]).width < 640
22
+ # Thumbnail.process(@source, { :size => '640x' }, settings).file
23
+ # else
24
+ # @source
25
+ # end
13
26
 
14
27
  if options[:crop]
15
28
  crop = CropCalculator.new(image, Image.from_geometry(options[:size]))
@@ -22,24 +35,5 @@ module Milton
22
35
  # TODO: raise if the store fails
23
36
  file.store(temp_dst)
24
37
  end
25
-
26
- protected
27
-
28
- # For speed, any derivatives less than 640-wide are made from a
29
- # 640-wide version of the image (so you're not generating tiny
30
- # thumbnails from an 8-megapixel upload)
31
- def source
32
- @quick_source ||= if image.width > 640 && Image.from_geometry(options[:size]).width < 640
33
- Thumbnail.process(@source, { :size => '640x' }, settings).file
34
- else
35
- @source
36
- end
37
- end
38
-
39
- # Returns and memoizes an Image initialized from the file we're making a
40
- # thumbnail of
41
- def image
42
- @image ||= Image.from_path(@source.path)
43
- end
44
38
  end
45
39
  end
@@ -44,7 +44,7 @@ module Milton
44
44
 
45
45
  # stream the download as opposed to downloading the whole thing and reading
46
46
  # it all into memory at once since it might be gigantic...
47
- s3.get(bucket_name, key) { |chunk| file.write(chunk) }
47
+ s3.get(options[:storage_options][:bucket], key) { |chunk| file.write(chunk) }
48
48
  file.close
49
49
  end
50
50
 
data/test/s3_helper.rb ADDED
@@ -0,0 +1,59 @@
1
+ require 'right_aws'
2
+
3
+ # this fakes S3 and makes it write to the file-system so we can check results
4
+ module RightAws
5
+ raise "Must define S3_ROOT with fake S3 root before requiring s3_helper" unless defined?(S3_ROOT)
6
+
7
+ class S3
8
+ def buckets
9
+ Dir.glob(S3_ROOT + '/*').collect do |bucket|
10
+ Bucket.new(self, File.basename(bucket), Time.now, Owner.new(1, 'owner'))
11
+ end
12
+ end
13
+
14
+ class Key
15
+ def put(data=nil, perms=nil, headers={})
16
+ Rails.logger.info "Putting to fake S3 store: #{filename}"
17
+ FileUtils.mkdir_p(File.join(S3_ROOT, @bucket.name, File.dirname(@name)))
18
+ FileUtils.cp(data.path, filename)
19
+ end
20
+
21
+ def delete
22
+ Rails.logger.info "Deleting from fake S3 store: #{filename}"
23
+ FileUtils.rm(filename)
24
+ end
25
+
26
+ def exists?
27
+ File.exists?(filename)
28
+ end
29
+
30
+ private
31
+
32
+ def filename
33
+ File.join(S3_ROOT, @bucket.name, @name)
34
+ end
35
+ end
36
+
37
+ class Bucket
38
+ def key(key_name, head=false)
39
+ Key.new(self, key_name, nil, {}, {}, Time.now, Time.now.to_s, 100, '', Owner.new(1, 'owner'))
40
+ end
41
+ end
42
+
43
+ class Grantee
44
+ def apply
45
+ true
46
+ end
47
+ end
48
+ end
49
+
50
+ class S3Interface < RightAwsBase
51
+ def get(bucket, key, headers={}, &block)
52
+ File.open(File.join(S3_ROOT, bucket, key), 'rb').each{ |io| block.call(io) }
53
+ end
54
+
55
+ def create_bucket(bucket, headers={})
56
+ FileUtils.mkdir_p(File.join(S3_ROOT, bucket))
57
+ end
58
+ end
59
+ end
data/test/test_helper.rb CHANGED
@@ -23,7 +23,7 @@ class ActiveSupport::TestCase
23
23
  ActiveSupport::TestCase.fixture_path = File.join(File.dirname(__FILE__), 'fixtures/')
24
24
 
25
25
  @@output_path = File.expand_path(File.join(File.dirname(__FILE__), 'output'))
26
- cattr_reader :output_path
26
+ cattr_reader :output_path
27
27
  def output_path;ActiveSupport::TestCase.output_path;end;
28
28
 
29
29
  # remove files created from previous test run, happens before instead of
@@ -60,3 +60,19 @@ class Net::HTTP
60
60
  raise "Trying to hit the interwebz!!!"
61
61
  end
62
62
  end
63
+
64
+ S3_ROOT = File.join(ActiveSupport::TestCase.output_path, 's3')
65
+ require File.join(File.dirname(__FILE__), 's3_helper')
66
+
67
+ class S3File
68
+ class << self
69
+ def path(url)
70
+ url.scan /http:\/\/(.*)\.s3.amazonaws.com\/(.*)\/(.*)/
71
+ File.join(S3_ROOT, $1, $2, $3)
72
+ end
73
+
74
+ def exists?(url)
75
+ File.exist?(path(url))
76
+ end
77
+ end
78
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: citrusbyte-milton
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Alavi
@@ -45,6 +45,7 @@ files:
45
45
  - test/milton/attachment_test.rb
46
46
  - test/milton/milton_test.rb
47
47
  - test/milton/resizing_test.rb
48
+ - test/s3_helper.rb
48
49
  - test/schema.rb
49
50
  - test/test_helper.rb
50
51
  has_rdoc: false