Skip to content
This repository
Browse code

Process :original style before all other styles

  • Loading branch information...
commit d3db7a1ce8f956fb677cc85b25e560bb2148436c 1 parent 9fb9255
Jim Ryan jimryan authored jyurek committed

Showing 2 changed files with 28 additions and 11 deletions. Show diff stats Hide diff stats

  1. +14 11 lib/paperclip/attachment.rb
  2. +14 0 test/attachment_test.rb
25 lib/paperclip/attachment.rb
@@ -427,18 +427,21 @@ def post_process(*style_args) #:nodoc:
427 427 end
428 428
429 429 def post_process_styles(*style_args) #:nodoc:
430   - styles.each do |name, style|
431   - begin
432   - if style_args.empty? || style_args.include?(name)
433   - raise RuntimeError.new("Style #{name} has no processors defined.") if style.processors.blank?
434   - @queued_for_write[name] = style.processors.inject(@queued_for_write[:original]) do |file, processor|
435   - Paperclip.processor(processor).make(file, style.processor_options, self)
436   - end
437   - end
438   - rescue PaperclipError => e
439   - log("An error was received while processing: #{e.inspect}")
440   - (@errors[:processing] ||= []) << e.message if @options[:whiny]
  430 + post_process_style(:original, styles[:original]) if styles.include?(:original) && (style_args.empty? || style_args.include?(:original))
  431 + styles.reject{ |name, style| name == :original }.each do |name, style|
  432 + post_process_style(name, style) if style_args.empty? || style_args.include?(name)
  433 + end
  434 + end
  435 +
  436 + def post_process_style(name, style) #:nodoc:
  437 + begin
  438 + raise RuntimeError.new("Style #{name} has no processors defined.") if style.processors.blank?
  439 + @queued_for_write[name] = style.processors.inject(@queued_for_write[:original]) do |file, processor|
  440 + Paperclip.processor(processor).make(file, style.processor_options, self)
441 441 end
  442 + rescue PaperclipError => e
  443 + log("An error was received while processing: #{e.inspect}")
  444 + (@errors[:processing] ||= []) << e.message if @options[:whiny]
442 445 end
443 446 end
444 447
14 test/attachment_test.rb
@@ -5,6 +5,20 @@
5 5 class Dummy; end
6 6
7 7 class AttachmentTest < Test::Unit::TestCase
  8 +
  9 + should "process :original style first" do
  10 + file = File.new(File.join(File.dirname(__FILE__), "fixtures", "50x50.png"), 'rb')
  11 + rebuild_class :styles => { :small => '100x>', :original => '42x42#' }
  12 + dummy = Dummy.new
  13 + dummy.avatar = file
  14 + dummy.save
  15 +
  16 + # :small avatar should be 42px wide (processed original), not 50px (preprocessed original)
  17 + assert_equal `identify -format "%w" "#{dummy.avatar.path(:small)}"`.strip, "42"
  18 +
  19 + file.close
  20 + end
  21 +
8 22 should "handle a boolean second argument to #url" do
9 23 mock_url_generator_builder = MockUrlGeneratorBuilder.new
10 24 attachment = Paperclip::Attachment.new(:name, :instance, :url_generator => mock_url_generator_builder)

0 comments on commit d3db7a1

Please sign in to comment.
Something went wrong with that request. Please try again.