[Git][noosfero/noosfero][master] 2 commits: Remove InterestsBlock#content method

Bráulio Bhavamitra gitlab at mg.gitlab.com
Fri May 13 19:04:04 BRT 2016


Bráulio Bhavamitra pushed to branch master at Noosfero / noosfero


Commits:
ced5fa14 by Rafael Reggiani Manzo at 2016-05-12T11:57:21-03:00
Remove InterestsBlock#content method

This removes html generation from the class improving MVC responsability
separation.

It required the creation of a new method, interests, and view
move/rename.

- - - - -
8b0cf64a by Bráulio Bhavamitra at 2016-05-13T22:03:44+00:00
Merge branch 'refactor_sniffer' into 'master'

Remove InterestsBlock#content method

This removes html generation from the class improving MVC responsability
separation.

It required the creation of a new method, interests, and view
move/rename.

See merge request !916
- - - - -


2 changed files:

- plugins/sniffer/lib/sniffer_plugin/interests_block.rb
- plugins/sniffer/views/blocks/sniffer_plugin/interests_block.html.erb → plugins/sniffer/views/blocks/interests.html.erb


Changes:

=====================================
plugins/sniffer/lib/sniffer_plugin/interests_block.rb
=====================================
--- a/plugins/sniffer/lib/sniffer_plugin/interests_block.rb
+++ b/plugins/sniffer/lib/sniffer_plugin/interests_block.rb
@@ -16,22 +16,20 @@ class SnifferPlugin::InterestsBlock < Block
     _("This block show interests of your profile or environment")
   end
 
-  def content(args = {})
-    block = self
+  def interests
+    results = nil
     profile = block.owner
-    proc do
-      if block.owner.is_a?(Profile)
-        interests = profile.snnifer_opportunities
-        interests |= profile.inputs if sniffer.profile.enterprise?
-      else # Environment
-        interests = SnifferPlugin::Opportunity.product_categories.limit(5).order('created_at DESC').all
-        interests += Input.limit(5).order('created_at DESC').all
-        interests.sort{ |a, b| -1 * a.created_at.to_i <=> b.created_at.to_i }
-      end
-
-      render :file => 'blocks/sniffer_plugin/interests_block',
-        :locals => {:block => block, :interests => interests}
+
+    if profile.is_a?(Profile)
+      results = profile.snnifer_opportunities
+      results |= profile.inputs if sniffer.profile.enterprise?
+    else # Environment
+      results = SnifferPlugin::Opportunity.product_categories.limit(5).order('created_at DESC').all
+      results += Input.limit(5).order('created_at DESC').all
+      results.sort{ |a, b| -1 * a.created_at.to_i <=> b.created_at.to_i }
     end
+
+    return results
   end
 
 end


=====================================
plugins/sniffer/views/blocks/sniffer_plugin/interests_block.html.erb → plugins/sniffer/views/blocks/interests.html.erb
=====================================
--- a/plugins/sniffer/views/blocks/sniffer_plugin/interests_block.html.erb
+++ b/plugins/sniffer/views/blocks/interests.html.erb
@@ -2,14 +2,14 @@
 
 <% if block.owner.is_a?(Profile) %>
   <ul>
-    <% interests.each do |interest| %>
+    <% block.interests.each do |interest| %>
       <li><%= interest.product_category.name %></li>
     <% end %>
   </ul>
 
   <div>
     <% if logged_in? and (current_user.person.is_admin?(environment) or profile.admins.include?(current_user.person)) %>
-      <%= _('Edit %{inputs} and %{interests}') % {
+      <%= _('Edit %{inputs} and %{block.interests}') % {
         :inputs => link_to(_("products' inputs"), :controller => :manage_products, :action => :index),
         :interests => link_to(_('declared interests'), :controller => :sniffer_plugin_myprofile, :action => :edit),
       } %>
@@ -17,7 +17,7 @@
   </div>
 <% else %>
   <ul>
-    <% interests.each do |interest| %>
+    <% block.interests.each do |interest| %>
       <li>
         <% profile = interest.is_a?(SnifferPlugin::Opportunity) ? interest.profile : interest.product.enterprise %>
         <%= _('%{interest} from %{profile}') % {



View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/b473c5019edc9123843b7217d1f0ecae11062852...8b0cf64aae88ed3a3ad9e2a62ebedf9c54064a49
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20160513/fc95970e/attachment-0001.html>


More information about the Noosfero-dev mailing list