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,13 +5,16 @@ Dir.glob(Rails.root.join(plugins_root, '*', 'controllers')) do |controllers_dir|
5 'profile' => 'profile/:profile/plugin', 5 'profile' => 'profile/:profile/plugin',
6 'myprofile' => 'myprofile/:profile/plugin', 6 'myprofile' => 'myprofile/:profile/plugin',
7 'admin' => 'admin/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_",'')