Commit a79d01ab7f327b07409c24efa5e0fba73626d076
1 parent
a8f1e7f9
Exists in
master
and in
26 other branches
hotspot: adding article_extra_toolbar_buttons hostspot
Showing
5 changed files
with
97 additions
and
5 deletions
Show diff stats
app/helpers/application_helper.rb
app/views/content_viewer/_article_toolbar.html.erb
| ... | ... | @@ -46,7 +46,10 @@ |
| 46 | 46 | <%= button(:clock, _('All versions'), {:controller => 'content_viewer', :profile => profile.identifier, :action => 'article_versions'}, :id => 'article-versions-link') %> |
| 47 | 47 | <% end %> |
| 48 | 48 | |
| 49 | - <%= @plugins.dispatch(:article_toolbar_actions, @page).collect { |content| instance_exec(&content) }.join("")%> | |
| 49 | + <% @plugins.dispatch(:article_extra_toolbar_buttons, @page).each do |plugin_button| %> | |
| 50 | + <%= button plugin_button[:icon], plugin_button[:title], plugin_button[:url], plugin_button[:html_options] %> | |
| 51 | + <% end %> | |
| 52 | + | |
| 50 | 53 | |
| 51 | 54 | <%= report_abuse(profile, :link, @page) %> |
| 52 | 55 | ... | ... |
lib/noosfero/plugin.rb
| ... | ... | @@ -426,10 +426,17 @@ class Noosfero::Plugin |
| 426 | 426 | [] |
| 427 | 427 | end |
| 428 | 428 | |
| 429 | - # -> Adds aditional actions to article | |
| 430 | - # returns = lambda block that creates html code | |
| 431 | - def article_toolbar_actions article | |
| 432 | - nil | |
| 429 | + # -> Adds aditional action buttons to article | |
| 430 | + # returns = { :title => title, :icon => icon, :url => url, :html_options => {} } | |
| 431 | + # title = name that will be displayed. | |
| 432 | + # icon = css class name (for customized icons include them in a css file). | |
| 433 | + # url = url or route to which the button will redirect. | |
| 434 | + # html_options = Html options for customization | |
| 435 | + # | |
| 436 | + # Multiple values could be passed as parameter. | |
| 437 | + # returns = [{:title => title, :icon => icon}, {:title => title, :icon => icon}] | |
| 438 | + def article_extra_toolbar_buttons(article) | |
| 439 | + [] | |
| 433 | 440 | end |
| 434 | 441 | |
| 435 | 442 | # -> Adds adicional content to article | ... | ... |
test/functional/content_viewer_controller_test.rb
| ... | ... | @@ -1436,4 +1436,76 @@ class ContentViewerControllerTest < ActionController::TestCase |
| 1436 | 1436 | |
| 1437 | 1437 | assert_no_tag :tag => 'h1', :attributes => { :class => /title/ }, :content => article.name |
| 1438 | 1438 | end |
| 1439 | + | |
| 1440 | + should 'add extra toolbar actions on article from plugins' do | |
| 1441 | + class Plugin1 < Noosfero::Plugin | |
| 1442 | + def article_extra_toolbar_buttons(article) | |
| 1443 | + {:title => 'some_title1', :icon => 'some_icon1', :url => {}} | |
| 1444 | + end | |
| 1445 | + end | |
| 1446 | + Noosfero::Plugin.stubs(:all).returns([Plugin1.name]) | |
| 1447 | + | |
| 1448 | + Environment.default.enable_plugin(Plugin1.name) | |
| 1449 | + | |
| 1450 | + page = profile.articles.create!(:name => 'myarticle', :body => 'the body of the text') | |
| 1451 | + | |
| 1452 | + get :view_page, :profile => profile.identifier, :page => [ 'myarticle' ] | |
| 1453 | + assert_tag :tag => 'div', :attributes => { :id => 'article-actions' }, :descendant => { :tag => 'a', :attributes => { :title => "some_title1" }} | |
| 1454 | + end | |
| 1455 | + | |
| 1456 | + should 'add more than one extra toolbar actions on article from plugins' do | |
| 1457 | + class Plugin1 < Noosfero::Plugin | |
| 1458 | + def article_extra_toolbar_buttons(article) | |
| 1459 | + {:title => 'some_title1', :icon => 'some_icon1', :url => {}} | |
| 1460 | + end | |
| 1461 | + end | |
| 1462 | + class Plugin2 < Noosfero::Plugin | |
| 1463 | + def article_extra_toolbar_buttons(article) | |
| 1464 | + {:title => 'some_title2', :icon => 'some_icon2', :url => {}} | |
| 1465 | + end | |
| 1466 | + end | |
| 1467 | + Noosfero::Plugin.stubs(:all).returns([Plugin1.name, Plugin2.name]) | |
| 1468 | + | |
| 1469 | + Environment.default.enable_plugin(Plugin1.name) | |
| 1470 | + Environment.default.enable_plugin(Plugin2.name) | |
| 1471 | + | |
| 1472 | + page = profile.articles.create!(:name => 'myarticle', :body => 'the body of the text') | |
| 1473 | + | |
| 1474 | + get :view_page, :profile => profile.identifier, :page => [ 'myarticle' ] | |
| 1475 | + assert_tag :tag => 'div', :attributes => { :id => 'article-actions' }, :descendant => { :tag => 'a', :attributes => { :title => "some_title1" }} | |
| 1476 | + assert_tag :tag => 'div', :attributes => { :id => 'article-actions' }, :descendant => { :tag => 'a', :attributes => { :title => "some_title2" }} | |
| 1477 | + end | |
| 1478 | + | |
| 1479 | + should 'add icon attribute in extra toolbar actions on article from plugins' do | |
| 1480 | + class Plugin1 < Noosfero::Plugin | |
| 1481 | + def article_extra_toolbar_buttons(article) | |
| 1482 | + {:title => 'some_title1', :icon => 'some_icon1', :url => {}} | |
| 1483 | + end | |
| 1484 | + end | |
| 1485 | + Noosfero::Plugin.stubs(:all).returns([Plugin1.name]) | |
| 1486 | + | |
| 1487 | + Environment.default.enable_plugin(Plugin1.name) | |
| 1488 | + | |
| 1489 | + page = profile.articles.create!(:name => 'myarticle', :body => 'the body of the text') | |
| 1490 | + | |
| 1491 | + get :view_page, :profile => profile.identifier, :page => [ 'myarticle' ] | |
| 1492 | + assert_tag :tag => 'div', :attributes => { :id => 'article-actions' }, :descendant => { :tag => 'a', :attributes => { :class => /some_icon1/ }} | |
| 1493 | + end | |
| 1494 | + | |
| 1495 | + should 'add url attribute in extra toolbar actions on article from plugins' do | |
| 1496 | + class Plugin1 < Noosfero::Plugin | |
| 1497 | + def article_extra_toolbar_buttons(article) | |
| 1498 | + {:title => 'some_title1', :icon => 'some_icon1', :url => '/bli'} | |
| 1499 | + end | |
| 1500 | + end | |
| 1501 | + Noosfero::Plugin.stubs(:all).returns([Plugin1.name]) | |
| 1502 | + | |
| 1503 | + Environment.default.enable_plugin(Plugin1.name) | |
| 1504 | + | |
| 1505 | + page = profile.articles.create!(:name => 'myarticle', :body => 'the body of the text') | |
| 1506 | + | |
| 1507 | + get :view_page, :profile => profile.identifier, :page => [ 'myarticle' ] | |
| 1508 | + assert_tag :tag => 'div', :attributes => { :id => 'article-actions' }, :descendant => { :tag => 'a', :attributes => { :href => "/bli" }} | |
| 1509 | + end | |
| 1510 | + | |
| 1439 | 1511 | end | ... | ... |
test/unit/plugin_test.rb
| ... | ... | @@ -560,4 +560,13 @@ class PluginTest < ActiveSupport::TestCase |
| 560 | 560 | assert_equivalent [st4.term, st2.term], limited_suggestions |
| 561 | 561 | end |
| 562 | 562 | |
| 563 | + should 'article_extra_toolbar_buttons return an empty array by default' do | |
| 564 | + class CustomBlock1 < Block; end; | |
| 565 | + | |
| 566 | + class Plugin1 < Noosfero::Plugin | |
| 567 | + end | |
| 568 | + p = Plugin1.new | |
| 569 | + assert_equal [], p.article_extra_toolbar_buttons(nil) | |
| 570 | + end | |
| 571 | + | |
| 563 | 572 | end | ... | ... |