Commit a837f96c9e1a01a4160248d565569b51cdf2c77f

Authored by Joenio Costa
1 parent 498e40b7

Adding Plugin hotspot 'parse_content'

also:
- fix noosfero/i18n: error_messages_for should works as documented in
  Rails API (accept param :header_message => '...')
- new helper method to display errors in a dialog box
- now Plugins knows what is URL to admin itself
- defining paths to cucumber steps and setup files in config/cucumber.yml
- allow plugins to have documentation in same way as Noosfero core

(ActionItem2056)
app/controllers/application.rb
... ... @@ -25,11 +25,6 @@ class ApplicationController < ActionController::Base
25 25 helper :document
26 26 helper :language
27 27  
28   - def boxes_editor?
29   - false
30   - end
31   - protected :boxes_editor?
32   -
33 28 def self.no_design_blocks
34 29 @no_design_blocks = true
35 30 end
... ... @@ -106,6 +101,14 @@ class ApplicationController < ActionController::Base
106 101  
107 102 protected
108 103  
  104 + def boxes_editor?
  105 + false
  106 + end
  107 +
  108 + def content_editor?
  109 + false
  110 + end
  111 +
109 112 def user
110 113 current_user.person if logged_in?
111 114 end
... ...
app/controllers/my_profile/cms_controller.rb
... ... @@ -383,5 +383,9 @@ class CmsController < MyProfileController
383 383 @selected_locale = @article.language || FastGettext.locale
384 384 end
385 385  
  386 + def content_editor?
  387 + true
  388 + end
  389 +
386 390 end
387 391  
... ...
app/controllers/my_profile/manage_products_controller.rb
... ... @@ -50,7 +50,7 @@ class ManageProductsController < ApplicationController
50 50 render :partial => 'shared/redirect_via_javascript',
51 51 :locals => { :url => url_for(:controller => 'manage_products', :action => 'show', :id => @product) }
52 52 else
53   - render :partial => 'shared/dialog_error_messages', :locals => { :object_name => 'product' }
  53 + render_dialog_error_messages 'product'
54 54 end
55 55 end
56 56 end
... ... @@ -81,7 +81,7 @@ class ManageProductsController < ApplicationController
81 81 render :partial => 'shared/redirect_via_javascript',
82 82 :locals => { :url => url_for(:controller => 'manage_products', :action => 'show', :id => @product) }
83 83 else
84   - render :partial => 'shared/dialog_error_messages', :locals => { :object_name => 'product' }
  84 + render_dialog_error_messages 'product'
85 85 end
86 86 end
87 87 end
... ... @@ -96,7 +96,7 @@ class ManageProductsController < ApplicationController
96 96 @inputs = @product.inputs
97 97 render :partial => 'display_inputs'
98 98 else
99   - render :partial => 'shared/dialog_error_messages', :locals => { :object_name => 'product' }
  99 + render_dialog_error_messages 'product'
100 100 end
101 101 else
102 102 render :partial => 'add_input'
... ... @@ -147,7 +147,7 @@ class ManageProductsController < ApplicationController
147 147 @inputs = @product.inputs
148 148 render :partial => 'display_inputs'
149 149 else
150   - render :partial => 'shared/dialog_error_messages', :locals => { :object_name => 'input' }
  150 + render_dialog_error_messages 'input'
151 151 end
152 152 end
153 153 end
... ...
app/helpers/application_helper.rb
... ... @@ -980,7 +980,10 @@ module ApplicationHelper
980 980 def article_to_html(article, options = {})
981 981 options.merge!(:page => params[:npage])
982 982 content = article.to_html(options)
983   - return self.instance_eval(&content) if content.kind_of?(Proc)
  983 + content = content.kind_of?(Proc) ? self.instance_eval(&content) : content
  984 + @plugins && @plugins.enabled_plugins.each do |plugin|
  985 + content = plugin.parse_content(content)
  986 + end
984 987 content
985 988 end
986 989  
... ... @@ -1221,4 +1224,8 @@ module ApplicationHelper
1221 1224 end
1222 1225 end
1223 1226  
  1227 + def render_dialog_error_messages(instance_name)
  1228 + render :partial => 'shared/dialog_error_messages', :locals => { :object_name => instance_name }
  1229 + end
  1230 +
1224 1231 end
... ...
app/helpers/boxes_helper.rb
... ... @@ -99,7 +99,9 @@ module BoxesHelper
99 99 unless block.visible?
100 100 options[:title] = _("This block is invisible. Your visitors will not see it.")
101 101 end
102   -
  102 + @controller.send(:content_editor?) || @plugins.enabled_plugins.each do |plugin|
  103 + result = plugin.parse_content(result)
  104 + end
103 105 box_decorator.block_target(block.box, block) +
104 106 content_tag('div',
105 107 content_tag('div',
... ...
app/views/manage_products/_edit_image.rhtml
... ... @@ -22,5 +22,5 @@
22 22 </script>
23 23  
24 24 <% if errors %>
25   - <%= render :partial => 'shared/dialog_error_messages', :locals => { :object_name => 'product' } %>
  25 + <%= render_dialog_error_messages 'product' %>
26 26 <% end %>
... ...
app/views/manage_products/_edit_info.rhtml
1 1 <% if errors %>
2   - <%= render :partial => 'shared/dialog_error_messages', :locals => { :object_name => 'product' } %>
  2 + <%= render_dialog_error_messages 'product' %>
3 3 <% end %>
4 4  
5 5 <% remote_form_for(@product,
... ...
app/views/manage_products/_edit_name.rhtml
... ... @@ -17,5 +17,5 @@
17 17 </script>
18 18  
19 19 <% if errors %>
20   - <%= render :partial => 'shared/dialog_error_messages', :locals => { :object_name => 'product' } %>
  20 + <%= render_dialog_error_messages 'product' %>
21 21 <% end %>
... ...
app/views/plugins/index.rhtml
... ... @@ -12,7 +12,7 @@
12 12 <%= hidden_field_tag('environment[enabled_plugins][]', '') %>
13 13 <% @active_plugins.each do |plugin| %>
14 14 <tr>
15   - <td><%= plugin.plugin_name %></td>
  15 + <td><%= plugin.has_admin_url? ? link_to(plugin.plugin_name, plugin.admin_url) : plugin.plugin_name %></td>
16 16 <td><%= plugin.plugin_description %></td>
17 17 <td><%= check_box_tag "environment[enabled_plugins][]", plugin, @environment.enabled_plugins.include?(plugin.to_s), :id => plugin.plugin_name %></td>
18 18 </tr>
... ...
config/cucumber.yml
1   -default: --tags ~@selenium,~@wip --exclude features/support/selenium.rb --exclude features/step_definitions/selenium_steps.rb
2   -selenium: --tags @selenium,~@wip
  1 +default: --tags ~@selenium,~@wip --exclude features/support/selenium.rb --exclude features/step_definitions/selenium_steps.rb -r features/support -r features/step_definitions
  2 +selenium: --tags @selenium,~@wip -r features/support -r features/step_definitions
... ...
doc/noosfero/plugins/index.textile 0 → 100644
... ... @@ -0,0 +1,2 @@
  1 +h1. Plugins
  2 +
... ...
features/plugins.feature
... ... @@ -56,4 +56,3 @@ Feature: plugins
56 56 Then I should not see "Test plugin button"
57 57 When I go to the profile
58 58 Then I should not see "Test plugin tab"
59   -
... ...
lib/noosfero/i18n.rb
... ... @@ -71,7 +71,9 @@ module ActionView::Helpers::ActiveRecordHelper
71 71 end
72 72 end
73 73  
74   - if options[:message_title]
  74 + if options[:header_message]
  75 + header_message = options[:header_message]
  76 + elsif options[:message_title]
75 77 header_message = instance.error_message(options[:message_title], count) % {:num => count, :record => record}
76 78 else
77 79 header_message = ((count == 1) ? _(@error_message_title[0]) : _(@error_message_title[1])) % {:num => count, :record => record}
... ...
lib/noosfero/plugin.rb
... ... @@ -52,6 +52,13 @@ class Noosfero::Plugin
52 52 _("No description informed.")
53 53 end
54 54  
  55 + def admin_url
  56 + {:controller => "#{name.underscore}_admin", :action => 'index'}
  57 + end
  58 +
  59 + def has_admin_url?
  60 + File.exists?(File.join(root_path, 'controllers', "#{name.underscore}_admin_controller.rb"))
  61 + end
55 62 end
56 63  
57 64 def expanded_template(file_path, locals = {})
... ... @@ -121,4 +128,10 @@ class Noosfero::Plugin
121 128 []
122 129 end
123 130  
  131 + # -> Parse and possibly make changes of content (article, block, etc) during HTML rendering
  132 + # returns = content as string after parser and changes
  133 + def parse_content(raw_content)
  134 + raw_content
  135 + end
  136 +
124 137 end
... ...
lib/tasks/doc.rake
1 1 namespace :noosfero do
2 2 namespace :doc do
  3 + Dir.glob('plugins/**/doc/*.textile').each do |file|
  4 + ln_sf File.join(RAILS_ROOT, file), 'doc/noosfero/plugins/'
  5 + end
3 6 input = Dir.glob('doc/noosfero/**/*.textile')
4 7 topics_xhtml = input.map { |item| item.sub('.textile', '.en.xhtml') }
5 8 sections = Dir.glob('doc/noosfero/*').select {|item| File.directory?(item) }
... ...
test/unit/plugin_test.rb
... ... @@ -18,6 +18,12 @@ class PluginTest &lt; Test::Unit::TestCase
18 18 assert_includes Noosfero::Plugin.all, Plugin1.to_s
19 19 end
20 20  
21   -end
  21 + should 'returns url to plugin management if plugin has admin_controller' do
  22 + class Plugin1 < Noosfero::Plugin
  23 + end
  24 + File.stubs(:exists?).with(anything).returns(true)
22 25  
  26 + assert_equal({:controller => 'plugin_test/plugin1_admin', :action => 'index'}, Plugin1.admin_url)
  27 + end
23 28  
  29 +end
... ...