Commit b6a3b701b57abd10ca822ca4c519d58c9bbbd46b

Authored by Rodrigo Souto
Committed by Daniela Feitosa
1 parent 45b0f5da

Adding a new button to assets

app/views/search/_product.rhtml
@@ -5,9 +5,10 @@ product_item_pos = 0 if ! product_item_pos @@ -5,9 +5,10 @@ product_item_pos = 0 if ! product_item_pos
5 product_item_pos += 1 5 product_item_pos += 1
6 %> 6 %>
7 7
  8 +<% extra_content = @plugins.map(:asset_product_extras, product, product.enterprise).collect { |content| instance_eval(&content) } %>
  9 +
8 <li class="product-item <%= ( pos % 2 == 0 ) ? 'odd' : 'even' %>"> 10 <li class="product-item <%= ( pos % 2 == 0 ) ? 'odd' : 'even' %>">
9 - <%= link_to_product product, :class => 'product-pic', :style => 'background-image:url(%s)' %  
10 - ( product.image ? product.image.public_filename(:minor) : '/images/icons-app/product-default-pic-minor.png' ) %> 11 + <%= link_to_product product, :class => 'product-pic', :style => 'background-image:url(%s)' % product.default_image(:minor) %>
11 <strong> 12 <strong>
12 <%= link_to_product product %> 13 <%= link_to_product product %>
13 </strong> 14 </strong>
@@ -18,4 +19,7 @@ product_item_pos += 1 @@ -18,4 +19,7 @@ product_item_pos += 1
18 <% end %> 19 <% end %>
19 <li> <%=_('Category:') + ' ' + link_to_product_category(product.product_category) %> </li> 20 <li> <%=_('Category:') + ' ' + link_to_product_category(product.product_category) %> </li>
20 </ul> 21 </ul>
  22 +
  23 + <%= extra_content.join('\n') %>
  24 +
21 </li> 25 </li>
lib/noosfero/plugin.rb
@@ -103,6 +103,12 @@ class Noosfero::Plugin @@ -103,6 +103,12 @@ class Noosfero::Plugin
103 nil 103 nil
104 end 104 end
105 105
  106 + # -> Adds content to products on asset list
  107 + # returns = lambda block that creates a html code
  108 + def asset_product_extras(product, enterprise)
  109 + nil
  110 + end
  111 +
106 # -> Adds content to the beginning of the page 112 # -> Adds content to the beginning of the page
107 # returns = lambda block that creates html code or raw rhtml/html.erb 113 # returns = lambda block that creates html code or raw rhtml/html.erb
108 def body_beginning 114 def body_beginning
public/stylesheets/application.css
@@ -4590,6 +4590,7 @@ h1#agenda-title { @@ -4590,6 +4590,7 @@ h1#agenda-title {
4590 } 4590 }
4591 4591
4592 .search-results-type-product li.product-item { 4592 .search-results-type-product li.product-item {
  4593 + position: relative;
4593 height: 60px; 4594 height: 60px;
4594 overflow: hidden; 4595 overflow: hidden;
4595 } 4596 }
test/functional/search_controller_test.rb
@@ -289,6 +289,27 @@ class SearchControllerTest &lt; Test::Unit::TestCase @@ -289,6 +289,27 @@ class SearchControllerTest &lt; Test::Unit::TestCase
289 assert_equal [prod1], assigns(:results)[:products] 289 assert_equal [prod1], assigns(:results)[:products]
290 end 290 end
291 291
  292 + should 'include extra content supplied by plugins on product asset' do
  293 + enterprise = fast_create(Enterprise)
  294 + product = fast_create(Product, :enterprise_id => enterprise.id)
  295 + plugin1_local_variable = "Plugin1"
  296 + plugin1_content = lambda {"<span id='plugin1'>This is #{plugin1_local_variable} speaking!</span>"}
  297 + plugin2_local_variable = "Plugin2"
  298 + plugin2_content = lambda {"<span id='plugin2'>This is #{plugin2_local_variable} speaking!</span>"}
  299 + contents = [plugin1_content, plugin2_content]
  300 +
  301 + plugins = mock()
  302 + plugins.stubs(:enabled_plugins).returns([])
  303 + plugins.stubs(:map).with(:body_beginning).returns([])
  304 + plugins.stubs(:map).with(:asset_product_extras, product, enterprise).returns(contents)
  305 + Noosfero::Plugin::Manager.stubs(:new).returns(plugins)
  306 +
  307 + get :assets, :asset => 'products'
  308 +
  309 + assert_tag :tag => 'span', :content => 'This is ' + plugin1_local_variable + ' speaking!', :attributes => {:id => 'plugin1'}
  310 + assert_tag :tag => 'span', :content => 'This is ' + plugin2_local_variable + ' speaking!', :attributes => {:id => 'plugin2'}
  311 + end
  312 +
292 should 'paginate enterprise listing' do 313 should 'paginate enterprise listing' do
293 @controller.expects(:limit).returns(1) 314 @controller.expects(:limit).returns(1)
294 ent1 = create_profile_with_optional_category(Enterprise, 'teste 1') 315 ent1 = create_profile_with_optional_category(Enterprise, 'teste 1')