Commit 08480dd52ab842eb70f16eea8e20d4477e131729
1 parent
0b0ad50d
Exists in
master
and in
29 other branches
New hotspot to add extra content at article header
Showing
3 changed files
with
34 additions
and
0 deletions
Show diff stats
app/views/content_viewer/_article_toolbar.rhtml
@@ -53,6 +53,7 @@ | @@ -53,6 +53,7 @@ | ||
53 | </div> | 53 | </div> |
54 | <div id="article-header"> | 54 | <div id="article-header"> |
55 | <%= link_to(image_tag('icons-mime/rss-feed.png'), @page.feed.url, :class => 'blog-feed-link') if @page.has_posts? && @page.feed %> | 55 | <%= link_to(image_tag('icons-mime/rss-feed.png'), @page.feed.url, :class => 'blog-feed-link') if @page.has_posts? && @page.feed %> |
56 | + <%= @plugins.dispatch(:article_header_extra_contents, @page).collect { |content| instance_eval(&content) }.join("") %> | ||
56 | <%= article_title(@page, :no_link => true) %> | 57 | <%= article_title(@page, :no_link => true) %> |
57 | <%= article_translations(@page) %> | 58 | <%= article_translations(@page) %> |
58 | </div> | 59 | </div> |
lib/noosfero/plugin.rb
@@ -449,6 +449,12 @@ class Noosfero::Plugin | @@ -449,6 +449,12 @@ class Noosfero::Plugin | ||
449 | nil | 449 | nil |
450 | end | 450 | end |
451 | 451 | ||
452 | + # -> Adds adicional content to article header | ||
453 | + # returns = lambda block that creates html code | ||
454 | + def article_header_extra_contents(article) | ||
455 | + nil | ||
456 | + end | ||
457 | + | ||
452 | # -> Finds objects by their contents | 458 | # -> Finds objects by their contents |
453 | # returns = {:results => [a, b, c, ...], ...} | 459 | # returns = {:results => [a, b, c, ...], ...} |
454 | # P.S.: The plugin might add other informations on the return hash for its | 460 | # P.S.: The plugin might add other informations on the return hash for its |
test/functional/content_viewer_controller_test.rb
@@ -1270,5 +1270,32 @@ class ContentViewerControllerTest < ActionController::TestCase | @@ -1270,5 +1270,32 @@ class ContentViewerControllerTest < ActionController::TestCase | ||
1270 | get :view_page, :profile => profile.identifier, :page => [blog.path] | 1270 | get :view_page, :profile => profile.identifier, :page => [blog.path] |
1271 | assert_tag :tag => 'strong', :content => /bold/ | 1271 | assert_tag :tag => 'strong', :content => /bold/ |
1272 | end | 1272 | end |
1273 | + | ||
1274 | + should 'add extra content on article header from plugins' do | ||
1275 | + class Plugin1 < Noosfero::Plugin | ||
1276 | + def article_header_extra_contents(args) | ||
1277 | + lambda { | ||
1278 | + content_tag('div', '', :class => 'plugin1') | ||
1279 | + } | ||
1280 | + end | ||
1281 | + end | ||
1282 | + class Plugin2 < Noosfero::Plugin | ||
1283 | + def article_header_extra_contents(args) | ||
1284 | + lambda { | ||
1285 | + content_tag('div', '', :class => 'plugin2') | ||
1286 | + } | ||
1287 | + end | ||
1288 | + end | ||
1289 | + | ||
1290 | + Environment.default.enable_plugin(Plugin1.name) | ||
1291 | + Environment.default.enable_plugin(Plugin2.name) | ||
1292 | + | ||
1293 | + page = profile.articles.create!(:name => 'myarticle', :body => 'the body of the text') | ||
1294 | + | ||
1295 | + xhr :get, :view_page, :profile => profile.identifier, :page => [ 'myarticle' ], :toolbar => true | ||
1296 | + | ||
1297 | + assert_tag :tag => 'div', :attributes => {:class => 'plugin1'} | ||
1298 | + assert_tag :tag => 'div', :attributes => {:class => 'plugin2'} | ||
1299 | + end | ||
1273 | 1300 | ||
1274 | end | 1301 | end |