dm-paperclip 2.4.1 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +29 -0
- data/Gemfile.lock +100 -0
- data/README.md +145 -0
- data/Rakefile +37 -71
- data/VERSION +1 -0
- data/dm-paperclip.gemspec +103 -0
- data/lib/dm-paperclip.rb +88 -74
- data/lib/dm-paperclip/attachment.rb +139 -102
- data/lib/dm-paperclip/callbacks.rb +55 -0
- data/lib/dm-paperclip/command_line.rb +86 -0
- data/lib/dm-paperclip/ext/blank.rb +24 -0
- data/lib/dm-paperclip/ext/class.rb +50 -0
- data/lib/dm-paperclip/ext/compatibility.rb +11 -0
- data/lib/dm-paperclip/ext/try_dup.rb +12 -0
- data/lib/dm-paperclip/geometry.rb +3 -5
- data/lib/dm-paperclip/interpolations.rb +57 -32
- data/lib/dm-paperclip/iostream.rb +12 -26
- data/lib/dm-paperclip/processor.rb +14 -4
- data/lib/dm-paperclip/storage.rb +2 -257
- data/lib/dm-paperclip/storage/filesystem.rb +73 -0
- data/lib/dm-paperclip/storage/s3.rb +209 -0
- data/lib/dm-paperclip/storage/s3/aws_library.rb +41 -0
- data/lib/dm-paperclip/storage/s3/aws_s3_library.rb +60 -0
- data/lib/dm-paperclip/style.rb +90 -0
- data/lib/dm-paperclip/thumbnail.rb +33 -24
- data/lib/dm-paperclip/upfile.rb +13 -5
- data/lib/dm-paperclip/validations.rb +40 -37
- data/lib/dm-paperclip/version.rb +4 -0
- data/test/attachment_test.rb +510 -67
- data/test/command_line_test.rb +138 -0
- data/test/fixtures/s3.yml +8 -0
- data/test/fixtures/twopage.pdf +0 -0
- data/test/fixtures/uppercase.PNG +0 -0
- data/test/geometry_test.rb +54 -19
- data/test/helper.rb +91 -28
- data/test/integration_test.rb +252 -79
- data/test/interpolations_test.rb +150 -0
- data/test/iostream_test.rb +8 -15
- data/test/paperclip_test.rb +222 -69
- data/test/processor_test.rb +10 -0
- data/test/storage_test.rb +102 -23
- data/test/style_test.rb +141 -0
- data/test/thumbnail_test.rb +106 -18
- data/test/upfile_test.rb +36 -0
- metadata +136 -121
- data/README.rdoc +0 -116
- data/init.rb +0 -1
- data/lib/dm-paperclip/callback_compatability.rb +0 -33
data/test/upfile_test.rb
ADDED
@@ -0,0 +1,36 @@
|
|
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(txt) => 'text/plain',
|
10
|
+
%w(htm html) => 'text/html',
|
11
|
+
%w(csv) => 'text/csv',
|
12
|
+
%w(xml) => 'text/xml',
|
13
|
+
%w(css) => 'text/css',
|
14
|
+
%w(js) => 'application/js',
|
15
|
+
%w(foo) => 'application/x-foo'
|
16
|
+
}.each do |extensions, content_type|
|
17
|
+
extensions.each do |extension|
|
18
|
+
should "return a content_type of #{content_type} for a file with extension .#{extension}" do
|
19
|
+
file = stub('file', :path => "basename.#{extension}")
|
20
|
+
class << file
|
21
|
+
include Paperclip::Upfile
|
22
|
+
end
|
23
|
+
|
24
|
+
assert_equal content_type, file.content_type
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
should "return a content_type of text/plain on a real file whose content_type is determined with the file command" do
|
30
|
+
file = File.new(File.join(File.dirname(__FILE__), "..", "LICENSE"))
|
31
|
+
class << file
|
32
|
+
include Paperclip::Upfile
|
33
|
+
end
|
34
|
+
assert_equal 'text/plain', file.content_type
|
35
|
+
end
|
36
|
+
end
|
metadata
CHANGED
@@ -1,181 +1,196 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: dm-paperclip
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 2
|
8
|
-
- 4
|
9
|
-
- 1
|
10
|
-
version: 2.4.1
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.5.0
|
5
|
+
prerelease:
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Ken Robertson
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
12
|
+
date: 2013-07-06 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: dm-core
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.2.0
|
22
|
+
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
|
-
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.2.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: dm-validations
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.2.0
|
33
38
|
type: :runtime
|
34
|
-
version_requirements: *id001
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
|
-
name: datamapper
|
37
39
|
prerelease: false
|
38
|
-
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.2.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: dm-migrations
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
39
49
|
none: false
|
40
|
-
requirements:
|
41
|
-
- -
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
|
44
|
-
segments:
|
45
|
-
- 0
|
46
|
-
version: "0"
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.2.0
|
47
54
|
type: :runtime
|
48
|
-
version_requirements: *id002
|
49
|
-
- !ruby/object:Gem::Dependency
|
50
|
-
name: shoulda
|
51
55
|
prerelease: false
|
52
|
-
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
57
|
none: false
|
54
|
-
requirements:
|
55
|
-
- -
|
56
|
-
- !ruby/object:Gem::Version
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
- !
|
64
|
-
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.2.0
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: extlib
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
65
71
|
prerelease: false
|
66
|
-
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
67
73
|
none: false
|
68
|
-
requirements:
|
69
|
-
- -
|
70
|
-
- !ruby/object:Gem::Version
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: jeweler
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 1.8.0
|
77
86
|
type: :development
|
78
|
-
version_requirements: *id004
|
79
|
-
- !ruby/object:Gem::Dependency
|
80
|
-
name: aws-s3
|
81
87
|
prerelease: false
|
82
|
-
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 1.8.0
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: yard
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
83
97
|
none: false
|
84
|
-
requirements:
|
85
|
-
- -
|
86
|
-
- !ruby/object:Gem::Version
|
87
|
-
|
88
|
-
segments:
|
89
|
-
- 0
|
90
|
-
version: "0"
|
98
|
+
requirements:
|
99
|
+
- - ~>
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 0.8.1
|
91
102
|
type: :development
|
92
|
-
version_requirements: *id005
|
93
|
-
- !ruby/object:Gem::Dependency
|
94
|
-
name: do_sqlite3
|
95
103
|
prerelease: false
|
96
|
-
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
97
105
|
none: false
|
98
|
-
requirements:
|
99
|
-
- -
|
100
|
-
- !ruby/object:Gem::Version
|
101
|
-
|
102
|
-
segments:
|
103
|
-
- 0
|
104
|
-
version: "0"
|
105
|
-
type: :development
|
106
|
-
version_requirements: *id006
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 0.8.1
|
107
110
|
description:
|
108
111
|
email: ken@invalidlogic.com
|
109
112
|
executables: []
|
110
|
-
|
111
113
|
extensions: []
|
112
|
-
|
113
|
-
|
114
|
-
- README.
|
115
|
-
files:
|
116
|
-
-
|
114
|
+
extra_rdoc_files:
|
115
|
+
- LICENSE
|
116
|
+
- README.md
|
117
|
+
files:
|
118
|
+
- Gemfile
|
119
|
+
- Gemfile.lock
|
117
120
|
- LICENSE
|
121
|
+
- README.md
|
118
122
|
- Rakefile
|
119
|
-
-
|
123
|
+
- VERSION
|
124
|
+
- dm-paperclip.gemspec
|
125
|
+
- lib/dm-paperclip.rb
|
120
126
|
- lib/dm-paperclip/attachment.rb
|
121
|
-
- lib/dm-paperclip/
|
127
|
+
- lib/dm-paperclip/callbacks.rb
|
128
|
+
- lib/dm-paperclip/command_line.rb
|
129
|
+
- lib/dm-paperclip/ext/blank.rb
|
130
|
+
- lib/dm-paperclip/ext/class.rb
|
131
|
+
- lib/dm-paperclip/ext/compatibility.rb
|
132
|
+
- lib/dm-paperclip/ext/try_dup.rb
|
122
133
|
- lib/dm-paperclip/geometry.rb
|
123
134
|
- lib/dm-paperclip/interpolations.rb
|
124
135
|
- lib/dm-paperclip/iostream.rb
|
125
136
|
- lib/dm-paperclip/processor.rb
|
126
137
|
- lib/dm-paperclip/storage.rb
|
138
|
+
- lib/dm-paperclip/storage/filesystem.rb
|
139
|
+
- lib/dm-paperclip/storage/s3.rb
|
140
|
+
- lib/dm-paperclip/storage/s3/aws_library.rb
|
141
|
+
- lib/dm-paperclip/storage/s3/aws_s3_library.rb
|
142
|
+
- lib/dm-paperclip/style.rb
|
127
143
|
- lib/dm-paperclip/thumbnail.rb
|
128
144
|
- lib/dm-paperclip/upfile.rb
|
129
145
|
- lib/dm-paperclip/validations.rb
|
130
|
-
- lib/dm-paperclip.rb
|
146
|
+
- lib/dm-paperclip/version.rb
|
131
147
|
- tasks/paperclip_tasks.rake
|
132
148
|
- test/attachment_test.rb
|
149
|
+
- test/command_line_test.rb
|
133
150
|
- test/fixtures/12k.png
|
134
151
|
- test/fixtures/50x50.png
|
135
152
|
- test/fixtures/5k.png
|
136
153
|
- test/fixtures/bad.png
|
154
|
+
- test/fixtures/s3.yml
|
137
155
|
- test/fixtures/text.txt
|
156
|
+
- test/fixtures/twopage.pdf
|
157
|
+
- test/fixtures/uppercase.PNG
|
138
158
|
- test/geometry_test.rb
|
139
159
|
- test/helper.rb
|
140
160
|
- test/integration_test.rb
|
161
|
+
- test/interpolations_test.rb
|
141
162
|
- test/iostream_test.rb
|
142
163
|
- test/paperclip_test.rb
|
164
|
+
- test/processor_test.rb
|
143
165
|
- test/storage_test.rb
|
166
|
+
- test/style_test.rb
|
144
167
|
- test/thumbnail_test.rb
|
145
|
-
|
146
|
-
homepage: http://
|
168
|
+
- test/upfile_test.rb
|
169
|
+
homepage: http://invalidlogic.com/dm-paperclip/
|
147
170
|
licenses: []
|
148
|
-
|
149
171
|
post_install_message:
|
150
|
-
rdoc_options:
|
151
|
-
|
152
|
-
- --inline-source
|
153
|
-
require_paths:
|
172
|
+
rdoc_options: []
|
173
|
+
require_paths:
|
154
174
|
- lib
|
155
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
175
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
156
176
|
none: false
|
157
|
-
requirements:
|
158
|
-
- -
|
159
|
-
- !ruby/object:Gem::Version
|
160
|
-
|
161
|
-
|
162
|
-
- 0
|
163
|
-
version: "0"
|
164
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ! '>='
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
165
182
|
none: false
|
166
|
-
requirements:
|
167
|
-
- -
|
168
|
-
- !ruby/object:Gem::Version
|
169
|
-
|
170
|
-
|
171
|
-
- 0
|
172
|
-
version: "0"
|
173
|
-
requirements:
|
183
|
+
requirements:
|
184
|
+
- - ! '>='
|
185
|
+
- !ruby/object:Gem::Version
|
186
|
+
version: '0'
|
187
|
+
requirements:
|
174
188
|
- ImageMagick
|
175
|
-
rubyforge_project:
|
176
|
-
rubygems_version: 1.
|
189
|
+
rubyforge_project:
|
190
|
+
rubygems_version: 1.8.23
|
177
191
|
signing_key:
|
178
192
|
specification_version: 3
|
179
|
-
summary: File attachments as attributes for DataMapper, based on the original Paperclip
|
193
|
+
summary: File attachments as attributes for DataMapper, based on the original Paperclip
|
194
|
+
by Jon Yurek at Thoughtbot
|
180
195
|
test_files: []
|
181
|
-
|
196
|
+
has_rdoc:
|
data/README.rdoc
DELETED
@@ -1,116 +0,0 @@
|
|
1
|
-
=DataMapper Paperclip
|
2
|
-
|
3
|
-
DM-Paperclip is a port of Thoughtbot's Paperclip plugin to work with DataMapper. This plugin is fully compatible with
|
4
|
-
the original ActiveRecord-oriented Paperclip. You could take an existing ActiveRecord database and use it with DataMapper.
|
5
|
-
The module also includes updates validation handling and automatic including of the necessary 'property' fields into
|
6
|
-
your model.
|
7
|
-
|
8
|
-
To use it within your models, you need to ensure the three database fields are included. They are {name}_file_name,
|
9
|
-
{name}_content_type, and {name}_file_size. The first two are strings, the final _file_size column is an integer. So
|
10
|
-
if your user model has an avatar field, then you would add avatar_file_name, avatar_content_type, and avatar_file_size.
|
11
|
-
|
12
|
-
As with the original Paperclip plugin, it allows processing of thumbnails at the time the record is saved though ImageMagick.
|
13
|
-
It processes the thumbnails through the command-line applications instead of using RMagick.
|
14
|
-
|
15
|
-
See the documentation for the +has_attached_file+ method for options.
|
16
|
-
|
17
|
-
==Code
|
18
|
-
|
19
|
-
The code DM-Paperclip is available at Github:
|
20
|
-
|
21
|
-
git clone git://github.com/krobertson/dm-paperclip.git
|
22
|
-
|
23
|
-
It is regularly updated to keep in sync with the latest from Thoughtbot.
|
24
|
-
|
25
|
-
Releases are tagged within the repository and versioned the same as the original model. You can also get the latest release
|
26
|
-
packaged as a gem through Rubyforge:
|
27
|
-
|
28
|
-
sudo gem install dm-paperclip
|
29
|
-
|
30
|
-
==Usage
|
31
|
-
|
32
|
-
In your model:
|
33
|
-
|
34
|
-
class User
|
35
|
-
include DataMapper::Resource
|
36
|
-
include Paperclip::Resource
|
37
|
-
property :id, Serial
|
38
|
-
property :username, String
|
39
|
-
has_attached_file :avatar,
|
40
|
-
:styles => { :medium => "300x300>",
|
41
|
-
:thumb => "100x100>" }
|
42
|
-
end
|
43
|
-
|
44
|
-
You will need to add an initializer to configure Paperclip. If on Rails, can add a config/initializers/paperclip.rb, on Merb
|
45
|
-
can use config/init.rb and add it to the Merb::BootLoader.after_app_loads section. Can also use environment configs, rackup
|
46
|
-
file, Rake task, wherever.
|
47
|
-
|
48
|
-
Paperclip.configure do |config|
|
49
|
-
config.root = Rails.root # the application root to anchor relative urls (defaults to Dir.pwd)
|
50
|
-
config.env = Rails.env # server env support, defaults to ENV['RACK_ENV'] or 'development'
|
51
|
-
config.use_dm_validations = true # validate attachment sizes and such, defaults to false
|
52
|
-
config.processors_path = 'lib/pc' # relative path to look for processors, defaults to 'lib/paperclip_processors'
|
53
|
-
end
|
54
|
-
|
55
|
-
Your database will need to add four columns, avatar_file_name (varchar), avatar_content_type (varchar), and
|
56
|
-
avatar_file_size (integer), and avatar_updated_at (datetime). You can either add these manually, auto-
|
57
|
-
migrate, or use the following migration:
|
58
|
-
|
59
|
-
migration( 1, :add_user_paperclip_fields ) do
|
60
|
-
up do
|
61
|
-
modify_table :users do
|
62
|
-
add_column :avatar_file_name, "varchar(255)"
|
63
|
-
add_column :avatar_content_type, "varchar(255)"
|
64
|
-
add_column :avatar_file_size, "integer"
|
65
|
-
add_column :avatar_updated_at, "datetime"
|
66
|
-
end
|
67
|
-
end
|
68
|
-
down do
|
69
|
-
modify_table :users do
|
70
|
-
drop_columns :avatar_file_name, :avatar_content_type, :avatar_file_size, :avatar_updated_at
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
In your edit and new views:
|
76
|
-
|
77
|
-
<% form_for @user, { :action => url(:user), :multipart => true } do %>
|
78
|
-
<%= file_field :name => 'avatar' %>
|
79
|
-
<% end %>
|
80
|
-
|
81
|
-
In your controller:
|
82
|
-
|
83
|
-
def create
|
84
|
-
...
|
85
|
-
@user.avatar = params[:avatar]
|
86
|
-
end
|
87
|
-
|
88
|
-
In your show view:
|
89
|
-
|
90
|
-
<%= image_tag @user.avatar.url %>
|
91
|
-
<%= image_tag @user.avatar.url(:medium) %>
|
92
|
-
<%= image_tag @user.avatar.url(:thumb) %>
|
93
|
-
|
94
|
-
The following validations are available:
|
95
|
-
|
96
|
-
validates_attachment_presence :avatar
|
97
|
-
validates_attachment_content_type :avatar, :content_type => "image/png"
|
98
|
-
validates_attachment_size :avatar, :in => 1..10240
|
99
|
-
validates_attachment_thumbnails :avatar
|
100
|
-
|
101
|
-
In order to use validations, you must have loaded the 'dm-validations' gem into your app
|
102
|
-
(available as a part of dm-more). If the gem isn't loaded before DM-Paperclip is loaded,
|
103
|
-
the validation methods will be excluded. You will also need to include DataMapper::Validate
|
104
|
-
into your mode:
|
105
|
-
|
106
|
-
class User
|
107
|
-
include DataMapper::Resource
|
108
|
-
include DataMapper::Validate
|
109
|
-
include Paperclip::Resource
|
110
|
-
property :id, Serial
|
111
|
-
property :username, String
|
112
|
-
has_attached_file :avatar,
|
113
|
-
:styles => { :medium => "300x300>",
|
114
|
-
:thumb => "100x100>" }
|
115
|
-
validates_attachment_size :avatar, :in => 1..5120
|
116
|
-
end
|