Commit 8a7b1048f2311471a63b086f44c76d2dc10e0319
Exists in
master
and in
27 other branches
Merge remote-tracking branch 'origin/master'
Showing
3 changed files
with
23 additions
and
14 deletions
Show diff stats
lib/noosfero/plugin.rb
@@ -24,11 +24,17 @@ class Noosfero::Plugin | @@ -24,11 +24,17 @@ class Noosfero::Plugin | ||
24 | 24 | ||
25 | def initialize! | 25 | def initialize! |
26 | return if !should_load | 26 | return if !should_load |
27 | - available_plugins.each do |plugin_dir| | 27 | + |
28 | + klasses = available_plugins.map do |plugin_dir| | ||
28 | plugin_name = File.basename(plugin_dir) | 29 | plugin_name = File.basename(plugin_dir) |
29 | - plugin = load_plugin(plugin_name) | ||
30 | - load_plugin_extensions(plugin_dir) | ||
31 | - load_plugin_filters(plugin) | 30 | + load_plugin plugin_name |
31 | + end | ||
32 | + available_plugins.each do |plugin_dir| | ||
33 | + load_plugin_extensions plugin_dir | ||
34 | + end | ||
35 | + # filters must be loaded after all extensions | ||
36 | + klasses.each do |plugin| | ||
37 | + load_plugin_filters plugin | ||
32 | end | 38 | end |
33 | end | 39 | end |
34 | 40 | ||
@@ -88,7 +94,7 @@ class Noosfero::Plugin | @@ -88,7 +94,7 @@ class Noosfero::Plugin | ||
88 | # This is a generic method that initialize any possible filter defined by a | 94 | # This is a generic method that initialize any possible filter defined by a |
89 | # plugin to a specific controller | 95 | # plugin to a specific controller |
90 | def load_plugin_filters(plugin) | 96 | def load_plugin_filters(plugin) |
91 | - Rails.configuration.to_prepare do | 97 | + ActionDispatch::Reloader.to_prepare do |
92 | filters = plugin.new.send 'application_controller_filters' rescue [] | 98 | filters = plugin.new.send 'application_controller_filters' rescue [] |
93 | Noosfero::Plugin.add_controller_filters ApplicationController, plugin, filters | 99 | Noosfero::Plugin.add_controller_filters ApplicationController, plugin, filters |
94 | 100 | ||
@@ -116,7 +122,7 @@ class Noosfero::Plugin | @@ -116,7 +122,7 @@ class Noosfero::Plugin | ||
116 | end | 122 | end |
117 | 123 | ||
118 | def load_plugin_extensions(dir) | 124 | def load_plugin_extensions(dir) |
119 | - Rails.configuration.to_prepare do | 125 | + ActionDispatch::Reloader.to_prepare do |
120 | Dir[File.join(dir, 'lib', 'ext', '*.rb')].each {|file| require_dependency file } | 126 | Dir[File.join(dir, 'lib', 'ext', '*.rb')].each {|file| require_dependency file } |
121 | end | 127 | end |
122 | end | 128 | end |
lib/noosfero/plugin/routes.rb
1 | plugins_root = Rails.env.test? ? 'plugins' : '{baseplugins,config/plugins}' | 1 | plugins_root = Rails.env.test? ? 'plugins' : '{baseplugins,config/plugins}' |
2 | +prefixes_by_folder = {public: 'plugin', | ||
3 | + profile: 'profile/:profile/plugin', | ||
4 | + myprofile: 'myprofile/:profile/plugin', | ||
5 | + admin: 'admin/plugin'} | ||
2 | 6 | ||
3 | Dir.glob(Rails.root.join(plugins_root, '*', 'controllers')) do |controllers_dir| | 7 | Dir.glob(Rails.root.join(plugins_root, '*', 'controllers')) do |controllers_dir| |
4 | - prefixes_by_folder = {'public' => 'plugin', | ||
5 | - 'profile' => 'profile/:profile/plugin', | ||
6 | - 'myprofile' => 'myprofile/:profile/plugin', | ||
7 | - 'admin' => 'admin/plugin'} | 8 | + plugin_name = File.basename(File.dirname(controllers_dir)) |
8 | 9 | ||
9 | controllers_by_folder = prefixes_by_folder.keys.inject({}) do |hash, folder| | 10 | controllers_by_folder = prefixes_by_folder.keys.inject({}) do |hash, folder| |
10 | - hash.merge!({folder => Dir.glob(File.join(controllers_dir, folder, '*')).map {|full_names| File.basename(full_names).gsub(/_controller.rb$/,'')}}) | 11 | + path = "#{controllers_dir}/#{folder}/" |
12 | + hash[folder] = Dir.glob("#{path}{*.rb,#{plugin_name}_plugin/*.rb}").map do |filename| | ||
13 | + filename.gsub(path, '').gsub(/_controller.rb$/, '') | ||
14 | + end | ||
15 | + hash | ||
11 | end | 16 | end |
12 | 17 | ||
13 | - plugin_name = File.basename(File.dirname(controllers_dir)) | ||
14 | - | ||
15 | controllers_by_folder.each do |folder, controllers| | 18 | controllers_by_folder.each do |folder, controllers| |
16 | controllers.each do |controller| | 19 | controllers.each do |controller| |
17 | controller_name = controller.gsub("#{plugin_name}_plugin_",'') | 20 | controller_name = controller.gsub("#{plugin_name}_plugin_",'') |
lib/noosfero/plugin/spammable.rb