public
Description: Treat an ActiveRecord model as a file attachment, storing its patch, size, content type, etc.
Homepage: http://weblog.techno-weenie.net
Clone URL: git://github.com/technoweenie/attachment_fu.git
Click here to lend your support to: attachment_fu and make a donation at www.pledgie.com !
use first arg of full_path/public_path to set the thumbnailed filename, if 
provided
technoweenie (author)
Fri Jul 04 02:20:34 -0700 2008
commit  e1c4eab368029d56dac1b1ce32e8edec7f042743
tree    59273019dc1ea7d5b9b8552a1e9a113bfe84c19e
parent  1ed2faadfe741f8928c9b305700e528a0a79d982
...
150
151
152
153
154
155
 
 
156
157
158
 
159
160
161
 
162
163
164
...
215
216
217
 
 
 
 
 
 
 
 
 
 
218
219
220
...
247
248
249
250
 
251
252
253
...
150
151
152
 
 
 
153
154
155
156
 
157
158
 
 
159
160
161
162
...
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
...
255
256
257
 
258
259
260
261
0
@@ -150,15 +150,13 @@ module AttachmentFu
0
       ("%08d" % attachment_path_id).scan(/..../) + args
0
     end
0
 
0
- def public_path(*args)
0
- args = [filename] if args.empty?
0
- File.join(attachment_path, *partitioned_path(*args)).sub(/^public\//, '/')
0
+ def public_path(thumbnail = nil)
0
+ File.join(attachment_path, *partitioned_path(thumbnailed_filename(thumbnail))).sub(/^public\//, '/')
0
     end
0
 
0
- def full_path(*args)
0
+ def full_path(thumbnail = nil)
0
       return nil if attachment_path_id.nil?
0
- args = [filename] if args.empty?
0
- File.expand_path(File.join(AttachmentFu.root_path, attachment_path, *partitioned_path(*args)))
0
+ File.expand_path(File.join(AttachmentFu.root_path, attachment_path, *partitioned_path(thumbnailed_filename(thumbnail))))
0
     end
0
 
0
     # Sets the path to the attachment about to be saved. Could be a string path to a file,
0
@@ -215,6 +213,16 @@ module AttachmentFu
0
     end
0
 
0
   protected
0
+ def thumbnailed_filename(thumbnail)
0
+ if thumbnail
0
+ pieces = filename.split('.')
0
+ pieces[pieces.size > 1 ? -2 : -1] << "_#{thumbnail}"
0
+ pieces * "."
0
+ else
0
+ filename
0
+ end
0
+ end
0
+
0
     def process_all_tasks(has_progress = respond_to?(:task_progress))
0
       self.class.attachment_tasks.each do |stack_item|
0
         if process_task?(stack_item)
0
@@ -247,7 +255,7 @@ module AttachmentFu
0
       has_progress = respond_to?(:task_progress)
0
       if respond_to?(:processed_at)
0
         return false if processed_at
0
- !has_progress || !check_task_progress(stack)\
0
+ !has_progress || !check_task_progress(stack)
0
       else
0
         has_progress ? !check_task_progress(stack) : (@new_attachment || new_record?)
0
       end
...
61
62
63
64
 
 
 
 
 
 
 
 
 
 
65
66
67
68
69
 
 
 
 
 
 
 
 
 
 
70
71
72
...
61
62
63
 
64
65
66
67
68
69
70
71
72
73
74
75
76
77
 
78
79
80
81
82
83
84
85
86
87
88
89
90
0
@@ -61,12 +61,30 @@ module AttachmentFu
0
 
0
       it "creates full_path from record id and attachment_path" do
0
         @asset.full_path.should == File.expand_path(File.join(AttachmentFu.root_path, "public/afu_spec_assets/#{@asset.partitioned_path * '/'}/#{@asset.filename}"))
0
- @asset.full_path("foo", "bar").should == File.expand_path(File.join(AttachmentFu.root_path, "public/afu_spec_assets/#{@asset.partitioned_path * '/'}/foo/bar"))
0
+ end
0
+
0
+ it "creates thumbnailed full_path from record id and attachment_path" do
0
+ @asset.full_path(:foo).should == File.expand_path(File.join(AttachmentFu.root_path, "public/afu_spec_assets/#{@asset.partitioned_path * '/'}/guinea_pig_foo.rb"))
0
+ begin
0
+ @asset.filename = 'guinea_pig'
0
+ @asset.full_path(:foo).should == File.expand_path(File.join(AttachmentFu.root_path, "public/afu_spec_assets/#{@asset.partitioned_path * '/'}/guinea_pig_foo"))
0
+ ensure
0
+ @asset.filename = 'guinea_pig.rb'
0
+ end
0
       end
0
 
0
       it "creates public_path from record id and attachment_path" do
0
         @asset.public_path.should == "/afu_spec_assets/#{@asset.partitioned_path * '/'}/#{@asset.filename}"
0
- @asset.public_path("foo", "bar").should == "/afu_spec_assets/#{@asset.partitioned_path * '/'}/foo/bar"
0
+ end
0
+
0
+ it "creates thumbnailed public_path from record id and attachment_path" do
0
+ @asset.public_path(:foo).should == "/afu_spec_assets/#{@asset.partitioned_path * '/'}/guinea_pig_foo.rb"
0
+ begin
0
+ @asset.filename = 'guinea_pig'
0
+ @asset.public_path(:foo).should == "/afu_spec_assets/#{@asset.partitioned_path * '/'}/guinea_pig_foo"
0
+ ensure
0
+ @asset.filename = 'guinea_pig.rb'
0
+ end
0
       end
0
 
0
       it "creates partitioned path from the record id" do

Comments

    No one has commented yet.