adding swfobject embedding

This commit is contained in:
Donald Ball 2008-11-24 02:18:49 -06:00
parent 79b5706eda
commit dd8541c232
2 changed files with 10 additions and 4 deletions

View File

@ -1,10 +1,13 @@
module Zoomifier module Zoomifier
module ViewHelpers module ViewHelpers
def zoomify_image_tag(source, options = {}) def zoomify_image_tag(source, options = {})
raise ArgumentError unless options[:id] raise ArgumentError unless [:id, :width, :height].all? {|o| options[o] }
content_tag :div, { :id => options[:id] } do s = content_tag :div, { :id => options[:id] } do
image_tag source, options.merge({ :id => nil }) image_tag source, options.merge({ :id => nil })
end 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
end end
end end
end end

View File

@ -16,7 +16,10 @@ describe Zoomifier::ViewHelpers do
end end
it "should generate the zoomify markup" do it "should generate the zoomify markup" do
@view.zoomify_image_tag('foo.jpg', { :id => 'foo', :alt => 'Foo Bar' }).should == @view.zoomify_image_tag('foo.jpg', { :id => 'foo', :alt => 'Foo Bar', :width => 800, :height => 500 }).should ==
'<div id="foo"><img alt="Foo Bar" src="/images/foo.jpg" /></div>' '<div id="foo"><img alt="Foo Bar" height="500" src="/images/foo.jpg" width="800" /></div>' +
"<script type=\"text/javascript\">\n//<![CDATA[\n" +
"swfobject.embedSWF('/swf/zoomifyViewer.swf', 'foo', '800', '500', '9.0.0', false, { zoomifyImagePath: '/images/foo/' });\n//]]>\n" +
'</script>'
end end
end end