Commit c4e8c606ffc0d984279c8160cf0d49c5c3afc808
1 parent
3f754a9b
Exists in
master
and in
27 other branches
Fix the merge of Noosfero::Plugin code
Showing
1 changed file
with
35 additions
and
26 deletions
Show diff stats
lib/noosfero/plugin.rb
| ... | ... | @@ -18,15 +18,16 @@ class Noosfero::Plugin |
| 18 | 18 | plugin_name = File.basename(plugin_dir) |
| 19 | 19 | load_plugin(plugin_name) |
| 20 | 20 | end |
| 21 | + end | |
| 21 | 22 | |
| 22 | - enabled_plugins.select do |entry| | |
| 23 | - File.directory?(entry) | |
| 24 | - end.each do |dir| | |
| 25 | - load_plugin dir | |
| 23 | + def setup(config) | |
| 24 | + return if !should_load | |
| 25 | + enabled.each do |dir| | |
| 26 | + setup_plugin(dir, config) | |
| 26 | 27 | end |
| 27 | 28 | end |
| 28 | 29 | |
| 29 | - def load_plugin dir | |
| 30 | + def setup_plugin(dir, config) | |
| 30 | 31 | plugin_name = File.basename(dir) |
| 31 | 32 | |
| 32 | 33 | plugin_dependencies_ok = true |
| ... | ... | @@ -40,30 +41,38 @@ class Noosfero::Plugin |
| 40 | 41 | end |
| 41 | 42 | end |
| 42 | 43 | |
| 43 | - return unless plugin_dependencies_ok | |
| 44 | - | |
| 45 | - # add load paths | |
| 46 | - Rails.configuration.controller_paths << File.join(dir, 'controllers') | |
| 47 | - ActiveSupport::Dependencies.load_paths << File.join(dir, 'controllers') | |
| 48 | - controllers_folders = %w[public profile myprofile admin] | |
| 49 | - controllers_folders.each do |folder| | |
| 50 | - Rails.configuration.controller_paths << File.join(dir, 'controllers', folder) | |
| 51 | - ActiveSupport::Dependencies.load_paths << File.join(dir, 'controllers', folder) | |
| 52 | - end | |
| 53 | - [ ActiveSupport::Dependencies.load_paths, $:].each do |path| | |
| 54 | - path << File.join(dir, 'models') | |
| 55 | - path << File.join(dir, 'lib') | |
| 44 | + if plugin_dependencies_ok | |
| 45 | + %w[ | |
| 46 | + controllers | |
| 47 | + controllers/public | |
| 48 | + controllers/profile | |
| 49 | + controllers/myprofile | |
| 50 | + controllers/admin | |
| 51 | + ].each do |folder| | |
| 52 | + config.autoload_paths << File.join(dir, folder) | |
| 53 | + end | |
| 54 | + [ config.autoload_paths, $:].each do |path| | |
| 55 | + path << File.join(dir, 'models') | |
| 56 | + path << File.join(dir, 'lib') | |
| 57 | + end | |
| 56 | 58 | end |
| 59 | + end | |
| 57 | 60 | |
| 58 | - # load vendor/plugins | |
| 59 | - Dir.glob(File.join(dir, '/vendor/plugins/*')).each do |vendor_plugin| | |
| 60 | - [ ActiveSupport::Dependencies.load_paths, $:].each{ |path| path << "#{vendor_plugin}/lib" } | |
| 61 | - init = "#{vendor_plugin}/init.rb" | |
| 62 | - require init.gsub(/.rb$/, '') if File.file? init | |
| 63 | - end | |
| 61 | + def load_plugin(dir) | |
| 62 | + (dir.to_s.camelize + 'Plugin').constantize | |
| 63 | + end | |
| 64 | 64 | |
| 65 | - # load class | |
| 66 | - klass(plugin_name) | |
| 65 | + def enabled | |
| 66 | + @enabled ||= | |
| 67 | + begin | |
| 68 | + plugins = Dir.glob(File.join(Rails.root, 'config', 'plugins', '*')) | |
| 69 | + if Rails.env.test? && !plugins.include?(File.join(Rails.root, 'config', 'plugins', 'foo')) | |
| 70 | + plugins << File.join(Rails.root, 'plugins', 'foo') | |
| 71 | + end | |
| 72 | + plugins.select do |entry| | |
| 73 | + File.directory?(entry) | |
| 74 | + end | |
| 75 | + end | |
| 67 | 76 | end |
| 68 | 77 | |
| 69 | 78 | def all | ... | ... |