Commit b3f0b7f35e0d61eb9ab994a3f8d33f4bea8a5af5

Authored by Braulio Bhavamitra
2 parents ffae019b e7b77af4

Merge branch 'plugins-namespaced-controllers' into 'master'

Support plugins' namespaced controllers

See merge request !447
Showing 1 changed file with 10 additions and 7 deletions   Show diff stats
lib/noosfero/plugin/routes.rb
1 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 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 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_",'')
... ...