cloudfuji_paperclip 2.4.6 → 3.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/.travis.yml +9 -6
- data/Appraisals +6 -6
- data/CONTRIBUTING.md +34 -2
- data/Gemfile +2 -0
- data/NEWS +90 -0
- data/README.md +62 -29
- data/RUNNING_TESTS.md +4 -0
- data/Rakefile +7 -2
- data/UPGRADING +14 -0
- data/features/basic_integration.feature +11 -7
- data/features/rake_tasks.feature +1 -1
- data/features/step_definitions/attachment_steps.rb +11 -2
- data/features/step_definitions/rails_steps.rb +17 -79
- data/features/support/env.rb +3 -0
- data/features/support/fakeweb.rb +7 -0
- data/features/support/file_helpers.rb +24 -0
- data/features/support/rails.rb +3 -3
- data/gemfiles/{rails3_1.gemfile → 3.0.gemfile} +3 -1
- data/gemfiles/{rails2.gemfile → 3.1.gemfile} +3 -1
- data/gemfiles/{rails3.gemfile → 3.2.gemfile} +3 -1
- data/images.rake +21 -0
- data/lib/cloudfuji_paperclip.rb +1 -0
- data/lib/generators/paperclip/paperclip_generator.rb +1 -2
- data/lib/paperclip.rb +54 -319
- data/lib/paperclip/attachment.rb +86 -107
- data/lib/paperclip/attachment_options.rb +9 -0
- data/lib/paperclip/callbacks.rb +30 -0
- data/lib/paperclip/errors.rb +27 -0
- data/lib/paperclip/geometry.rb +6 -4
- data/lib/paperclip/glue.rb +23 -0
- data/lib/paperclip/helpers.rb +71 -0
- data/lib/paperclip/instance_methods.rb +35 -0
- data/lib/paperclip/interpolations.rb +4 -4
- data/lib/paperclip/io_adapters/attachment_adapter.rb +69 -0
- data/lib/paperclip/io_adapters/file_adapter.rb +81 -0
- data/lib/paperclip/io_adapters/identity_adapter.rb +12 -0
- data/lib/paperclip/io_adapters/nil_adapter.rb +34 -0
- data/lib/paperclip/io_adapters/registry.rb +32 -0
- data/lib/paperclip/io_adapters/stringio_adapter.rb +64 -0
- data/lib/paperclip/io_adapters/uploaded_file_adapter.rb +63 -0
- data/lib/paperclip/locales/en.yml +17 -0
- data/lib/paperclip/logger.rb +21 -0
- data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +5 -5
- data/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +7 -7
- data/lib/paperclip/matchers/validate_attachment_size_matcher.rb +11 -11
- data/lib/paperclip/missing_attachment_styles.rb +6 -9
- data/lib/paperclip/processor.rb +32 -17
- data/lib/paperclip/railtie.rb +13 -17
- data/lib/paperclip/storage/filesystem.rb +4 -13
- data/lib/paperclip/storage/fog.rb +33 -24
- data/lib/paperclip/storage/s3.rb +36 -28
- data/lib/paperclip/tempfile.rb +41 -0
- data/lib/paperclip/thumbnail.rb +2 -3
- data/lib/paperclip/validators.rb +45 -0
- data/lib/paperclip/validators/attachment_content_type_validator.rb +54 -0
- data/lib/paperclip/validators/attachment_presence_validator.rb +26 -0
- data/lib/paperclip/validators/attachment_size_validator.rb +102 -0
- data/lib/paperclip/version.rb +1 -1
- data/lib/tasks/paperclip.rake +4 -12
- data/paperclip.gemspec +15 -5
- data/test/adapter_registry_test.rb +32 -0
- data/test/attachment_adapter_test.rb +51 -0
- data/test/attachment_options_test.rb +27 -0
- data/test/attachment_test.rb +130 -46
- data/test/file_adapter_test.rb +88 -0
- data/test/generator_test.rb +78 -0
- data/test/geometry_test.rb +5 -5
- data/test/helper.rb +21 -22
- data/test/identity_adapter_test.rb +8 -0
- data/test/integration_test.rb +55 -102
- data/test/interpolations_test.rb +15 -5
- data/test/matchers/validate_attachment_content_type_matcher_test.rb +23 -0
- data/test/matchers/validate_attachment_presence_matcher_test.rb +21 -0
- data/test/matchers/validate_attachment_size_matcher_test.rb +37 -2
- data/test/nil_adapter_test.rb +25 -0
- data/test/paperclip_missing_attachment_styles_test.rb +16 -0
- data/test/paperclip_test.rb +34 -183
- data/test/storage/filesystem_test.rb +27 -27
- data/test/storage/fog_test.rb +68 -12
- data/test/storage/s3_live_test.rb +79 -38
- data/test/storage/s3_test.rb +204 -34
- data/test/stringio_adapter_test.rb +42 -0
- data/test/thumbnail_test.rb +29 -8
- data/test/uploaded_file_adapter_test.rb +98 -0
- data/test/url_generator_test.rb +8 -8
- data/test/validators/attachment_content_type_validator_test.rb +192 -0
- data/test/validators/attachment_presence_validator_test.rb +85 -0
- data/test/validators/attachment_size_validator_test.rb +207 -0
- data/test/validators_test.rb +25 -0
- metadata +166 -59
- data/generators/paperclip/USAGE +0 -5
- data/generators/paperclip/paperclip_generator.rb +0 -27
- data/generators/paperclip/templates/paperclip_migration.rb.erb +0 -19
- data/init.rb +0 -4
- data/lib/paperclip/callback_compatibility.rb +0 -61
- data/lib/paperclip/iostream.rb +0 -45
- data/lib/paperclip/upfile.rb +0 -62
- data/rails/init.rb +0 -2
- data/test/.gitignore +0 -1
- data/test/fixtures/question?mark.png +0 -0
- data/test/iostream_test.rb +0 -71
- data/test/upfile_test.rb +0 -53
data/generators/paperclip/USAGE
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
class PaperclipGenerator < Rails::Generator::NamedBase
|
2
|
-
attr_accessor :attachments, :migration_name
|
3
|
-
|
4
|
-
def initialize(args, options = {})
|
5
|
-
super
|
6
|
-
@class_name, @attachments = args[0], args[1..-1]
|
7
|
-
end
|
8
|
-
|
9
|
-
def manifest
|
10
|
-
file_name = generate_file_name
|
11
|
-
@migration_name = file_name.camelize
|
12
|
-
record do |m|
|
13
|
-
m.migration_template "paperclip_migration.rb.erb",
|
14
|
-
File.join('db', 'migrate'),
|
15
|
-
:migration_file_name => file_name
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
def generate_file_name
|
22
|
-
names = attachments.map{|a| a.underscore }
|
23
|
-
names = names[0..-2] + ["and", names[-1]] if names.length > 1
|
24
|
-
"add_attachments_#{names.join("_")}_to_#{@class_name.underscore}"
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
class <%= migration_name %> < ActiveRecord::Migration
|
2
|
-
def self.up
|
3
|
-
<% attachments.each do |attachment| -%>
|
4
|
-
add_column :<%= class_name.underscore.camelize.tableize %>, :<%= attachment %>_file_name, :string
|
5
|
-
add_column :<%= class_name.underscore.camelize.tableize %>, :<%= attachment %>_content_type, :string
|
6
|
-
add_column :<%= class_name.underscore.camelize.tableize %>, :<%= attachment %>_file_size, :integer
|
7
|
-
add_column :<%= class_name.underscore.camelize.tableize %>, :<%= attachment %>_updated_at, :datetime
|
8
|
-
<% end -%>
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.down
|
12
|
-
<% attachments.each do |attachment| -%>
|
13
|
-
remove_column :<%= class_name.underscore.camelize.tableize %>, :<%= attachment %>_file_name
|
14
|
-
remove_column :<%= class_name.underscore.camelize.tableize %>, :<%= attachment %>_content_type
|
15
|
-
remove_column :<%= class_name.underscore.camelize.tableize %>, :<%= attachment %>_file_size
|
16
|
-
remove_column :<%= class_name.underscore.camelize.tableize %>, :<%= attachment %>_updated_at
|
17
|
-
<% end -%>
|
18
|
-
end
|
19
|
-
end
|
data/init.rb
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
module Paperclip
|
2
|
-
module CallbackCompatability
|
3
|
-
module Rails21
|
4
|
-
def self.included(base)
|
5
|
-
base.extend(Defining)
|
6
|
-
base.send(:include, Running)
|
7
|
-
end
|
8
|
-
|
9
|
-
module Defining
|
10
|
-
def define_paperclip_callbacks(*args)
|
11
|
-
args.each do |callback|
|
12
|
-
define_callbacks("before_#{callback}")
|
13
|
-
define_callbacks("after_#{callback}")
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
module Running
|
19
|
-
def run_paperclip_callbacks(callback, opts = nil, &blk)
|
20
|
-
# The overall structure of this isn't ideal since after callbacks run even if
|
21
|
-
# befores return false. But this is how rails 3's callbacks work, unfortunately.
|
22
|
-
if run_callbacks(:"before_#{callback}"){ |result, object| result == false } != false
|
23
|
-
blk.call
|
24
|
-
end
|
25
|
-
run_callbacks(:"after_#{callback}"){ |result, object| result == false }
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
module Rails3
|
31
|
-
def self.included(base)
|
32
|
-
base.extend(Defining)
|
33
|
-
base.send(:include, Running)
|
34
|
-
end
|
35
|
-
|
36
|
-
module Defining
|
37
|
-
def define_paperclip_callbacks(*callbacks)
|
38
|
-
define_callbacks *[callbacks, {:terminator => "result == false"}].flatten
|
39
|
-
callbacks.each do |callback|
|
40
|
-
eval <<-end_callbacks
|
41
|
-
def before_#{callback}(*args, &blk)
|
42
|
-
set_callback(:#{callback}, :before, *args, &blk)
|
43
|
-
end
|
44
|
-
def after_#{callback}(*args, &blk)
|
45
|
-
set_callback(:#{callback}, :after, *args, &blk)
|
46
|
-
end
|
47
|
-
end_callbacks
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
module Running
|
53
|
-
def run_paperclip_callbacks(callback, opts = nil, &block)
|
54
|
-
run_callbacks(callback, opts, &block)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
end
|
59
|
-
|
60
|
-
end
|
61
|
-
end
|
data/lib/paperclip/iostream.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
# Provides method that can be included on File-type objects (IO, StringIO, Tempfile, etc) to allow stream copying
|
2
|
-
# and Tempfile conversion.
|
3
|
-
module IOStream
|
4
|
-
# Returns a Tempfile containing the contents of the readable object.
|
5
|
-
def to_tempfile(object)
|
6
|
-
return object.to_tempfile if object.respond_to?(:to_tempfile)
|
7
|
-
name = object.respond_to?(:original_filename) ? object.original_filename : (object.respond_to?(:path) ? object.path : "stream")
|
8
|
-
tempfile = Paperclip::Tempfile.new(["stream", File.extname(name)])
|
9
|
-
tempfile.binmode
|
10
|
-
stream_to(object, tempfile)
|
11
|
-
end
|
12
|
-
|
13
|
-
# Copies one read-able object from one place to another in blocks, obviating the need to load
|
14
|
-
# the whole thing into memory. Defaults to 8k blocks. Returns a File if a String is passed
|
15
|
-
# in as the destination and returns the IO or Tempfile as passed in if one is sent as the destination.
|
16
|
-
def stream_to object, path_or_file, in_blocks_of = 8192
|
17
|
-
dstio = case path_or_file
|
18
|
-
when String then File.new(path_or_file, "wb+")
|
19
|
-
when IO then path_or_file
|
20
|
-
when Tempfile then path_or_file
|
21
|
-
end
|
22
|
-
buffer = ""
|
23
|
-
object.rewind
|
24
|
-
while object.read(in_blocks_of, buffer) do
|
25
|
-
dstio.write(buffer)
|
26
|
-
end
|
27
|
-
dstio.rewind
|
28
|
-
dstio
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
# Corrects a bug in Windows when asking for Tempfile size.
|
33
|
-
if defined?(Tempfile) && RUBY_PLATFORM !~ /java/
|
34
|
-
class Tempfile
|
35
|
-
def size
|
36
|
-
if @tmpfile
|
37
|
-
@tmpfile.fsync
|
38
|
-
@tmpfile.flush
|
39
|
-
@tmpfile.stat.size
|
40
|
-
else
|
41
|
-
0
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
data/lib/paperclip/upfile.rb
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
require 'mime/types'
|
2
|
-
|
3
|
-
module Paperclip
|
4
|
-
# The Upfile module is a convenience module for adding uploaded-file-type methods
|
5
|
-
# to the +File+ class. Useful for testing.
|
6
|
-
# user.avatar = File.new("test/test_avatar.jpg")
|
7
|
-
module Upfile
|
8
|
-
|
9
|
-
# Infer the MIME-type of the file from the extension.
|
10
|
-
def content_type
|
11
|
-
types = MIME::Types.type_for(self.original_filename)
|
12
|
-
if types.length == 0
|
13
|
-
type_from_file_command
|
14
|
-
elsif types.length == 1
|
15
|
-
types.first.content_type
|
16
|
-
else
|
17
|
-
iterate_over_array_to_find_best_option(types)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def iterate_over_array_to_find_best_option(types)
|
22
|
-
types.reject {|type| type.content_type.match(/\/x-/) }.first
|
23
|
-
end
|
24
|
-
|
25
|
-
def type_from_file_command
|
26
|
-
# On BSDs, `file` doesn't give a result code of 1 if the file doesn't exist.
|
27
|
-
type = (self.original_filename.match(/\.(\w+)$/)[1] rescue "octet-stream").downcase
|
28
|
-
mime_type = (Paperclip.run("file", "-b --mime :file", :file => self.path).split(/[:;]\s+/)[0] rescue "application/x-#{type}")
|
29
|
-
mime_type = "application/x-#{type}" if mime_type.match(/\(.*?\)/)
|
30
|
-
mime_type
|
31
|
-
end
|
32
|
-
|
33
|
-
# Returns the file's normal name.
|
34
|
-
def original_filename
|
35
|
-
File.basename(self.path)
|
36
|
-
end
|
37
|
-
|
38
|
-
# Returns the size of the file.
|
39
|
-
def size
|
40
|
-
File.size(self)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
if defined? StringIO
|
46
|
-
class StringIO
|
47
|
-
attr_accessor :original_filename, :content_type, :fingerprint
|
48
|
-
def original_filename
|
49
|
-
@original_filename ||= "stringio.txt"
|
50
|
-
end
|
51
|
-
def content_type
|
52
|
-
@content_type ||= "text/plain"
|
53
|
-
end
|
54
|
-
def fingerprint
|
55
|
-
@fingerprint ||= Digest::MD5.hexdigest(self.string)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
class File #:nodoc:
|
61
|
-
include Paperclip::Upfile
|
62
|
-
end
|
data/rails/init.rb
DELETED
data/test/.gitignore
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
debug.log
|
Binary file
|
data/test/iostream_test.rb
DELETED
@@ -1,71 +0,0 @@
|
|
1
|
-
require './test/helper'
|
2
|
-
|
3
|
-
class IOStreamTest < Test::Unit::TestCase
|
4
|
-
include IOStream
|
5
|
-
context "A file" do
|
6
|
-
setup do
|
7
|
-
@file = File.new(File.join(File.dirname(__FILE__), "fixtures", "5k.png"), 'rb')
|
8
|
-
end
|
9
|
-
|
10
|
-
teardown { @file.close }
|
11
|
-
|
12
|
-
context "that is sent #stream_to" do
|
13
|
-
|
14
|
-
context "and given a String" do
|
15
|
-
setup do
|
16
|
-
FileUtils.mkdir_p(File.join(ROOT, 'tmp'))
|
17
|
-
assert @result = stream_to(@file, File.join(ROOT, 'tmp', 'iostream.string.test'))
|
18
|
-
end
|
19
|
-
|
20
|
-
should "return a File" do
|
21
|
-
assert @result.is_a?(File)
|
22
|
-
end
|
23
|
-
|
24
|
-
should "contain the same data as the original file" do
|
25
|
-
@file.rewind; @result.rewind
|
26
|
-
assert_equal @file.read, @result.read
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
context "and given a Tempfile" do
|
31
|
-
setup do
|
32
|
-
tempfile = Tempfile.new('iostream.test')
|
33
|
-
tempfile.binmode
|
34
|
-
assert @result = stream_to(@file, tempfile)
|
35
|
-
end
|
36
|
-
|
37
|
-
should "return a Tempfile" do
|
38
|
-
assert @result.is_a?(Tempfile)
|
39
|
-
end
|
40
|
-
|
41
|
-
should "contain the same data as the original file" do
|
42
|
-
@file.rewind; @result.rewind
|
43
|
-
assert_equal @file.read, @result.read
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
end
|
48
|
-
|
49
|
-
context "that is converted #to_tempfile" do
|
50
|
-
setup do
|
51
|
-
assert @tempfile = to_tempfile(@file)
|
52
|
-
end
|
53
|
-
|
54
|
-
should "convert it to a Paperclip Tempfile" do
|
55
|
-
assert @tempfile.is_a?(Paperclip::Tempfile)
|
56
|
-
end
|
57
|
-
|
58
|
-
should "have the name be based on the original_filename" do
|
59
|
-
name = File.basename(@file.path)
|
60
|
-
extension = File.extname(name)
|
61
|
-
basename = File.basename(name, extension)
|
62
|
-
assert_match %r[^stream.*?#{Regexp.quote(extension)}], File.basename(@tempfile.path)
|
63
|
-
end
|
64
|
-
|
65
|
-
should "have the Tempfile contain the same data as the file" do
|
66
|
-
@file.rewind; @tempfile.rewind
|
67
|
-
assert_equal @file.read, @tempfile.read
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
data/test/upfile_test.rb
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
require './test/helper'
|
2
|
-
|
3
|
-
class UpfileTest < Test::Unit::TestCase
|
4
|
-
{ %w(jpg jpe jpeg) => 'image/jpeg',
|
5
|
-
%w(tif tiff) => 'image/tiff',
|
6
|
-
%w(png) => 'image/png',
|
7
|
-
%w(gif) => 'image/gif',
|
8
|
-
%w(bmp) => 'image/bmp',
|
9
|
-
%w(svg) => 'image/svg+xml',
|
10
|
-
%w(txt) => 'text/plain',
|
11
|
-
%w(htm html) => 'text/html',
|
12
|
-
%w(csv) => 'text/csv',
|
13
|
-
%w(xml) => 'application/xml',
|
14
|
-
%w(css) => 'text/css',
|
15
|
-
%w(js) => 'application/javascript',
|
16
|
-
%w(foo) => 'application/x-foo'
|
17
|
-
}.each do |extensions, content_type|
|
18
|
-
extensions.each do |extension|
|
19
|
-
should "return a content_type of #{content_type} for a file with extension .#{extension}" do
|
20
|
-
file = stub('file', :path => "basename.#{extension}")
|
21
|
-
class << file
|
22
|
-
include Paperclip::Upfile
|
23
|
-
end
|
24
|
-
|
25
|
-
assert_equal content_type, file.content_type
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
should "return a content_type of text/plain on a real file whose content_type is determined with the file command" do
|
31
|
-
file = File.new(File.join(File.dirname(__FILE__), "..", "LICENSE"))
|
32
|
-
class << file
|
33
|
-
include Paperclip::Upfile
|
34
|
-
end
|
35
|
-
assert_equal 'text/plain', file.content_type
|
36
|
-
end
|
37
|
-
|
38
|
-
{ '5k.png' => 'image/png',
|
39
|
-
'animated.gif' => 'image/gif',
|
40
|
-
'text.txt' => 'text/plain',
|
41
|
-
'twopage.pdf' => 'application/pdf'
|
42
|
-
}.each do |filename, content_type|
|
43
|
-
should "return a content type of #{content_type} from a file command for file #{filename}" do
|
44
|
-
file = File.new(File.join(File.dirname(__FILE__), "fixtures", filename))
|
45
|
-
class << file
|
46
|
-
include Paperclip::Upfile
|
47
|
-
end
|
48
|
-
|
49
|
-
assert_equal content_type, file.type_from_file_command
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
end
|