Commit d3db7a1c by Jim Ryan Committed by Jon Yurek

Process :original style before all other styles

parent 9fb92553
......@@ -427,18 +427,21 @@ module Paperclip
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
......
......@@ -5,6 +5,20 @@ require 'paperclip/attachment'
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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment