diff --git a/app/helpers/catalog_helper.rb b/app/helpers/catalog_helper.rb
index 2bfe021..84a7c4a 100644
--- a/app/helpers/catalog_helper.rb
+++ b/app/helpers/catalog_helper.rb
@@ -6,7 +6,7 @@ include ManageProductsHelper
def display_products_list(profile, products)
data = ''
products.each { |product|
-
+ extra_content = @plugins.map(:catalog_item_extras, product).collect { |content| instance_eval(&content) }
data << content_tag('li',
link_to_product(product, :class => 'product-pic', :style => 'background-image:url(%s)' % ( product.image ? product.image.public_filename(:portrait) : '/images/icons-app/product-default-pic-portrait.png' )) +
content_tag('h3', link_to_product(product)) +
@@ -14,7 +14,11 @@ include ManageProductsHelper
(product.price ? content_tag('li', _('Price: %s') % ( "%.2f" % product.price), :class => 'product_price') : '') +
content_tag('li', product_category_name(profile, product.product_category), :class => 'product_category')
) +
- (product.description ? content_tag('div', txt2html(product.description), :class => 'description') : tag('br', :style => 'clear:both')),
+ (product.description ? content_tag('div',
+ txt2html(product.description),
+ :class => 'description') : tag('br',
+ :style => 'clear:both')) +
+ extra_content.join("\n"),
:class => 'product')
}
content_tag('h1', _('Products/Services')) + content_tag('ul', data, :id => 'product_list')
diff --git a/app/views/layouts/application-ng.rhtml b/app/views/layouts/application-ng.rhtml
index a4e0e39..8e16388 100644
--- a/app/views/layouts/application-ng.rhtml
+++ b/app/views/layouts/application-ng.rhtml
@@ -13,10 +13,20 @@
<%= stylesheet_link_tag icon_theme_stylesheet_path %>
<%= stylesheet_link_tag theme_stylesheet_path %>
<%= stylesheet_link_tag jquery_ui_theme_stylesheet_path %>
+ <% @plugins.enabled_plugins.each do |plugin| %>
+ <% if plugin.stylesheet? %>
+ <%= stylesheet_tag plugin.class.public_path('style.css'), {} %>
+ <% end %>
+ <% end %>
<%# Add custom tags/styles/etc via content_for %>
<%= yield :head %>
<%= javascript_tag('render_all_jquery_ui_widgets()') %>
+ <% @plugins.enabled_plugins.each do |plugin| %>
+ <% plugin.js_files.each do |js_file| %>
+ <%= javascript_src_tag plugin.class.public_path(js_file), {} %>
+ <% end %>
+ <% end %>
<%= _("Go to the content") %>
+ <%=
+ @plugins.map(:body_beginning).collect do |content|
+ content.respond_to?(:call) ? content.call : content
+ end.join('\n')
+ %>
<%= render :partial => 'manage_products/display_info' %>
+ <% extra_content = @plugins.map(:product_info_extras, @product).collect { |content| instance_eval(&content) } %>
+ <%= extra_content.join("\n") %>
diff --git a/lib/noosfero/plugin.rb b/lib/noosfero/plugin.rb
index 5a22246..33cecd8 100644
--- a/lib/noosfero/plugin.rb
+++ b/lib/noosfero/plugin.rb
@@ -32,7 +32,15 @@ class Noosfero::Plugin
# Here the developer should specify the meta-informations that the plugin can
# inform.
def plugin_name
- self.to_s.underscore.humanize
+ self.name.underscore.humanize
+ end
+
+ def public_name
+ self.name.underscore.gsub('_plugin','')
+ end
+
+ def public_path(file = '')
+ compute_public_path((public_name + '/' + file), 'plugins')
end
def plugin_description
@@ -41,12 +49,18 @@ class Noosfero::Plugin
end
- def expanded_template(original_path, file_path, locals = {})
- while(File.basename(File.dirname(original_path)) != 'plugins')
- original_path = File.dirname(original_path)
- end
+ def expanded_template(file_path, locals = {})
+ views_path = "#{RAILS_ROOT}/plugins/#{self.class.public_name}/views"
+ ERB.new(File.read("#{views_path}/#{file_path}")).result(binding)
+ end
+
+ # 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.
- ERB.new(File.read("#{original_path}/#{file_path}")).result(binding)
+ # -> If true, noosfero will include plugin_dir/public/style.css into
+ # application
+ def stylesheet?
+ false
end
# Here the developer should specify the events to which the plugins can
@@ -72,4 +86,28 @@ class Noosfero::Plugin
nil
end
+ # -> Adds content to calalog item
+ # returns = lambda block that creates a html code
+ def catalog_item_extras(item)
+ nil
+ end
+
+ # -> Adds content to products info
+ # returns = lambda block that creates a html code
+ def product_info_extras(product)
+ nil
+ end
+
+ # -> Adds content to the beginning of the page
+ # returns = lambda block that creates html code or raw rhtml/html.erb
+ def body_beginning
+ nil
+ end
+
+ # -> Add plugins' javascript files to application
+ # returns = ['example1.js', 'javascripts/example2.js', 'example3.js']
+ def js_files
+ []
+ end
+
end
diff --git a/lib/noosfero/plugin/manager.rb b/lib/noosfero/plugin/manager.rb
index e57631c..95635f0 100644
--- a/lib/noosfero/plugin/manager.rb
+++ b/lib/noosfero/plugin/manager.rb
@@ -6,8 +6,12 @@ class Noosfero::Plugin::Manager
@context = Noosfero::Plugin::Context.new(controller)
end
- def map(event)
- enabled_plugins.map { |plugin| plugin.send(event) }.compact.flatten
+ def map(event, *args)
+ enabled_plugins.map { |plugin| plugin.send(event, *args) }.compact.flatten
+ end
+
+ def collect(&block)
+ enabled_plugins.collect(&block)
end
def enabled_plugins
diff --git a/plugins/mezuro/lib/mezuro_plugin.rb b/plugins/mezuro/lib/mezuro_plugin.rb
index 01d8384..8c317a4 100644
--- a/plugins/mezuro/lib/mezuro_plugin.rb
+++ b/plugins/mezuro/lib/mezuro_plugin.rb
@@ -19,7 +19,7 @@ class MezuroPlugin < Noosfero::Plugin
MezuroPlugin::Project.by_profile(context.profile).with_tab.map do |project|
{ :title => 'Mezuro ' + project.name,
:id => 'mezuro-project-'+project.identifier,
- :content => expanded_template(__FILE__,"views/show.html.erb",{:current_project => project}) }
+ :content => expanded_template("show.html.erb",{:current_project => project}) }
end
end
end
--
libgit2 0.21.2