public
Description: Paperclip File Management Plugin
Homepage: http://www.thoughtbot.com/projects/paperclip
Clone URL: git://github.com/thoughtbot/paperclip.git
Tweaked the interpolation matching so :id won't step on :id_partition.


git-svn-id: https://svn.thoughtbot.com/plugins/paperclip/trunk@458 
7bbfaf0e-4d1d-0410-9690-a8bb5f8ef2aa
jyurek (author)
Thu Apr 17 07:06:09 -0700 2008
commit  96dc32b2b4d1dadc936217f7367e44bccb00b0b6
tree    0f2a9ef4c3d4fe86a53521fd86497a56b72f24c0
parent  61d8253b48d7ac377b50e7edae8e80f59d05017f
...
148
149
150
151
 
 
 
152
153
154
...
157
158
159
160
 
161
162
163
...
215
216
217
218
 
219
220
221
...
148
149
150
 
151
152
153
154
155
156
...
159
160
161
 
162
163
164
165
...
217
218
219
 
220
221
222
223
0
@@ -148,7 +148,9 @@ module Paperclip
0
     def self.interpolations
0
       @interpolations ||= {
0
         :rails_root => lambda{|attachment,style| RAILS_ROOT },
0
- :class => lambda{|attachment,style| attachment.instance.class.to_s.downcase.pluralize },
0
+ :class => lambda do |attachment,style|
0
+ attachment.instance.class.to_s.downcase.pluralize
0
+ end,
0
         :basename => lambda do |attachment,style|
0
                            attachment.original_filename.gsub(/\.(.*?)$/, "")
0
                          end,
0
@@ -157,7 +159,7 @@ module Paperclip
0
                            File.extname(attachment.original_filename).gsub(/^\.+/, "")
0
                          end,
0
         :id => lambda{|attachment,style| attachment.instance.id },
0
- :partition_id => lambda do |attachment, style|
0
+ :id_partition => lambda do |attachment, style|
0
                            ("%09d" % attachment.instance.id).scan(/\d{3}/).join("/")
0
                          end,
0
         :attachment => lambda{|attachment,style| attachment.name.to_s.downcase.pluralize },
0
@@ -215,7 +217,7 @@ module Paperclip
0
       style ||= default_style
0
       pattern = pattern.dup
0
       self.class.interpolations.each do |tag, l|
0
- pattern.gsub!(/:#{tag}/) do |match|
0
+ pattern.gsub!(/:\b#{tag}\b/) do |match|
0
           l.call( self, style )
0
         end
0
       end
...
60
61
62
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
64
65
...
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
0
@@ -60,6 +60,22 @@ class AttachmentTest < Test::Unit::TestCase
0
     end
0
   end
0
 
0
+ context "An attachment with similarly named interpolations" do
0
+ setup do
0
+ rebuild_model :path => ":id.omg/:id-bbq/:idwhat/:id_partition.wtf"
0
+ @dummy = Dummy.new
0
+ @dummy.stubs(:id).returns(1024)
0
+ @file = File.new(File.join(File.dirname(__FILE__),
0
+ "fixtures",
0
+ "5k.png"))
0
+ @dummy.avatar = @file
0
+ end
0
+
0
+ should "make sure that they are interpolated correctly" do
0
+ assert_equal "1024.omg/1024-bbq/:idwhat/000/001/024.wtf", @dummy.avatar.path
0
+ end
0
+ end
0
+
0
   context "An attachment" do
0
     setup do
0
       Paperclip::Attachment.default_options.merge!({

Comments

    No one has commented yet.