Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Process :original style before all other styles

  • Loading branch information...
commit d3db7a1ce8f956fb677cc85b25e560bb2148436c 1 parent 9fb9255
Jim Ryan jimryan authored jyurek committed
Showing with 28 additions and 11 deletions.
  1. +14 −11 lib/paperclip/attachment.rb
  2. +14 −0 test/attachment_test.rb
25 lib/paperclip/attachment.rb
View
@@ -427,18 +427,21 @@ def post_process(*style_args) #:nodoc:
end
def post_process_styles(*style_args) #:nodoc:
- styles.each do |name, style|
- begin
- if style_args.empty? || style_args.include?(name)
- raise RuntimeError.new("Style #{name} has no processors defined.") if style.processors.blank?
- @queued_for_write[name] = style.processors.inject(@queued_for_write[:original]) do |file, processor|
- Paperclip.processor(processor).make(file, style.processor_options, self)
- end
- end
- rescue PaperclipError => e
- log("An error was received while processing: #{e.inspect}")
- (@errors[:processing] ||= []) << e.message if @options[:whiny]
+ post_process_style(:original, styles[:original]) if styles.include?(:original) && (style_args.empty? || style_args.include?(:original))
+ styles.reject{ |name, style| name == :original }.each do |name, style|
+ post_process_style(name, style) if style_args.empty? || style_args.include?(name)
+ end
+ end
+
+ def post_process_style(name, style) #:nodoc:
+ begin
+ raise RuntimeError.new("Style #{name} has no processors defined.") if style.processors.blank?
+ @queued_for_write[name] = style.processors.inject(@queued_for_write[:original]) do |file, processor|
+ Paperclip.processor(processor).make(file, style.processor_options, self)
end
+ rescue PaperclipError => e
+ log("An error was received while processing: #{e.inspect}")
+ (@errors[:processing] ||= []) << e.message if @options[:whiny]
end
end
14 test/attachment_test.rb
View
@@ -5,6 +5,20 @@
class Dummy; end
class AttachmentTest < Test::Unit::TestCase
+
+ should "process :original style first" do
+ file = File.new(File.join(File.dirname(__FILE__), "fixtures", "50x50.png"), 'rb')
+ rebuild_class :styles => { :small => '100x>', :original => '42x42#' }
+ dummy = Dummy.new
+ dummy.avatar = file
+ dummy.save
+
+ # :small avatar should be 42px wide (processed original), not 50px (preprocessed original)
+ assert_equal `identify -format "%w" "#{dummy.avatar.path(:small)}"`.strip, "42"
+
+ file.close
+ end
+
should "handle a boolean second argument to #url" do
mock_url_generator_builder = MockUrlGeneratorBuilder.new
attachment = Paperclip::Attachment.new(:name, :instance, :url_generator => mock_url_generator_builder)
Please sign in to comment.
Something went wrong with that request. Please try again.