Commit 41aa926a283008a50fb45a136092b453c7eeee4f

Authored by Joenio Costa
Committed by Daniela Feitosa
1 parent 52abcfe2

Allowing themes to define addthis icon image

(ActionItem1982)
app/helpers/content_viewer_helper.rb
... ... @@ -60,4 +60,12 @@ module ContentViewerHelper
60 60 }
61 61 end
62 62  
  63 + def addthis_image_tag
  64 + if File.exists?(File.join(Rails.root, 'public', theme_path, 'images', 'addthis.gif'))
  65 + image_tag(File.join(theme_path, 'images', 'addthis.gif'), :border => 0, :alt => '')
  66 + else
  67 + image_tag("/images/bt-bookmark.gif", :width => 53, :height => 16, :border => 0, :alt => '')
  68 + end
  69 + end
  70 +
63 71 end
... ...
app/views/content_viewer/view_page.rhtml
... ... @@ -47,7 +47,8 @@
47 47 };
48 48 addthis_options = '<%= escape_javascript( NOOSFERO_CONF['addthis_options'] ) %>';
49 49 </script>
50   -<a href="http://www.addthis.com/bookmark.php" id="bt_addThis" target="_blank" onmouseover="return addthis_open(this, '', '[URL]')" onmouseout="addthis_close()" onclick="return addthis_sendto()"><img src="/images/bt-bookmark.gif" width="53" height="16" border="0" alt="" /></a><script type="text/javascript" src="http://s7.addthis.com/js/152/addthis_widget.js"></script>
  50 +<a href="http://www.addthis.com/bookmark.php" id="bt_addThis" target="_blank" onmouseover="return addthis_open(this, '', '[URL]')" onmouseout="addthis_close()" onclick="return addthis_sendto()"><%= addthis_image_tag %></a>
  51 +<script type="text/javascript" src="http://s7.addthis.com/js/152/addthis_widget.js"></script>
51 52 </div>
52 53 <% end %>
53 54  
... ...
test/unit/content_viewer_helper_test.rb
... ... @@ -115,6 +115,20 @@ class ContentViewerHelperTest &lt; Test::Unit::TestCase
115 115 assert_equal "http://www.facebook.com/sharer.php?s=100&p[title]=Some+title&p[summary]=This+is+a+test&p[url]=http%3A%2F%2Fnoosfero.org%2Fblog_helper_test%2Fsome-title&p[images][0]=http%3A%2F%2Fnoosfero.org%2Fimages%2Fx.png", addthis_facebook_url(a)
116 116 end
117 117  
  118 + should 'theme provides addthis custom icon' do
  119 + stubs(:session).returns({:theme => 'base'})
  120 + File.expects(:exists?).with(anything).returns(true)
  121 + Environment.any_instance.stubs(:default_hostname).returns('noosfero.org')
  122 + assert_match 'addthis.gif', addthis_image_tag
  123 + end
  124 +
  125 + should 'use default addthis icon if theme has no addthis.gif image' do
  126 + stubs(:session).returns({:theme => 'base'})
  127 + File.expects(:exists?).with(anything).returns(false)
  128 + Environment.any_instance.stubs(:default_hostname).returns('noosfero.org')
  129 + assert_match 'bt-bookmark.gif', addthis_image_tag
  130 + end
  131 +
118 132 protected
119 133  
120 134 include ActionView::Helpers::TextHelper
... ... @@ -138,3 +152,6 @@ end
138 152 def url_for(args = {})
139 153 ['http:/', args[:host], args[:profile], args[:page]].join('/')
140 154 end
  155 +def image_tag(file, args = {})
  156 + file
  157 +end
... ...