public
Description: DataMapper port of the Paperclip plugin by Thoughtbot
Homepage: http://invalidlogic.com/dm-paperclip/
Clone URL: git://github.com/krobertson/dm-paperclip.git
Updated to match up to Paperclip 2.1.2
krobertson (author)
Wed May 14 23:51:28 -0700 2008
commit  5e6136bc6e76393eaa1f0fe65fbbf7cc102cb213
tree    e1c85c648fd9c6aae65ee8ec24cef17cad546de5
parent  981747932500f1d6009dad0c52d14e244cae3c45
...
35
36
37
38
 
39
40
41
...
35
36
37
 
38
39
40
41
0
@@ -35,7 +35,7 @@ require File.join(File.dirname(__FILE__), 'dm-paperclip', 'storage')
0
 require File.join(File.dirname(__FILE__), 'dm-paperclip', 'attachment')
0
 
0
 module Paperclip
0
- VERSION = "2.1.0"
0
+ VERSION = "2.1.2"
0
   class << self
0
     # Provides configurability to Paperclip. There are a number of options available, such as:
0
     # * whiny_thumbnails: Will raise an error if Paperclip cannot process thumbnails of
...
153
154
155
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
156
157
158
...
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
0
@@ -153,6 +153,22 @@ module Paperclip
0
       }
0
     end
0
 
0
+ # This method really shouldn't be called that often. It's expected use is in the
0
+ # paperclip:refresh rake task and that's it. It will regenerate all thumbnails
0
+ # forcefully, by reobtaining the original file and going through the post-process
0
+ # again.
0
+ def reprocess!
0
+ new_original = Tempfile.new("paperclip-reprocess")
0
+ old_original = to_file(:original)
0
+ new_original.write( old_original.read )
0
+ new_original.rewind
0
+
0
+ @queued_for_write = { :original => new_original }
0
+ post_process
0
+
0
+ old_original.close if old_original.respond_to?(:close)
0
+ end
0
+
0
     def self.underscore(camel_cased_word)
0
       camel_cased_word.to_s.gsub(/::/, '/').
0
       gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
...
6
7
8
9
10
 
 
11
12
13
...
19
20
21
22
 
 
23
24
 
25
26
27
 
28
29
30
...
6
7
8
 
 
9
10
11
12
13
...
19
20
21
 
22
23
24
 
25
26
27
 
28
29
30
31
0
@@ -6,8 +6,8 @@ end
0
 
0
 def obtain_attachments
0
   name = ENV['ATTACHMENT'] || ENV['attachment']
0
- raise "Class #{@klass.name} has no attachments specified" unless @klass.respond_to?(:attachment_names)
0
- if !name.blank? && @klass.attachment_names.include?(name)
0
+ raise "Class #{@klass.name} has no attachments specified" unless @klass.respond_to?(:attachment_definitions)
0
+ if !name.blank? && @klass.attachment_definitions.keys.include?(name)
0
     [ name ]
0
   else
0
     @klass.attachment_definitions.keys
0
@@ -19,12 +19,13 @@ namespace :paperclip do
0
   task :refresh => :environment do
0
     klass = obtain_class
0
     names = obtain_attachments
0
-
0
+ instances = klass.all
0
+
0
     puts "Regenerating thumbnails for #{instances.length} instances of #{klass.name}:"
0
- klass.all.each do |instance|
0
+ instances.each do |instance|
0
       names.each do |name|
0
         result = if instance.send("#{ name }?")
0
- instance.send(name).send("post_process")
0
+ instance.send(name).reprocess!
0
           instance.send(name).save
0
         else
0
           true
...
18
19
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
22
23
...
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
0
@@ -18,6 +18,38 @@ class IntegrationTest < Test::Unit::TestCase
0
     end
0
   end
0
 
0
+ context "An attachment" do
0
+ setup do
0
+ rebuild_model :styles => { :thumb => "50x50#" }
0
+ @dummy = Dummy.new
0
+ @dummy.id = 1
0
+ @file = File.new(File.join(File.dirname(__FILE__),
0
+ "fixtures",
0
+ "5k.png"))
0
+ @dummy.avatar = @file
0
+ assert @dummy.save
0
+ end
0
+
0
+ should "create its thumbnails properly" do
0
+ assert_match /\b50x50\b/, `identify '#{@dummy.avatar.path(:thumb)}'`
0
+ end
0
+
0
+ context "redefining its attachment styles" do
0
+ setup do
0
+ Dummy.class_eval do
0
+ has_attached_file :avatar, :styles => { :thumb => "150x25#" }
0
+ end
0
+ @d2 = Dummy[@dummy.id]
0
+ @d2.avatar.reprocess!
0
+ @d2.save
0
+ end
0
+
0
+ should "create its thumbnails properly" do
0
+ assert_match /\b150x25\b/, `identify '#{@dummy.avatar.path(:thumb)}'`
0
+ end
0
+ end
0
+ end
0
+
0
   context "A model with no attachment validation" do
0
     setup do
0
       rebuild_model :styles => { :large => "300x300>",

Comments

    No one has commented yet.