From f5c2a127d2e2de8bd51b558ed9a48098365584ad Mon Sep 17 00:00:00 2001 From: Rodrigo Souto Date: Thu, 19 Sep 2013 17:14:03 -0300 Subject: [PATCH] hotspot: refactor profile_image_link hotspot --- app/helpers/application_helper.rb | 2 +- lib/noosfero/plugin.rb | 4 ++-- lib/noosfero/plugin/manager.rb | 19 +++++-------------- test/unit/plugin_manager_test.rb | 4 ++++ 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index b34a693..2a74756 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -558,7 +558,7 @@ module ApplicationHelper # displays a link to the profile homepage with its image (as generated by # #profile_image) and its name below it. def profile_image_link( profile, size=:portrait, tag='li', extra_info = nil ) - if content = @plugins.first_impl(:profile_image_link, profile) + if content = @plugins.dispatch_first(:profile_image_link, profile, size, tag, extra_info) return instance_eval(&content) end name = profile.short_name diff --git a/lib/noosfero/plugin.rb b/lib/noosfero/plugin.rb index d100365..08d3ef6 100644 --- a/lib/noosfero/plugin.rb +++ b/lib/noosfero/plugin.rb @@ -152,7 +152,7 @@ class Noosfero::Plugin # Here the developer may specify the events to which the plugins can # register and must return true or false. The default value must be false. - # Must also explicitly defined its returning variables. + # Must also explicitly define its returning variables. # -> If true, noosfero will include plugin_dir/public/style.css into # application @@ -172,7 +172,7 @@ class Noosfero::Plugin # -> Customize profile block design and behavior # (overwrites profile_image_link function) # returns = lambda block that creates html code. - def profile_image_link profile + def profile_image_link(profile, size, tag, extra_info) nil end diff --git a/lib/noosfero/plugin/manager.rb b/lib/noosfero/plugin/manager.rb index e3682bd..d807898 100644 --- a/lib/noosfero/plugin/manager.rb +++ b/lib/noosfero/plugin/manager.rb @@ -31,32 +31,23 @@ class Noosfero::Plugin::Manager map { |plugin| plugin.send(event, *args) }.compact end - # return first implementation of a specific hotspot - def first_impl(event, *args) - default = Noosfero::Plugin.new.send(event, *args) - impl = default - each do |plugin| - impl = plugin.send(event, *args) - break if impl != default - end - impl - end - alias :dispatch_scopes :dispatch_without_flatten def dispatch_first(event, *args) - result = nil + default = Noosfero::Plugin.new.send(event, *args) + result = default each do |plugin| result = plugin.send(event, *args) - break if result.present? + break if result != default end result end def fetch_first_plugin(event, *args) + default = Noosfero::Plugin.new.send(event, *args) result = nil each do |plugin| - if plugin.send(event, *args) + if plugin.send(event, *args) != default result = plugin.class break end diff --git a/test/unit/plugin_manager_test.rb b/test/unit/plugin_manager_test.rb index f9ab0b7..a9f9603 100644 --- a/test/unit/plugin_manager_test.rb +++ b/test/unit/plugin_manager_test.rb @@ -61,6 +61,10 @@ class PluginManagerTest < ActiveSupport::TestCase end should 'dispatch_first method returns the first plugin response if there is many plugins to responde the event' do + class Noosfero::Plugin + def random_event + end + end class Plugin1 < Noosfero::Plugin def random_event -- libgit2 0.21.2