Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
respect :convert_options and :source_file_options in :styles hash
Browse files Browse the repository at this point in the history
  • Loading branch information
kasatani committed Nov 4, 2011
1 parent bc5c51d commit b66833e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
8 changes: 6 additions & 2 deletions lib/paperclip/style.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ def initialize name, definition, attachment
@geometry = definition.delete(:geometry)
@format = definition.delete(:format)
@processors = definition.delete(:processors)
@convert_options = definition.delete(:convert_options)
@source_file_options = definition.delete(:source_file_options)
@other_args = definition
else
@geometry, @format = [definition, nil].flatten[0..1]
Expand Down Expand Up @@ -46,11 +48,13 @@ def whiny?
end

def convert_options
attachment.send(:extra_options_for, name)
@convert_options.respond_to?(:call) ? @convert_options.call(attachment.instance) :
(@convert_options || attachment.send(:extra_options_for, name))
end

def source_file_options
attachment.send(:extra_source_file_options_for, name)
@source_file_options.respond_to?(:call) ? @source_file_options.call(attachment.instance) :
(@source_file_options || attachment.send(:extra_source_file_options_for, name))
end

# returns the geometry string for this style
Expand Down
31 changes: 30 additions & 1 deletion test/style_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ class StyleTest < Test::Unit::TestCase
:styles => {
:foo => lambda{|a| "300x300#"},
:bar => {
:geometry => lambda{|a| "300x300#"}
:geometry => lambda{|a| "300x300#"},
:convert_options => lambda{|a| "-do_stuff"},
:source_file_options => lambda{|a| "-do_extra_stuff"}
}
}
end
Expand All @@ -51,6 +53,8 @@ class StyleTest < Test::Unit::TestCase
assert_equal "300x300#", @attachment.options.styles[:bar].geometry
assert_equal [:test], @attachment.options.styles[:foo].processors
assert_equal [:test], @attachment.options.styles[:bar].processors
assert_equal "-do_stuff", @attachment.options.styles[:bar].convert_options
assert_equal "-do_extra_stuff", @attachment.options.styles[:bar].source_file_options
end
end

Expand Down Expand Up @@ -177,4 +181,29 @@ class StyleTest < Test::Unit::TestCase
assert_equal [:test], @attachment.options.styles[:foo].processors
end
end

context "An attachment with :convert_options and :source_file_options in :styles" do
setup do
@attachment = attachment :path => ":basename.:extension",
:styles => {
:thumb => "100x100",
:large => {:geometry => "400x400",
:convert_options => "-do_stuff",
:source_file_options => "-do_extra_stuff"
}
}
@file = StringIO.new("...")
@file.stubs(:original_filename).returns("file.jpg")
end

should "have empty options for :thumb style" do
assert_equal "", @attachment.options.styles[:thumb].processor_options[:convert_options]
assert_equal "", @attachment.options.styles[:thumb].processor_options[:source_file_options]
end

should "have the right options for :large style" do
assert_equal "-do_stuff", @attachment.options.styles[:large].processor_options[:convert_options]
assert_equal "-do_extra_stuff", @attachment.options.styles[:large].processor_options[:source_file_options]
end
end
end

0 comments on commit b66833e

Please sign in to comment.