Commit 071c3d7992625c53fa52d8c3af8e26531892b63b
Committed by
Daniela Feitosa
1 parent
e7d2150d
Exists in
master
and in
29 other branches
Adding hot spots and fixing somethings
* Hot Spots: - Catalog item extra content - Stylesheet - JS - Application body extra content - Product info extra content * Plugin new methods - Public name - Public path * Plugin manager - Fixing map and adding collect method * Fixes: - Expand template method
Showing
6 changed files
with
74 additions
and
11 deletions
Show diff stats
app/helpers/catalog_helper.rb
@@ -6,7 +6,7 @@ include ManageProductsHelper | @@ -6,7 +6,7 @@ include ManageProductsHelper | ||
6 | def display_products_list(profile, products) | 6 | def display_products_list(profile, products) |
7 | data = '' | 7 | data = '' |
8 | products.each { |product| | 8 | products.each { |product| |
9 | - | 9 | + extra_content = @plugins.map(:catalog_item_extras, product).collect { |content| instance_eval(&content) } |
10 | data << content_tag('li', | 10 | data << content_tag('li', |
11 | 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' )) + | 11 | 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' )) + |
12 | content_tag('h3', link_to_product(product)) + | 12 | content_tag('h3', link_to_product(product)) + |
@@ -14,7 +14,11 @@ include ManageProductsHelper | @@ -14,7 +14,11 @@ include ManageProductsHelper | ||
14 | (product.price ? content_tag('li', _('Price: %s') % ( "%.2f" % product.price), :class => 'product_price') : '') + | 14 | (product.price ? content_tag('li', _('Price: %s') % ( "%.2f" % product.price), :class => 'product_price') : '') + |
15 | content_tag('li', product_category_name(profile, product.product_category), :class => 'product_category') | 15 | content_tag('li', product_category_name(profile, product.product_category), :class => 'product_category') |
16 | ) + | 16 | ) + |
17 | - (product.description ? content_tag('div', txt2html(product.description), :class => 'description') : tag('br', :style => 'clear:both')), | 17 | + (product.description ? content_tag('div', |
18 | + txt2html(product.description), | ||
19 | + :class => 'description') : tag('br', | ||
20 | + :style => 'clear:both')) + | ||
21 | + extra_content.join("\n"), | ||
18 | :class => 'product') | 22 | :class => 'product') |
19 | } | 23 | } |
20 | content_tag('h1', _('Products/Services')) + content_tag('ul', data, :id => 'product_list') | 24 | content_tag('h1', _('Products/Services')) + content_tag('ul', data, :id => 'product_list') |
app/views/layouts/application-ng.rhtml
@@ -13,10 +13,20 @@ | @@ -13,10 +13,20 @@ | ||
13 | <%= stylesheet_link_tag icon_theme_stylesheet_path %> | 13 | <%= stylesheet_link_tag icon_theme_stylesheet_path %> |
14 | <%= stylesheet_link_tag theme_stylesheet_path %> | 14 | <%= stylesheet_link_tag theme_stylesheet_path %> |
15 | <%= stylesheet_link_tag jquery_ui_theme_stylesheet_path %> | 15 | <%= stylesheet_link_tag jquery_ui_theme_stylesheet_path %> |
16 | + <% @plugins.enabled_plugins.each do |plugin| %> | ||
17 | + <% if plugin.stylesheet? %> | ||
18 | + <%= stylesheet_tag plugin.class.public_path('style.css'), {} %> | ||
19 | + <% end %> | ||
20 | + <% end %> | ||
16 | 21 | ||
17 | <%# Add custom tags/styles/etc via content_for %> | 22 | <%# Add custom tags/styles/etc via content_for %> |
18 | <%= yield :head %> | 23 | <%= yield :head %> |
19 | <%= javascript_tag('render_all_jquery_ui_widgets()') %> | 24 | <%= javascript_tag('render_all_jquery_ui_widgets()') %> |
25 | + <% @plugins.enabled_plugins.each do |plugin| %> | ||
26 | + <% plugin.js_files.each do |js_file| %> | ||
27 | + <%= javascript_src_tag plugin.class.public_path(js_file), {} %> | ||
28 | + <% end %> | ||
29 | + <% end %> | ||
20 | </head> | 30 | </head> |
21 | <body class="<%= | 31 | <body class="<%= |
22 | # Identify the current controller and action for the CSS: | 32 | # Identify the current controller and action for the CSS: |
@@ -27,6 +37,11 @@ | @@ -27,6 +37,11 @@ | ||
27 | %>" > | 37 | %>" > |
28 | 38 | ||
29 | <a href="#content" id="link-go-content"><span><%= _("Go to the content") %></span></a> | 39 | <a href="#content" id="link-go-content"><span><%= _("Go to the content") %></span></a> |
40 | + <%= | ||
41 | + @plugins.map(:body_beginning).collect do |content| | ||
42 | + content.respond_to?(:call) ? content.call : content | ||
43 | + end.join('\n') | ||
44 | + %> | ||
30 | 45 | ||
31 | <div id="wrap-1"> | 46 | <div id="wrap-1"> |
32 | <div id='theme-header'> | 47 | <div id='theme-header'> |
app/views/manage_products/show.rhtml
@@ -14,6 +14,8 @@ | @@ -14,6 +14,8 @@ | ||
14 | </div> | 14 | </div> |
15 | <div id='product-info'> | 15 | <div id='product-info'> |
16 | <%= render :partial => 'manage_products/display_info' %> | 16 | <%= render :partial => 'manage_products/display_info' %> |
17 | + <% extra_content = @plugins.map(:product_info_extras, @product).collect { |content| instance_eval(&content) } %> | ||
18 | + <%= extra_content.join("\n") %> | ||
17 | </div> | 19 | </div> |
18 | </div> | 20 | </div> |
19 | 21 |
lib/noosfero/plugin.rb
@@ -32,7 +32,15 @@ class Noosfero::Plugin | @@ -32,7 +32,15 @@ class Noosfero::Plugin | ||
32 | # Here the developer should specify the meta-informations that the plugin can | 32 | # Here the developer should specify the meta-informations that the plugin can |
33 | # inform. | 33 | # inform. |
34 | def plugin_name | 34 | def plugin_name |
35 | - self.to_s.underscore.humanize | 35 | + self.name.underscore.humanize |
36 | + end | ||
37 | + | ||
38 | + def public_name | ||
39 | + self.name.underscore.gsub('_plugin','') | ||
40 | + end | ||
41 | + | ||
42 | + def public_path(file = '') | ||
43 | + compute_public_path((public_name + '/' + file), 'plugins') | ||
36 | end | 44 | end |
37 | 45 | ||
38 | def plugin_description | 46 | def plugin_description |
@@ -41,12 +49,18 @@ class Noosfero::Plugin | @@ -41,12 +49,18 @@ class Noosfero::Plugin | ||
41 | 49 | ||
42 | end | 50 | end |
43 | 51 | ||
44 | - def expanded_template(original_path, file_path, locals = {}) | ||
45 | - while(File.basename(File.dirname(original_path)) != 'plugins') | ||
46 | - original_path = File.dirname(original_path) | ||
47 | - end | 52 | + def expanded_template(file_path, locals = {}) |
53 | + views_path = "#{RAILS_ROOT}/plugins/#{self.class.public_name}/views" | ||
54 | + ERB.new(File.read("#{views_path}/#{file_path}")).result(binding) | ||
55 | + end | ||
56 | + | ||
57 | + # Here the developer may specify the events to which the plugins can | ||
58 | + # register and must return true or false. The default value must be false. | ||
48 | 59 | ||
49 | - ERB.new(File.read("#{original_path}/#{file_path}")).result(binding) | 60 | + # -> If true, noosfero will include plugin_dir/public/style.css into |
61 | + # application | ||
62 | + def stylesheet? | ||
63 | + false | ||
50 | end | 64 | end |
51 | 65 | ||
52 | # Here the developer should specify the events to which the plugins can | 66 | # Here the developer should specify the events to which the plugins can |
@@ -72,4 +86,28 @@ class Noosfero::Plugin | @@ -72,4 +86,28 @@ class Noosfero::Plugin | ||
72 | nil | 86 | nil |
73 | end | 87 | end |
74 | 88 | ||
89 | + # -> Adds content to calalog item | ||
90 | + # returns = lambda block that creates a html code | ||
91 | + def catalog_item_extras(item) | ||
92 | + nil | ||
93 | + end | ||
94 | + | ||
95 | + # -> Adds content to products info | ||
96 | + # returns = lambda block that creates a html code | ||
97 | + def product_info_extras(product) | ||
98 | + nil | ||
99 | + end | ||
100 | + | ||
101 | + # -> Adds content to the beginning of the page | ||
102 | + # returns = lambda block that creates html code or raw rhtml/html.erb | ||
103 | + def body_beginning | ||
104 | + nil | ||
105 | + end | ||
106 | + | ||
107 | + # -> Add plugins' javascript files to application | ||
108 | + # returns = ['example1.js', 'javascripts/example2.js', 'example3.js'] | ||
109 | + def js_files | ||
110 | + [] | ||
111 | + end | ||
112 | + | ||
75 | end | 113 | end |
lib/noosfero/plugin/manager.rb
@@ -6,8 +6,12 @@ class Noosfero::Plugin::Manager | @@ -6,8 +6,12 @@ class Noosfero::Plugin::Manager | ||
6 | @context = Noosfero::Plugin::Context.new(controller) | 6 | @context = Noosfero::Plugin::Context.new(controller) |
7 | end | 7 | end |
8 | 8 | ||
9 | - def map(event) | ||
10 | - enabled_plugins.map { |plugin| plugin.send(event) }.compact.flatten | 9 | + def map(event, *args) |
10 | + enabled_plugins.map { |plugin| plugin.send(event, *args) }.compact.flatten | ||
11 | + end | ||
12 | + | ||
13 | + def collect(&block) | ||
14 | + enabled_plugins.collect(&block) | ||
11 | end | 15 | end |
12 | 16 | ||
13 | def enabled_plugins | 17 | def enabled_plugins |
plugins/mezuro/lib/mezuro_plugin.rb
@@ -19,7 +19,7 @@ class MezuroPlugin < Noosfero::Plugin | @@ -19,7 +19,7 @@ class MezuroPlugin < Noosfero::Plugin | ||
19 | MezuroPlugin::Project.by_profile(context.profile).with_tab.map do |project| | 19 | MezuroPlugin::Project.by_profile(context.profile).with_tab.map do |project| |
20 | { :title => 'Mezuro ' + project.name, | 20 | { :title => 'Mezuro ' + project.name, |
21 | :id => 'mezuro-project-'+project.identifier, | 21 | :id => 'mezuro-project-'+project.identifier, |
22 | - :content => expanded_template(__FILE__,"views/show.html.erb",{:current_project => project}) } | 22 | + :content => expanded_template("show.html.erb",{:current_project => project}) } |
23 | end | 23 | end |
24 | end | 24 | end |
25 | end | 25 | end |