Commit 77064dd35440b3a6e247b1a9227a37bac8eb0cf7

Authored by Braulio Bhavamitra
1 parent 77aa69cd

plugins: Support namespaced controllers' classes

Let us write FooPlugin::MyprofileController instead of
FooPluginMyprofileController
Showing 1 changed file with 6 additions and 3 deletions   Show diff stats
lib/noosfero/plugin/routes.rb
... ... @@ -5,13 +5,16 @@ Dir.glob(Rails.root.join(plugins_root, '*', 'controllers')) do |controllers_dir|
5 5 'profile' => 'profile/:profile/plugin',
6 6 'myprofile' => 'myprofile/:profile/plugin',
7 7 'admin' => 'admin/plugin'}
  8 + plugin_name = File.basename(File.dirname(controllers_dir))
8 9  
9 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 16 end
12 17  
13   - plugin_name = File.basename(File.dirname(controllers_dir))
14   -
15 18 controllers_by_folder.each do |folder, controllers|
16 19 controllers.each do |controller|
17 20 controller_name = controller.gsub("#{plugin_name}_plugin_",'')
... ...