[noosfero/noosfero][next] 3 commits: adding article toolbar hotspot
Leandro Nunes
gitlab at gitlab.com
Tue Mar 31 13:32:48 BRT 2015
Leandro Nunes pushed to next at Noosfero / noosfero
Commits:
262fb4e6 by Leandro Nunes dos Santos at 2015-03-02T17:41:56Z
adding article toolbar hotspot
- - - - -
a8f1e7f9 by Leandro Nunes dos Santos at 2015-03-31T08:28:37Z
Merge branch 'add_hotspot_article_toolbar' into next
- - - - -
a79d01ab by Leandro Nunes dos Santos at 2015-03-31T13:32:40Z
hotspot: adding article_extra_toolbar_buttons hostspot
- - - - -
5 changed files:
- app/helpers/application_helper.rb
- app/views/content_viewer/_article_toolbar.html.erb
- lib/noosfero/plugin.rb
- test/functional/content_viewer_controller_test.rb
- test/unit/plugin_test.rb
Changes:
=====================================
app/helpers/application_helper.rb
=====================================
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -212,6 +212,7 @@ module ApplicationHelper
end
def button(type, label, url, html_options = {})
+ html_options ||= {}
the_class = 'with-text'
if html_options.has_key?(:class)
the_class << ' ' << html_options[:class]
=====================================
app/views/content_viewer/_article_toolbar.html.erb
=====================================
--- a/app/views/content_viewer/_article_toolbar.html.erb
+++ b/app/views/content_viewer/_article_toolbar.html.erb
@@ -46,6 +46,11 @@
<%= button(:clock, _('All versions'), {:controller => 'content_viewer', :profile => profile.identifier, :action => 'article_versions'}, :id => 'article-versions-link') %>
<% end %>
+ <% @plugins.dispatch(:article_extra_toolbar_buttons, @page).each do |plugin_button| %>
+ <%= button plugin_button[:icon], plugin_button[:title], plugin_button[:url], plugin_button[:html_options] %>
+ <% end %>
+
+
<%= report_abuse(profile, :link, @page) %>
</div>
=====================================
lib/noosfero/plugin.rb
=====================================
--- a/lib/noosfero/plugin.rb
+++ b/lib/noosfero/plugin.rb
@@ -426,6 +426,19 @@ class Noosfero::Plugin
[]
end
+ # -> Adds aditional action buttons to article
+ # returns = { :title => title, :icon => icon, :url => url, :html_options => {} }
+ # title = name that will be displayed.
+ # icon = css class name (for customized icons include them in a css file).
+ # url = url or route to which the button will redirect.
+ # html_options = Html options for customization
+ #
+ # Multiple values could be passed as parameter.
+ # returns = [{:title => title, :icon => icon}, {:title => title, :icon => icon}]
+ def article_extra_toolbar_buttons(article)
+ []
+ end
+
# -> Adds adicional content to article
# returns = lambda block that creates html code
def article_extra_contents(article)
=====================================
test/functional/content_viewer_controller_test.rb
=====================================
--- a/test/functional/content_viewer_controller_test.rb
+++ b/test/functional/content_viewer_controller_test.rb
@@ -1436,4 +1436,76 @@ class ContentViewerControllerTest < ActionController::TestCase
assert_no_tag :tag => 'h1', :attributes => { :class => /title/ }, :content => article.name
end
+
+ should 'add extra toolbar actions on article from plugins' do
+ class Plugin1 < Noosfero::Plugin
+ def article_extra_toolbar_buttons(article)
+ {:title => 'some_title1', :icon => 'some_icon1', :url => {}}
+ end
+ end
+ Noosfero::Plugin.stubs(:all).returns([Plugin1.name])
+
+ Environment.default.enable_plugin(Plugin1.name)
+
+ page = profile.articles.create!(:name => 'myarticle', :body => 'the body of the text')
+
+ get :view_page, :profile => profile.identifier, :page => [ 'myarticle' ]
+ assert_tag :tag => 'div', :attributes => { :id => 'article-actions' }, :descendant => { :tag => 'a', :attributes => { :title => "some_title1" }}
+ end
+
+ should 'add more than one extra toolbar actions on article from plugins' do
+ class Plugin1 < Noosfero::Plugin
+ def article_extra_toolbar_buttons(article)
+ {:title => 'some_title1', :icon => 'some_icon1', :url => {}}
+ end
+ end
+ class Plugin2 < Noosfero::Plugin
+ def article_extra_toolbar_buttons(article)
+ {:title => 'some_title2', :icon => 'some_icon2', :url => {}}
+ end
+ end
+ Noosfero::Plugin.stubs(:all).returns([Plugin1.name, Plugin2.name])
+
+ Environment.default.enable_plugin(Plugin1.name)
+ Environment.default.enable_plugin(Plugin2.name)
+
+ page = profile.articles.create!(:name => 'myarticle', :body => 'the body of the text')
+
+ get :view_page, :profile => profile.identifier, :page => [ 'myarticle' ]
+ assert_tag :tag => 'div', :attributes => { :id => 'article-actions' }, :descendant => { :tag => 'a', :attributes => { :title => "some_title1" }}
+ assert_tag :tag => 'div', :attributes => { :id => 'article-actions' }, :descendant => { :tag => 'a', :attributes => { :title => "some_title2" }}
+ end
+
+ should 'add icon attribute in extra toolbar actions on article from plugins' do
+ class Plugin1 < Noosfero::Plugin
+ def article_extra_toolbar_buttons(article)
+ {:title => 'some_title1', :icon => 'some_icon1', :url => {}}
+ end
+ end
+ Noosfero::Plugin.stubs(:all).returns([Plugin1.name])
+
+ Environment.default.enable_plugin(Plugin1.name)
+
+ page = profile.articles.create!(:name => 'myarticle', :body => 'the body of the text')
+
+ get :view_page, :profile => profile.identifier, :page => [ 'myarticle' ]
+ assert_tag :tag => 'div', :attributes => { :id => 'article-actions' }, :descendant => { :tag => 'a', :attributes => { :class => /some_icon1/ }}
+ end
+
+ should 'add url attribute in extra toolbar actions on article from plugins' do
+ class Plugin1 < Noosfero::Plugin
+ def article_extra_toolbar_buttons(article)
+ {:title => 'some_title1', :icon => 'some_icon1', :url => '/bli'}
+ end
+ end
+ Noosfero::Plugin.stubs(:all).returns([Plugin1.name])
+
+ Environment.default.enable_plugin(Plugin1.name)
+
+ page = profile.articles.create!(:name => 'myarticle', :body => 'the body of the text')
+
+ get :view_page, :profile => profile.identifier, :page => [ 'myarticle' ]
+ assert_tag :tag => 'div', :attributes => { :id => 'article-actions' }, :descendant => { :tag => 'a', :attributes => { :href => "/bli" }}
+ end
+
end
=====================================
test/unit/plugin_test.rb
=====================================
--- a/test/unit/plugin_test.rb
+++ b/test/unit/plugin_test.rb
@@ -560,4 +560,13 @@ class PluginTest < ActiveSupport::TestCase
assert_equivalent [st4.term, st2.term], limited_suggestions
end
+ should 'article_extra_toolbar_buttons return an empty array by default' do
+ class CustomBlock1 < Block; end;
+
+ class Plugin1 < Noosfero::Plugin
+ end
+ p = Plugin1.new
+ assert_equal [], p.article_extra_toolbar_buttons(nil)
+ end
+
end
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/fe3c0b17eb9366bd157e8c85ee9fec00a62cbed5...a79d01ab7f327b07409c24efa5e0fba73626d076
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20150331/a4699441/attachment.html>
More information about the Noosfero-dev
mailing list