Permalink
Browse files

tweak the thumbnail load process

  • Loading branch information...
1 parent c9ddd35 commit 022ec71e1931b5b5d33c647772af0dc91c5d30c3 @technoweenie committed Dec 14, 2008
Showing with 12 additions and 4 deletions.
  1. +12 −4 lib/attachment_fu/tasks/thumbnails.rb
@@ -47,12 +47,16 @@ def initialize(klass, options)
end
def self.inherited(klass)
- if th_task = attachment_tasks[:thumbnails]
- th_task.thumbnail_class ||= klass
- end
+ th_task = attachment_tasks[:thumbnails]
+ th_task.thumbnail_class ||= klass
super
+ th_task.assign_thumbnail_class_to_attachment_class if !th_task.thumbnail_class_processed?
end
end
+
+ if @thumbnail_class = @options[:thumbnail_class]
+ assign_thumbnail_class_to_attachment_class
+ end
end
# task :thumbnails, :sizes => {:thumb => '50x50', :tiny => [10, 10]}
@@ -76,7 +80,7 @@ def call(attachment, options)
# Set the given class as the thumbnail class for the current attachment class
def assign_thumbnail_class_to_attachment_class
- @thumbnail_class = @options[:thumbnail_class] || @klass.const_set(:Thumbnail, Class.new(@klass))
+ @thumbnail_class ||= @klass.const_set(:Thumbnail, Class.new(@klass))
if @thumbnail_class.is_a?(String) ; @thumbnail_class = @thumbnail_class.constantize; end
th_task = self
@@ -111,6 +115,10 @@ def attachment_path_id
@thumbnail_class_processed = true
end
+ def thumbnail_class_processed?
+ @thumbnail_class_processed
+ end
+
def thumbnail_name_for(attachment, thumbnail = nil)
return attachment.filename if thumbnail.blank?
ext = nil

0 comments on commit 022ec71

Please sign in to comment.