From 08480dd52ab842eb70f16eea8e20d4477e131729 Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Thu, 5 Dec 2013 11:20:08 -0300 Subject: [PATCH] New hotspot to add extra content at article header --- app/views/content_viewer/_article_toolbar.rhtml | 1 + lib/noosfero/plugin.rb | 6 ++++++ test/functional/content_viewer_controller_test.rb | 27 +++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 0 deletions(-) diff --git a/app/views/content_viewer/_article_toolbar.rhtml b/app/views/content_viewer/_article_toolbar.rhtml index aee80d5..e83ad4e 100644 --- a/app/views/content_viewer/_article_toolbar.rhtml +++ b/app/views/content_viewer/_article_toolbar.rhtml @@ -53,6 +53,7 @@
<%= link_to(image_tag('icons-mime/rss-feed.png'), @page.feed.url, :class => 'blog-feed-link') if @page.has_posts? && @page.feed %> + <%= @plugins.dispatch(:article_header_extra_contents, @page).collect { |content| instance_eval(&content) }.join("") %> <%= article_title(@page, :no_link => true) %> <%= article_translations(@page) %>
diff --git a/lib/noosfero/plugin.rb b/lib/noosfero/plugin.rb index 8fc0061..7b7e03a 100644 --- a/lib/noosfero/plugin.rb +++ b/lib/noosfero/plugin.rb @@ -449,6 +449,12 @@ class Noosfero::Plugin nil end + # -> Adds adicional content to article header + # returns = lambda block that creates html code + def article_header_extra_contents(article) + nil + end + # -> Finds objects by their contents # returns = {:results => [a, b, c, ...], ...} # P.S.: The plugin might add other informations on the return hash for its diff --git a/test/functional/content_viewer_controller_test.rb b/test/functional/content_viewer_controller_test.rb index f103e79..a25ed4d 100644 --- a/test/functional/content_viewer_controller_test.rb +++ b/test/functional/content_viewer_controller_test.rb @@ -1270,5 +1270,32 @@ class ContentViewerControllerTest < ActionController::TestCase get :view_page, :profile => profile.identifier, :page => [blog.path] assert_tag :tag => 'strong', :content => /bold/ end + + should 'add extra content on article header from plugins' do + class Plugin1 < Noosfero::Plugin + def article_header_extra_contents(args) + lambda { + content_tag('div', '', :class => 'plugin1') + } + end + end + class Plugin2 < Noosfero::Plugin + def article_header_extra_contents(args) + lambda { + content_tag('div', '', :class => 'plugin2') + } + end + end + + Environment.default.enable_plugin(Plugin1.name) + Environment.default.enable_plugin(Plugin2.name) + + page = profile.articles.create!(:name => 'myarticle', :body => 'the body of the text') + + xhr :get, :view_page, :profile => profile.identifier, :page => [ 'myarticle' ], :toolbar => true + + assert_tag :tag => 'div', :attributes => {:class => 'plugin1'} + assert_tag :tag => 'div', :attributes => {:class => 'plugin2'} + end end -- libgit2 0.21.2