diff --git a/lib/zoomifier_helper.rb b/lib/zoomifier_helper.rb index 6cb94ab..413e325 100644 --- a/lib/zoomifier_helper.rb +++ b/lib/zoomifier_helper.rb @@ -2,11 +2,14 @@ module Zoomifier module ViewHelpers def zoomify_image_tag(source, options = {}) raise ArgumentError unless [:id, :width, :height].all? {|o| options[o] } + if File.file?(path = RAILS_ROOT + '/public/images/' + source) + Zoomifier::zoomify(path) + end s = content_tag :div, { :id => options[:id] } do image_tag source, options.merge({ :id => nil }) end zoomify_path = image_path(source).gsub(/\.[^.]+$/, '') - s += javascript_tag "swfobject.embedSWF('/swf/zoomifyViewer.swf', '#{options[:id]}', '#{options[:width]}', '#{options[:height]}', '9.0.0', false, { zoomifyImagePath: '#{zoomify_path}/' });" + s += javascript_tag "swfobject.embedSWF('/swfs/zoomifyViewer.swf', '#{options[:id]}', '#{options[:width]}', '#{options[:height]}', '9.0.0', false, { zoomifyImagePath: '#{zoomify_path}/' });" s end end diff --git a/spec/zoomifier_helper_spec.rb b/spec/zoomifier_helper_spec.rb index 7fcf2dd..4728df9 100644 --- a/spec/zoomifier_helper_spec.rb +++ b/spec/zoomifier_helper_spec.rb @@ -19,9 +19,6 @@ end describe Zoomifier::ViewHelpers, "when included into ActionView" do before(:all) do ActionView::Base.send :include, Zoomifier::ViewHelpers - end - - before(:each) do @view = ActionView::Base.new end @@ -37,7 +34,16 @@ describe Zoomifier::ViewHelpers, "when included into ActionView" do @view.zoomify_image_tag('foo.jpg', { :id => 'foo', :alt => 'Foo Bar', :width => 800, :height => 500 }).should == '
Foo Bar
' + "' end + + it "should automatically zoomify an image" do + FileUtils.copy(File.dirname(__FILE__) + '/data/1024x768.jpg', RAILS_ROOT + '/public/images/') + File.directory?(RAILS_ROOT + '/public/images/1024x768/').should be_false + @view.zoomify_image_tag('1024x768.jpg', {:id => 'foo', :alt => 'Foo Bar', :width => 400, :height => 300 }) + File.directory?(RAILS_ROOT + '/public/images/1024x768/').should be_true + FileUtils.rm_rf(RAILS_ROOT + '/public/images/1024x768/') + File.delete(RAILS_ROOT + '/public/images/1024x768.jpg') + end end