Commit 476084af by Sam L'Ecuyer Committed by Prem Sichanugrist

add selective processing for thumbanils

Closes #499
parent 7a1dbd40
...@@ -11,6 +11,7 @@ module Paperclip ...@@ -11,6 +11,7 @@ module Paperclip
:url => "/system/:attachment/:id/:style/:filename", :url => "/system/:attachment/:id/:style/:filename",
:path => ":rails_root/public:url", :path => ":rails_root/public:url",
:styles => {}, :styles => {},
:only_process => [],
:processors => [:thumbnail], :processors => [:thumbnail],
:convert_options => {}, :convert_options => {},
:default_url => "/:attachment/:style/missing.png", :default_url => "/:attachment/:style/missing.png",
...@@ -41,6 +42,7 @@ module Paperclip ...@@ -41,6 +42,7 @@ module Paperclip
@path = options[:path] @path = options[:path]
@path = @path.call(self) if @path.is_a?(Proc) @path = @path.call(self) if @path.is_a?(Proc)
@styles = options[:styles] @styles = options[:styles]
@only_process = options[:only_process]
@normalized_styles = nil @normalized_styles = nil
@default_url = options[:default_url] @default_url = options[:default_url]
@default_style = options[:default_style] @default_style = options[:default_style]
...@@ -107,7 +109,7 @@ module Paperclip ...@@ -107,7 +109,7 @@ module Paperclip
@dirty = true @dirty = true
post_process if @post_processing post_process(*@only_process) if @post_processing
# Reset the file size if the original file was reprocessed. # Reset the file size if the original file was reprocessed.
instance_write(:file_size, @queued_for_write[:original].size.to_i) instance_write(:file_size, @queued_for_write[:original].size.to_i)
......
...@@ -250,6 +250,24 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -250,6 +250,24 @@ class AttachmentTest < Test::Unit::TestCase
end end
end end
context "An attachment with :only_process" do
setup do
rebuild_model :styles => {
:thumb => "100x100",
:large => "400x400"
},
:only_process => [:thumb]
@file = StringIO.new("...")
@attachment = Dummy.new.avatar
end
should "only process the provided style" do
@attachment.expects(:post_process).with(:thumb)
@attachment.expects(:post_process).with(:large).never
@attachment.assign(@file)
end
end
context "An attachment with :convert_options that is a proc" do context "An attachment with :convert_options that is a proc" do
setup do setup do
rebuild_model :styles => { rebuild_model :styles => {
......
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