Commit 0d196bd9a9436cdafa57928c50b492ccd6a19889
1 parent
3bfc2f78
Exists in
master
and in
29 other branches
Load vendor/plugins inside noosfero plugins
Showing
1 changed file
with
40 additions
and
26 deletions
Show diff stats
lib/noosfero/plugin.rb
... | ... | @@ -16,38 +16,52 @@ class Noosfero::Plugin |
16 | 16 | if Rails.env.test? && !enabled_plugins.include?(File.join(Rails.root, 'config', 'plugins', 'foo')) |
17 | 17 | enabled_plugins << File.join(Rails.root, 'plugins', 'foo') |
18 | 18 | end |
19 | + | |
19 | 20 | enabled_plugins.select do |entry| |
20 | 21 | File.directory?(entry) |
21 | 22 | end.each do |dir| |
22 | - plugin_name = File.basename(dir) | |
23 | - | |
24 | - plugin_dependencies_ok = true | |
25 | - plugin_dependencies_file = File.join(dir, 'dependencies.rb') | |
26 | - if File.exists?(plugin_dependencies_file) | |
27 | - begin | |
28 | - require plugin_dependencies_file | |
29 | - rescue LoadError => ex | |
30 | - plugin_dependencies_ok = false | |
31 | - $stderr.puts "W: Noosfero plugin #{plugin_name} failed to load (#{ex})" | |
32 | - end | |
33 | - end | |
23 | + load_plugin dir | |
24 | + end | |
25 | + end | |
34 | 26 | |
35 | - if plugin_dependencies_ok | |
36 | - Rails.configuration.controller_paths << File.join(dir, 'controllers') | |
37 | - ActiveSupport::Dependencies.load_paths << File.join(dir, 'controllers') | |
38 | - controllers_folders = %w[public profile myprofile admin] | |
39 | - controllers_folders.each do |folder| | |
40 | - Rails.configuration.controller_paths << File.join(dir, 'controllers', folder) | |
41 | - ActiveSupport::Dependencies.load_paths << File.join(dir, 'controllers', folder) | |
42 | - end | |
43 | - [ ActiveSupport::Dependencies.load_paths, $:].each do |path| | |
44 | - path << File.join(dir, 'models') | |
45 | - path << File.join(dir, 'lib') | |
46 | - end | |
47 | - | |
48 | - klass(plugin_name) | |
27 | + def load_plugin dir | |
28 | + plugin_name = File.basename(dir) | |
29 | + | |
30 | + plugin_dependencies_ok = true | |
31 | + plugin_dependencies_file = File.join(dir, 'dependencies.rb') | |
32 | + if File.exists?(plugin_dependencies_file) | |
33 | + begin | |
34 | + require plugin_dependencies_file | |
35 | + rescue LoadError => ex | |
36 | + plugin_dependencies_ok = false | |
37 | + $stderr.puts "W: Noosfero plugin #{plugin_name} failed to load (#{ex})" | |
49 | 38 | end |
50 | 39 | end |
40 | + | |
41 | + return unless plugin_dependencies_ok | |
42 | + | |
43 | + # add load paths | |
44 | + Rails.configuration.controller_paths << File.join(dir, 'controllers') | |
45 | + ActiveSupport::Dependencies.load_paths << File.join(dir, 'controllers') | |
46 | + controllers_folders = %w[public profile myprofile admin] | |
47 | + controllers_folders.each do |folder| | |
48 | + Rails.configuration.controller_paths << File.join(dir, 'controllers', folder) | |
49 | + ActiveSupport::Dependencies.load_paths << File.join(dir, 'controllers', folder) | |
50 | + end | |
51 | + [ ActiveSupport::Dependencies.load_paths, $:].each do |path| | |
52 | + path << File.join(dir, 'models') | |
53 | + path << File.join(dir, 'lib') | |
54 | + end | |
55 | + | |
56 | + # load vendor/plugins | |
57 | + Dir.glob(File.join(dir, '/vendor/plugins/*')).each do |vendor_plugin| | |
58 | + [ ActiveSupport::Dependencies.load_paths, $:].each{ |path| path << "#{vendor_plugin}/lib" } | |
59 | + init = "#{vendor_plugin}/init.rb" | |
60 | + require init.gsub(/.rb$/, '') if File.file? init | |
61 | + end | |
62 | + | |
63 | + # load class | |
64 | + klass(plugin_name) | |
51 | 65 | end |
52 | 66 | |
53 | 67 | def all | ... | ... |