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,11 +25,6 @@ class ApplicationController < ActionController::Base
25 helper :document 25 helper :document
26 helper :language 26 helper :language
27 27
28 - def boxes_editor?  
29 - false  
30 - end  
31 - protected :boxes_editor?  
32 -  
33 def self.no_design_blocks 28 def self.no_design_blocks
34 @no_design_blocks = true 29 @no_design_blocks = true
35 end 30 end
@@ -106,6 +101,14 @@ class ApplicationController < ActionController::Base @@ -106,6 +101,14 @@ class ApplicationController < ActionController::Base
106 101
107 protected 102 protected
108 103
  104 + def boxes_editor?
  105 + false
  106 + end
  107 +
  108 + def content_editor?
  109 + false
  110 + end
  111 +
109 def user 112 def user
110 current_user.person if logged_in? 113 current_user.person if logged_in?
111 end 114 end
app/controllers/my_profile/cms_controller.rb
@@ -383,5 +383,9 @@ class CmsController < MyProfileController @@ -383,5 +383,9 @@ class CmsController < MyProfileController
383 @selected_locale = @article.language || FastGettext.locale 383 @selected_locale = @article.language || FastGettext.locale
384 end 384 end
385 385
  386 + def content_editor?
  387 + true
  388 + end
  389 +
386 end 390 end
387 391
app/controllers/my_profile/manage_products_controller.rb
@@ -50,7 +50,7 @@ class ManageProductsController < ApplicationController @@ -50,7 +50,7 @@ class ManageProductsController < ApplicationController
50 render :partial => 'shared/redirect_via_javascript', 50 render :partial => 'shared/redirect_via_javascript',
51 :locals => { :url => url_for(:controller => 'manage_products', :action => 'show', :id => @product) } 51 :locals => { :url => url_for(:controller => 'manage_products', :action => 'show', :id => @product) }
52 else 52 else
53 - render :partial => 'shared/dialog_error_messages', :locals => { :object_name => 'product' } 53 + render_dialog_error_messages 'product'
54 end 54 end
55 end 55 end
56 end 56 end
@@ -81,7 +81,7 @@ class ManageProductsController < ApplicationController @@ -81,7 +81,7 @@ class ManageProductsController < ApplicationController
81 render :partial => 'shared/redirect_via_javascript', 81 render :partial => 'shared/redirect_via_javascript',
82 :locals => { :url => url_for(:controller => 'manage_products', :action => 'show', :id => @product) } 82 :locals => { :url => url_for(:controller => 'manage_products', :action => 'show', :id => @product) }
83 else 83 else
84 - render :partial => 'shared/dialog_error_messages', :locals => { :object_name => 'product' } 84 + render_dialog_error_messages 'product'
85 end 85 end
86 end 86 end
87 end 87 end
@@ -96,7 +96,7 @@ class ManageProductsController < ApplicationController @@ -96,7 +96,7 @@ class ManageProductsController < ApplicationController
96 @inputs = @product.inputs 96 @inputs = @product.inputs
97 render :partial => 'display_inputs' 97 render :partial => 'display_inputs'
98 else 98 else
99 - render :partial => 'shared/dialog_error_messages', :locals => { :object_name => 'product' } 99 + render_dialog_error_messages 'product'
100 end 100 end
101 else 101 else
102 render :partial => 'add_input' 102 render :partial => 'add_input'
@@ -147,7 +147,7 @@ class ManageProductsController < ApplicationController @@ -147,7 +147,7 @@ class ManageProductsController < ApplicationController
147 @inputs = @product.inputs 147 @inputs = @product.inputs
148 render :partial => 'display_inputs' 148 render :partial => 'display_inputs'
149 else 149 else
150 - render :partial => 'shared/dialog_error_messages', :locals => { :object_name => 'input' } 150 + render_dialog_error_messages 'input'
151 end 151 end
152 end 152 end
153 end 153 end
app/helpers/application_helper.rb
@@ -980,7 +980,10 @@ module ApplicationHelper @@ -980,7 +980,10 @@ module ApplicationHelper
980 def article_to_html(article, options = {}) 980 def article_to_html(article, options = {})
981 options.merge!(:page => params[:npage]) 981 options.merge!(:page => params[:npage])
982 content = article.to_html(options) 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 content 987 content
985 end 988 end
986 989
@@ -1221,4 +1224,8 @@ module ApplicationHelper @@ -1221,4 +1224,8 @@ module ApplicationHelper
1221 end 1224 end
1222 end 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 end 1231 end
app/helpers/boxes_helper.rb
@@ -99,7 +99,9 @@ module BoxesHelper @@ -99,7 +99,9 @@ module BoxesHelper
99 unless block.visible? 99 unless block.visible?
100 options[:title] = _("This block is invisible. Your visitors will not see it.") 100 options[:title] = _("This block is invisible. Your visitors will not see it.")
101 end 101 end
102 - 102 + @controller.send(:content_editor?) || @plugins.enabled_plugins.each do |plugin|
  103 + result = plugin.parse_content(result)
  104 + end
103 box_decorator.block_target(block.box, block) + 105 box_decorator.block_target(block.box, block) +
104 content_tag('div', 106 content_tag('div',
105 content_tag('div', 107 content_tag('div',
app/views/manage_products/_edit_image.rhtml
@@ -22,5 +22,5 @@ @@ -22,5 +22,5 @@
22 </script> 22 </script>
23 23
24 <% if errors %> 24 <% if errors %>
25 - <%= render :partial => 'shared/dialog_error_messages', :locals => { :object_name => 'product' } %> 25 + <%= render_dialog_error_messages 'product' %>
26 <% end %> 26 <% end %>
app/views/manage_products/_edit_info.rhtml
1 <% if errors %> 1 <% if errors %>
2 - <%= render :partial => 'shared/dialog_error_messages', :locals => { :object_name => 'product' } %> 2 + <%= render_dialog_error_messages 'product' %>
3 <% end %> 3 <% end %>
4 4
5 <% remote_form_for(@product, 5 <% remote_form_for(@product,
app/views/manage_products/_edit_name.rhtml
@@ -17,5 +17,5 @@ @@ -17,5 +17,5 @@
17 </script> 17 </script>
18 18
19 <% if errors %> 19 <% if errors %>
20 - <%= render :partial => 'shared/dialog_error_messages', :locals => { :object_name => 'product' } %> 20 + <%= render_dialog_error_messages 'product' %>
21 <% end %> 21 <% end %>
app/views/plugins/index.rhtml
@@ -12,7 +12,7 @@ @@ -12,7 +12,7 @@
12 <%= hidden_field_tag('environment[enabled_plugins][]', '') %> 12 <%= hidden_field_tag('environment[enabled_plugins][]', '') %>
13 <% @active_plugins.each do |plugin| %> 13 <% @active_plugins.each do |plugin| %>
14 <tr> 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 <td><%= plugin.plugin_description %></td> 16 <td><%= plugin.plugin_description %></td>
17 <td><%= check_box_tag "environment[enabled_plugins][]", plugin, @environment.enabled_plugins.include?(plugin.to_s), :id => plugin.plugin_name %></td> 17 <td><%= check_box_tag "environment[enabled_plugins][]", plugin, @environment.enabled_plugins.include?(plugin.to_s), :id => plugin.plugin_name %></td>
18 </tr> 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 @@ @@ -0,0 +1,2 @@
  1 +h1. Plugins
  2 +
features/plugins.feature
@@ -56,4 +56,3 @@ Feature: plugins @@ -56,4 +56,3 @@ Feature: plugins
56 Then I should not see "Test plugin button" 56 Then I should not see "Test plugin button"
57 When I go to the profile 57 When I go to the profile
58 Then I should not see "Test plugin tab" 58 Then I should not see "Test plugin tab"
59 -  
lib/noosfero/i18n.rb
@@ -71,7 +71,9 @@ module ActionView::Helpers::ActiveRecordHelper @@ -71,7 +71,9 @@ module ActionView::Helpers::ActiveRecordHelper
71 end 71 end
72 end 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 header_message = instance.error_message(options[:message_title], count) % {:num => count, :record => record} 77 header_message = instance.error_message(options[:message_title], count) % {:num => count, :record => record}
76 else 78 else
77 header_message = ((count == 1) ? _(@error_message_title[0]) : _(@error_message_title[1])) % {:num => count, :record => record} 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,6 +52,13 @@ class Noosfero::Plugin
52 _("No description informed.") 52 _("No description informed.")
53 end 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 end 62 end
56 63
57 def expanded_template(file_path, locals = {}) 64 def expanded_template(file_path, locals = {})
@@ -121,4 +128,10 @@ class Noosfero::Plugin @@ -121,4 +128,10 @@ class Noosfero::Plugin
121 [] 128 []
122 end 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 end 137 end
lib/tasks/doc.rake
1 namespace :noosfero do 1 namespace :noosfero do
2 namespace :doc do 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 input = Dir.glob('doc/noosfero/**/*.textile') 6 input = Dir.glob('doc/noosfero/**/*.textile')
4 topics_xhtml = input.map { |item| item.sub('.textile', '.en.xhtml') } 7 topics_xhtml = input.map { |item| item.sub('.textile', '.en.xhtml') }
5 sections = Dir.glob('doc/noosfero/*').select {|item| File.directory?(item) } 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,6 +18,12 @@ class PluginTest &lt; Test::Unit::TestCase
18 assert_includes Noosfero::Plugin.all, Plugin1.to_s 18 assert_includes Noosfero::Plugin.all, Plugin1.to_s
19 end 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