cirandas.net

commit 0fe22bfef8d7bf03e9e4f7b2e3ed99eb5babd017

Author: Braulio Bhavamitra <braulio@prout.io>

Organize routes with configured paths

%!v(PANIC=String method: strings: negative Repeat count)


diff --git a/config/application.rb b/config/application.rb
index dff688a928cde52708a198ab1b24808c625479e3..f24762408dd9af200a3332dcd3f9647653d4b249 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -121,8 +121,16 @@       :key    => '_noosfero_session',
     }
     config.session_store :active_record_store, key: '_noosfero_session'
 
-    config.paths['db/migrate'].concat Dir.glob("#{Rails.root}/{baseplugins,config/plugins}/*/db/migrate")
-    config.i18n.load_path.concat Dir.glob("#{Rails.root}/{baseplugins,config/plugins}/*/locales/*.{rb,yml}")
+    config.paths['config/routes.rb'] =
+      Dir['config/routes/*.rb'] +
+      Dir['config/routes/profile/*.rb'] +
+      Dir['config/routes/myprofile/*.rb'] +
+      Dir['config/routes/admin/*.rb'] +
+      Dir['{baseplugins,config/plugins}/*/config/routes**.rb'] +
+      Dir['config/routes/cms/*.rb']
+
+    config.paths['db/migrate'].concat Dir.glob("{baseplugins,config/plugins}/*/db/migrate")
+    config.i18n.load_path.concat Dir.glob("{baseplugins,config/plugins}/*/locales/*.{rb,yml}")
 
     config.middleware.use Noosfero::MultiTenancy::Middleware
 




diff --git a/config/routes/02_test.rb b/config/routes/02_test.rb
new file mode 100644
index 0000000000000000000000000000000000000000..3917d6355cb588299b5eb2e3da453acf4fff9e39
--- /dev/null
+++ b/config/routes/02_test.rb
@@ -0,0 +1,5 @@
+Noosfero::Application.routes.draw do
+
+  match 'test/:controller(/:action(/:id))', controller: /.*test.*/, via: :all
+
+end




diff --git a/config/routes/03_assets.rb b/config/routes/03_assets.rb
new file mode 100644
index 0000000000000000000000000000000000000000..8709250b4b8d0fe240d834f291bddafc1dde2b89
--- /dev/null
+++ b/config/routes/03_assets.rb
@@ -0,0 +1,11 @@
+Noosfero::Application.routes.draw do
+
+  match 'images(/*stuff)', to: 'not_found#nothing', via: :all
+  match 'stylesheets(/*stuff)', to: 'not_found#nothing', via: :all
+  match 'designs(/*stuff)', to: 'not_found#nothing', via: :all
+  match 'articles(/*stuff)', to: 'not_found#nothing', via: :all
+  match 'javascripts(/*stuff)', to: 'not_found#nothing', via: :all
+  match 'thumbnails(/*stuff)', to: 'not_found#nothing', via: :all
+  match 'user_themes(/*stuff)', to: 'not_found#nothing', via: :all
+
+end




diff --git a/config/routes/03_home.rb b/config/routes/03_home.rb
new file mode 100644
index 0000000000000000000000000000000000000000..a7fbf8324f09ff48ea2d699731765f8a2eb693d5
--- /dev/null
+++ b/config/routes/03_home.rb
@@ -0,0 +1,14 @@
+Noosfero::Application.routes.draw do
+
+  environment_domain_constraint = -> request { !Domain.hosting_profile_at(request.host) }
+
+  # -- just remember to delete public/index.html.
+  # You can have the root of your site routed by hooking up ''
+  root to: 'home#index', constraints: environment_domain_constraint, via: :all
+
+  match 'site(/:action)', controller: :home, via: :all
+  match 'api(/:action)', controller: :api, via: :all
+
+  match 'embed/:action/:id', controller: :embed, id: /\d+/, via: :all
+
+end




diff --git a/config/routes/04_doc.rb b/config/routes/04_doc.rb
new file mode 100644
index 0000000000000000000000000000000000000000..54119dcd10485371688609482af24ac6ed14daae
--- /dev/null
+++ b/config/routes/04_doc.rb
@@ -0,0 +1,8 @@
+Noosfero::Application.routes.draw do
+
+  # online documentation
+  match 'doc', to: 'doc#index', as: :doc, via: :all
+  match 'doc/:section', to: 'doc#section', as: :doc_section, via: :all
+  match 'doc/:section/:topic', to: 'doc#topic', as: :doc_topic, via: :all
+
+end




diff --git a/config/routes/05_account.rb b/config/routes/05_account.rb
new file mode 100644
index 0000000000000000000000000000000000000000..2ac2d408a86e64260504355b0a3935a8a653af2c
--- /dev/null
+++ b/config/routes/05_account.rb
@@ -0,0 +1,7 @@
+Noosfero::Application.routes.draw do
+
+  # user account controller
+  match 'account/new_password/:code', controller: :account, action: :new_password, via: :all
+  match 'account(/:action)', controller: :account, via: :all
+
+end




diff --git a/config/routes/06_search.rb b/config/routes/06_search.rb
new file mode 100644
index 0000000000000000000000000000000000000000..e962a4bda10e093041efef425a2a99f061ce498f
--- /dev/null
+++ b/config/routes/06_search.rb
@@ -0,0 +1,12 @@
+Noosfero::Application.routes.draw do
+
+  # tags
+  match 'tag', controller: :search, action: :tags, via: :all
+  match 'tag(/:tag)', controller: :search, action: :tag, tag: /.*/, via: :all
+
+  # categories index
+  match 'cat/*category_path', to: 'search#category_index', as: :category, via: :all
+  # search
+  match 'search(/:action(/*category_path))', controller: :search, via: :all, as: :search
+
+end




diff --git a/config/routes/07_map_balloon.rb b/config/routes/07_map_balloon.rb
new file mode 100644
index 0000000000000000000000000000000000000000..f1b875c24c0530a0986822a4c2179fb73175a2ff
--- /dev/null
+++ b/config/routes/07_map_balloon.rb
@@ -0,0 +1,5 @@
+Noosfero::Application.routes.draw do
+
+  match 'map_balloon/:action/:id', controller: :map_balloon, id: /.*/, via: :all
+
+end




diff --git a/config/routes/08_chat.rb b/config/routes/08_chat.rb
new file mode 100644
index 0000000000000000000000000000000000000000..cdb6f420778d7549de146fd3318b235038699fd8
--- /dev/null
+++ b/config/routes/08_chat.rb
@@ -0,0 +1,5 @@
+Noosfero::Application.routes.draw do
+
+  match 'chat(/:action(/:id))', controller: :chat, via: :all
+
+end




diff --git a/config/routes/09_enterprise.rb b/config/routes/09_enterprise.rb
new file mode 100644
index 0000000000000000000000000000000000000000..8ff8f3838f2877cf2061b84261e2e996d92031c7
--- /dev/null
+++ b/config/routes/09_enterprise.rb
@@ -0,0 +1,6 @@
+Noosfero::Application.routes.draw do
+
+  # enterprise registration
+  match 'enterprise_registration(/:action)', controller: :enterprise_registration, via: :all
+
+end




diff --git a/config/routes/50_plugins.rb b/config/routes/50_plugins.rb
new file mode 100644
index 0000000000000000000000000000000000000000..e9c94ff8035ef0564097f1c371e77b9d49fbb9d3
--- /dev/null
+++ b/config/routes/50_plugins.rb
@@ -0,0 +1,73 @@
+paths              = {}
+profile_format     = /#{Noosfero.identifier_format}/i
+plugins_root       = if Rails.env.test? then 'plugins' else '{baseplugins,config/plugins}' end
+prefixes_by_folder = {
+  public:    'plugin',
+  profile:   'profile/:profile/plugin',
+  myprofile: 'myprofile/:profile/plugin',
+  admin:     'admin/plugin',
+}
+
+Dir.glob Rails.root.join plugins_root, '*', 'controllers' do |controllers_dir|
+  plugin_name = File.basename File.dirname controllers_dir
+
+  controllers_by_folder = prefixes_by_folder.keys.inject({}) do |hash, folder|
+    path = "#{controllers_dir}/#{folder}/"
+    hash[folder] = Dir.glob("#{path}{*.rb,#{plugin_name}_plugin/*.rb}").map do |filename|
+      filename.gsub(path, '').gsub(/[_\/]controller.rb$/, '')
+    end
+    hash
+  end
+
+
+  controllers_by_folder.each do |folder, controllers|
+    controllers.each do |controller|
+      controller_name = controller.gsub(/#{plugin_name}_plugin[_\/]?/, '')
+      controller_path = if controller_name.present? then "/#{controller_name}" else '' end
+
+      as  = controller.tr '/','_'
+      url = "#{prefixes_by_folder[folder]}/#{plugin_name}#{controller_path}(/:action(/:id))"
+
+      paths[url] = {
+        controller: controller,
+        via:        :all,
+        as:         as,
+      }
+      paths[url][:profile] = profile_format if folder.to_s.in? %w[profile myprofile]
+    end
+  end
+
+  # DEPRECATED default controllers
+  paths.reverse_merge!(
+    "plugin/#{plugin_name}(/:action(/:id))" => {
+      controller: "#{plugin_name}_plugin",
+      via:        :all,
+    },
+    "admin/plugin/#{plugin_name}(/:action(/:id))" => {
+      controller: "#{plugin_name}_plugin_admin",
+      via:        :all,
+    },
+
+    "profile/:profile/plugin/#{plugin_name}(/:action(/:id))" => {
+      controller: "#{plugin_name}_plugin_profile",
+      via:        :all,
+      profile:    profile_format,
+    },
+    "myprofile/:profile/plugin/#{plugin_name}(/:action(/:id))" => {
+      controller: "#{plugin_name}_plugin_myprofile",
+      via:        :all,
+      profile:    profile_format,
+    },
+  )
+end
+
+Noosfero::Application.routes.draw do
+
+  paths.each do |url, opts|
+    controller_klass = "#{opts[:controller]}_controller".camelize.constantize rescue nil
+    next unless controller_klass
+
+    match url, opts
+  end
+
+end




diff --git a/config/routes/admin/40_admin.rb b/config/routes/admin/40_admin.rb
new file mode 100644
index 0000000000000000000000000000000000000000..eac5784d97c3a24e5b2ce6898c3d5ff5f9b31e78
--- /dev/null
+++ b/config/routes/admin/40_admin.rb
@@ -0,0 +1,7 @@
+Noosfero::Application.routes.draw do
+
+  match 'admin', controller: :admin_panel, action: :index, via: :all
+  match 'admin/:controller(/:action((.:format)/:id))', controller: Noosfero.pattern_for_controllers_in_directory('admin'), via: :all
+  match 'admin/:controller(/:action(/:id))', controller: Noosfero.pattern_for_controllers_in_directory('admin'), via: :all
+
+end




diff --git a/config/routes/cms/60_cms.rb b/config/routes/cms/60_cms.rb
new file mode 100644
index 0000000000000000000000000000000000000000..b6592a1586b8faba7a2058a6d55535551d1c7feb
--- /dev/null
+++ b/config/routes/cms/60_cms.rb
@@ -0,0 +1,18 @@
+Noosfero::Application.routes.draw do
+
+  environment_domain_constraint = -> request { !Domain.hosting_profile_at(request.host) }
+
+  match ':profile/*page/versions', controller: :content_viewer, action: :article_versions, profile: /#{Noosfero.identifier_format_in_url}/i, constraints: environment_domain_constraint, via: :all
+  match '*page/versions', controller: :content_viewer, action: :article_versions, via: :all
+
+  match ':profile/*page/versions_diff', controller: :content_viewer, action: :versions_diff, profile: /#{Noosfero.identifier_format_in_url}/i, constraints: environment_domain_constraint, via: :all
+  match '*page/versions_diff', controller: :content_viewer, action: :versions_diff, via: :all
+
+  # match requests for profiles that don't have a custom domain
+  match ':profile(/*page)', controller: :content_viewer, action: :view_page, profile: /#{Noosfero.identifier_format_in_url}/i,
+    constraints: environment_domain_constraint, via: :all, as: :page
+
+  # match requests for content in domains hosted for profiles
+  match '/(*page)', controller: :content_viewer, action: :view_page, via: :all
+
+end




diff --git a/config/routes/myprofile/30_myprofile.rb b/config/routes/myprofile/30_myprofile.rb
new file mode 100644
index 0000000000000000000000000000000000000000..a4d3a684c582bf612e26690cac9be41e6d3af42d
--- /dev/null
+++ b/config/routes/myprofile/30_myprofile.rb
@@ -0,0 +1,6 @@
+Noosfero::Application.routes.draw do
+
+  match 'myprofile/:profile', controller: :profile_editor, action: :index, profile: /#{Noosfero.identifier_format_in_url}/i, via: :all
+  match 'myprofile/:profile/:controller(/:action(/:id))', controller: Noosfero.pattern_for_controllers_in_directory('my_profile'), profile: /#{Noosfero.identifier_format_in_url}/i, as: :myprofile, via: :all
+
+end




diff --git a/config/routes/profile/21_profile.rb b/config/routes/profile/21_profile.rb
new file mode 100644
index 0000000000000000000000000000000000000000..4dc906ededd44697b7bde9d0a62fd75b7ca66041
--- /dev/null
+++ b/config/routes/profile/21_profile.rb
@@ -0,0 +1,34 @@
+Noosfero::Application.routes.draw do
+
+  match ':profile/about', controller: :profile, action: :about, profile: /#{Noosfero.identifier_format_in_url}/i, via: :all
+  match ':profile/activities', controller: :profile, action: :activities, profile: /#{Noosfero.identifier_format_in_url}/i, via: :all
+
+  # events
+  match 'profile/:profile/events_by_day', controller: :events, action: :events_by_day, profile: /#{Noosfero.identifier_format_in_url}/i, via: :all
+  match 'profile/:profile/events_by_month', controller: :events, action: :events_by_month, profile: /#{Noosfero.identifier_format_in_url}/i, via: :all
+  match 'profile/:profile/events/:year/:month/:day', controller: :events, action: :events, year: /\d*/, month: /\d*/, day: /\d*/, profile: /#{Noosfero.identifier_format_in_url}/i, via: :all
+  match 'profile/:profile/events/:year/:month', controller: :events, action: :events, year: /\d*/, month: /\d*/, profile: /#{Noosfero.identifier_format_in_url}/i, via: :all
+  match 'profile/:profile/events', controller: :events, action: :events, profile: /#{Noosfero.identifier_format_in_url}/i, via: :all
+
+  # invite
+  match 'profile/:profile/invite/friends', controller: :invite, action: :invite_friends, profile: /#{Noosfero.identifier_format_in_url}/i, via: :all
+  match 'profile/:profile/invite/:action', controller: :invite, profile: /#{Noosfero.identifier_format_in_url}/i, via: :all
+
+  # feeds per tag
+  match 'profile/:profile/tags/:id/feed', controller: :profile, action: :tag_feed, id: /.+/, profile: /#{Noosfero.identifier_format_in_url}/i, as: :tag_feed, via: :all
+
+  # profile tags
+  match 'profile/:profile/tags/:id', controller: :profile, action: :content_tagged, id: /.+/, profile: /#{Noosfero.identifier_format_in_url}/i, via: :all
+  match 'profile/:profile/tags(/:id)', controller: :profile, action: :tags, profile: /#{Noosfero.identifier_format_in_url}/i, via: :all
+
+  # profile search
+  match 'profile/:profile/search', controller: :profile_search, action: :index, profile: /#{Noosfero.identifier_format_in_url}/i,
+    via: :all, as: :profile_search
+
+  # comments
+  match 'profile/:profile/comment/:action/:id', controller: :comment, profile: /#{Noosfero.identifier_format_in_url}/i, via: :all
+
+  # public profile information
+  match 'profile/:profile(/:action(/:id))', controller: :profile, action: :index, id: /[^\/]*/, profile: /#{Noosfero.identifier_format_in_url}/i, as: :profile, via: :all
+
+end




diff --git a/config/routes/profile/22_profile.rb b/config/routes/profile/22_profile.rb
new file mode 100644
index 0000000000000000000000000000000000000000..fc8639c66a332e6ad1990323c77d3b7543735c38
--- /dev/null
+++ b/config/routes/profile/22_profile.rb
@@ -0,0 +1,6 @@
+Noosfero::Application.routes.draw do
+
+  # contact
+  match 'contact(/:profile)/:action(/:id)', controller: :contact, action: :index, id: /.*/, profile: /#{Noosfero.identifier_format_in_url}/i, via: :all
+
+end




diff --git a/config/routes/profile/23_profile.rb b/config/routes/profile/23_profile.rb
new file mode 100644
index 0000000000000000000000000000000000000000..4e3456e7ee0e658fea87eb199df4afa2177be057
--- /dev/null
+++ b/config/routes/profile/23_profile.rb
@@ -0,0 +1,11 @@
+Noosfero::Application.routes.draw do
+
+  ##
+  # Keep products URL compatibility
+  get 'catalog/:profile', to: redirect{ |params, request| "/profile/#{request.params[:profile]}/plugin/products/catalog" }
+  get 'profile/:profile/catalog', to: redirect{ |params, request| "/profile/#{request.params[:profile]}/plugin/products/catalog" }
+  get 'myprofile/:profile/manage_products(/:action(/:id))', to: (redirect do |params, request|
+    "/profile/#{request.params[:profile]}/plugin/products/page/#{request.params[:action]}/#{request.params[:id]}"
+  end)
+
+end




diff --git a/config/routes.rb b/config/routes.rb
index 9287b86f56c06c917b760e7d92360e0b4bddd298..9260f0ed4f437ab6b393233db0df2a3fb436c576 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,154 +1,6 @@
-require_dependency 'noosfero'
-
 Noosfero::Application.routes.draw do
-  # The priority is based upon order of creation: first created -> highest priority.
-  # Sample of regular route:
-  # map.connect 'products/:id', controller: 'catalog', action: 'view'
-  # Keep in mind you can assign values other than :controller and :action
-
-  # Sample of named route:
-  # map.purchase 'products/:id/purchase', controller: 'catalog', action: 'purchase'
-  # This route can be invoked with purchase_url(id: product.id)
-
-  environment_domain_constraint = -> request { !Domain.hosting_profile_at(request.host) }
-
-  ######################################################
-  ## Public controllers
-  ######################################################
-
-
-  match 'test/:controller(/:action(/:id))', controller: /.*test.*/, via: :all
 
-  # -- just remember to delete public/index.html.
-  # You can have the root of your site routed by hooking up ''
-  root to: 'home#index', constraints: environment_domain_constraint, via: :all
-
-  match 'site(/:action)', controller: 'home', via: :all
-  match 'api(/:action)', controller: 'api', via: :all
-
-  match 'images(/*stuff)', to: 'not_found#nothing', via: :all
-  match 'stylesheets(/*stuff)', to: 'not_found#nothing', via: :all
-  match 'designs(/*stuff)', to: 'not_found#nothing', via: :all
-  match 'articles(/*stuff)', to: 'not_found#nothing', via: :all
-  match 'javascripts(/*stuff)', to: 'not_found#nothing', via: :all
-  match 'thumbnails(/*stuff)', to: 'not_found#nothing', via: :all
-  match 'user_themes(/*stuff)', to: 'not_found#nothing', via: :all
-
-  # embed controller
-  match 'embed/:action/:id', controller: 'embed', id: /\d+/, via: :all
-
-  # online documentation
-  match 'doc', to: 'doc#index', as: :doc, via: :all
-  match 'doc/:section', to: 'doc#section', as: :doc_section, via: :all
-  match 'doc/:section/:topic', to: 'doc#topic', as: :doc_topic, via: :all
-
-  # user account controller
-  match 'account/new_password/:code', controller: 'account', action: 'new_password', via: :all
-  match 'account(/:action)', controller: 'account', via: :all
-
-  # enterprise registration
-  match 'enterprise_registration(/:action)', controller: 'enterprise_registration', via: :all
-
-  # tags
-  match 'tag', controller: 'search', action: 'tags', via: :all
-  match 'tag/:tag', controller: 'search', action: 'tag', tag: /.*/, via: :all
-
-  # categories index
-  match 'cat/*category_path', to: 'search#category_index', as: :category, via: :all
-  # search
-  match 'search(/:action(/*category_path))', controller: 'search', via: :all
-
-  ##
-  # Keep products URL compatibility
-  get 'catalog/:profile', to: redirect{ |params, request| "/profile/#{request.params[:profile]}/plugin/products/catalog" }
-  get 'myprofile/:profile/manage_products(/:action(/:id))', to: (redirect do |params, request|
-    "/profile/#{request.params[:profile]}/plugin/products/page/#{request.params[:action]}/#{request.params[:id]}"
-  end)
-
-  match ':profile/about', controller: 'profile', action: 'about', profile: /#{Noosfero.identifier_format_in_url}/i, via: :all
-  match ':profile/activities', controller: 'profile', action: 'activities', profile: /#{Noosfero.identifier_format_in_url}/i, via: :all
-
-  # events
-  match 'profile/:profile/events_by_day', controller: 'events', action: 'events_by_day', profile: /#{Noosfero.identifier_format_in_url}/i, via: :all
-  match 'profile/:profile/events_by_month', controller: 'events', action: 'events_by_month', profile: /#{Noosfero.identifier_format_in_url}/i, via: :all
-  match 'profile/:profile/events/:year/:month/:day', controller: 'events', action: 'events', year: /\d*/, month: /\d*/, day: /\d*/, profile: /#{Noosfero.identifier_format_in_url}/i, via: :all
-  match 'profile/:profile/events/:year/:month', controller: 'events', action: 'events', year: /\d*/, month: /\d*/, profile: /#{Noosfero.identifier_format_in_url}/i, via: :all
-  match 'profile/:profile/events', controller: 'events', action: 'events', profile: /#{Noosfero.identifier_format_in_url}/i, via: :all
-
-  # invite
-  match 'profile/:profile/invite/friends', controller: 'invite', action: 'invite_friends', profile: /#{Noosfero.identifier_format_in_url}/i, via: :all
-  match 'profile/:profile/invite/:action', controller: 'invite', profile: /#{Noosfero.identifier_format_in_url}/i, via: :all
-
-  # feeds per tag
-  match 'profile/:profile/tags/:id/feed', controller: 'profile', action:'tag_feed', id: /.+/, profile: /#{Noosfero.identifier_format_in_url}/i, as: :tag_feed, via: :all
-
-  # profile tags
-  match 'profile/:profile/tags/:id', controller: 'profile', action: 'content_tagged', id: /.+/, profile: /#{Noosfero.identifier_format_in_url}/i, via: :all
-  match 'profile/:profile/tags(/:id)', controller: 'profile', action: 'tags', profile: /#{Noosfero.identifier_format_in_url}/i, via: :all
-
-  # profile search
-  match 'profile/:profile/search', controller: 'profile_search', action: 'index', profile: /#{Noosfero.identifier_format_in_url}/i, via: :all
-
-  # comments
-  match 'profile/:profile/comment/:action/:id', controller: 'comment', profile: /#{Noosfero.identifier_format_in_url}/i, via: :all
-
-  # public profile information
-  match 'profile/:profile(/:action(/:id))', controller: 'profile', action: 'index', id: /[^\/]*/, profile: /#{Noosfero.identifier_format_in_url}/i, as: :profile, via: :all
-
-  # contact
-  match 'contact/:profile/:action(/:id)', controller: 'contact', action: 'index', id: /.*/, profile: /#{Noosfero.identifier_format_in_url}/i, via: :all
-
-  # map balloon
-  match 'map_balloon/:action/:id', controller: 'map_balloon', id: /.*/, via: :all
-
-  # chat
-  match 'chat(/:action(/:id))', controller: 'chat', via: :all
-
-
-  ######################################################
-  ## Controllers that are profile-specific (for profile admins )
-  ######################################################
-  # profile customization - "My profile"
-  match 'myprofile/:profile', controller: 'profile_editor', action: 'index', profile: /#{Noosfero.identifier_format_in_url}/i, via: :all
-  match 'myprofile/:profile/:controller(/:action(/:id))', controller: Noosfero.pattern_for_controllers_in_directory('my_profile'), profile: /#{Noosfero.identifier_format_in_url}/i, as: :myprofile, via: :all
-
-
-  ######################################################
-  ## Controllers that are used by environment admin
-  ######################################################
-  # administrative tasks for a environment
-  match 'admin', controller: 'admin_panel', action: :index, via: :all
-  match 'admin/:controller(/:action((.:format)/:id))', controller: Noosfero.pattern_for_controllers_in_directory('admin'), via: :all
-  match 'admin/:controller(/:action(/:id))', controller: Noosfero.pattern_for_controllers_in_directory('admin'), via: :all
-
-
-  ######################################################
-  ## Controllers that are used by system admin
-  ######################################################
-  # administrative tasks for a environment
-  match 'system', controller: 'system', via: :all
-  match 'system/:controller(/:action(/:id))', controller: Noosfero.pattern_for_controllers_in_directory('system'), via: :all
-
-  ######################################################
-  # plugin routes
-  ######################################################
-  plugins_routes = File.join(File.dirname(__FILE__) + '/../lib/noosfero/plugin/routes.rb')
-  eval(IO.read(plugins_routes), binding, plugins_routes)
-
-  # cache stuff - hack
-  match 'public/:action/:id', controller: 'public', via: :all
+  # everything inside `config/routes` directory
 
-  match ':profile/*page/versions', controller: 'content_viewer', action: 'article_versions', profile: /#{Noosfero.identifier_format_in_url}/i, constraints: environment_domain_constraint, via: :all
-  match '*page/versions', controller: 'content_viewer', action: 'article_versions', via: :all
+end
 
-  match ':profile/*page/versions_diff', controller: 'content_viewer', action: 'versions_diff', profile: /#{Noosfero.identifier_format_in_url}/i, constraints: environment_domain_constraint, via: :all
-  match '*page/versions_diff', controller: 'content_viewer', action: 'versions_diff', via: :all
-
-  # match requests for profiles that don't have a custom domain
-  match ':profile(/*page)', controller: 'content_viewer', action: 'view_page', profile: /#{Noosfero.identifier_format_in_url}/i,
-    constraints: environment_domain_constraint, via: :all, as: :page
-
-  # match requests for content in domains hosted for profiles
-  match '/(*page)', controller: 'content_viewer', action: 'view_page', via: :all
-
-end




diff --git a/config/spring.rb b/config/spring.rb
index f0bcfd0a8968314f9de328d558422683560dd84a..16eb8bfcefdba03fcbfb47a648bd8e70ca2b4d5d 100644
--- a/config/spring.rb
+++ b/config/spring.rb
@@ -3,6 +3,7 @@   .env
   .env.local
   .ruby-version
   .rbenv-vars
+  config/**
   lib/**
   tmp/restart.txt
   tmp/caching-dev.txt




diff --git a/lib/noosfero/plugin/routes.rb b/lib/noosfero/plugin/routes.rb
deleted file mode 100644
index 8635957706ab745067116f64aabf0f42af2cf4ab..0000000000000000000000000000000000000000
--- a/lib/noosfero/plugin/routes.rb
+++ /dev/null
@@ -1,73 +0,0 @@
-plugins_root       = if Rails.env.test? then 'plugins' else '{baseplugins,config/plugins}' end
-prefixes_by_folder = {
-  public:    'plugin',
-  profile:   'profile/:profile/plugin',
-  myprofile: 'myprofile/:profile/plugin',
-  admin:     'admin/plugin',
-}
-
-Dir.glob Rails.root.join plugins_root, '*', 'controllers' do |controllers_dir|
-  plugin_name = File.basename File.dirname controllers_dir
-
-  controllers_by_folder = prefixes_by_folder.keys.inject({}) do |hash, folder|
-    path = "#{controllers_dir}/#{folder}/"
-    hash[folder] = Dir.glob("#{path}{*.rb,#{plugin_name}_plugin/*.rb}").map do |filename|
-      filename.gsub(path, '').gsub(/[_\/]controller.rb$/, '')
-    end
-    hash
-  end
-
-  paths          = {}
-  profile_format = /#{Noosfero.identifier_format}/i
-
-  controllers_by_folder.each do |folder, controllers|
-    controllers.each do |controller|
-      controller_name = controller.gsub(/#{plugin_name}_plugin[_\/]?/, '')
-      controller_path = if controller_name.present? then "/#{controller_name}" else '' end
-
-      as  = controller.tr '/','_'
-      url = "#{prefixes_by_folder[folder]}/#{plugin_name}#{controller_path}(/:action(/:id))"
-
-      paths[url] = {
-        controller: controller,
-        via:        :all,
-        as:         as,
-      }
-      paths[url][:profile] = profile_format if folder.to_s.in? %w[profile myprofile]
-    end
-  end
-
-  # DEPRECATED default controllers
-  paths.reverse_merge!(
-    "plugin/#{plugin_name}(/:action(/:id))" => {
-      controller: "#{plugin_name}_plugin",
-      via:        :all,
-    },
-    "admin/plugin/#{plugin_name}(/:action(/:id))" => {
-      controller: "#{plugin_name}_plugin_admin",
-      via:        :all,
-    },
-
-    "profile/:profile/plugin/#{plugin_name}(/:action(/:id))" => {
-      controller: "#{plugin_name}_plugin_profile",
-      via:        :all,
-      profile:    profile_format,
-    },
-    "myprofile/:profile/plugin/#{plugin_name}(/:action(/:id))" => {
-      controller: "#{plugin_name}_plugin_myprofile",
-      via:        :all,
-      profile:    profile_format,
-    },
-  )
-
-  paths.each do |url, opts|
-    controller_klass = "#{opts[:controller]}_controller".camelize.constantize rescue nil
-    next unless controller_klass
-
-    match url, opts
-  end
-end
-
-Dir.glob Rails.root.join plugins_root, '*', 'config', 'routes.rb' do |route|
-  eval IO.read(route), binding, route
-end




diff --git a/lib/noosfero/plugin.rb b/lib/noosfero/plugin.rb
index 61a2715559db51735289ee86636c65392a119067..1d1c851782d186ce17fc8afdd137d5b1a5a4100a 100644
--- a/lib/noosfero/plugin.rb
+++ b/lib/noosfero/plugin.rb
@@ -70,6 +70,7 @@       end
 
       if plugin_dependencies_ok
         [config.autoload_paths, config.eager_load_paths].each do |path|
+          path.concat Dir["#{dir}/app/*/"]
           path.concat Dir["#{dir}/controllers/{,public,profile,myprofile,admin,concerns}"]
           path.concat Dir["#{dir}/models{,/concerns}"]
           path.concat Dir["#{dir}/lib"]




diff --git a/plugins/custom_routes/config/routes.rb b/plugins/custom_routes/config/routes.rb
index aca6d6c536cefdfd21da22d96bb720549efb073d..7cebfac1d2994ff22680ec81f7b58e374cd63c16 100644
--- a/plugins/custom_routes/config/routes.rb
+++ b/plugins/custom_routes/config/routes.rb
@@ -1 +1,2 @@
-CustomRoutesPlugin::CustomRoutes.load if defined?(CustomRoutesPlugin)
+CustomRoutesPlugin::CustomRoutes.load
+




diff --git a/plugins/open_graph/controllers/myprofile/open_graph_plugin/myprofile_controller.rb b/plugins/open_graph/controllers/myprofile/open_graph_plugin/myprofile_controller.rb
index 4aededb32214400f3f90035b49e8bd36f0c8deef..7497dd1d74b0848f19c6d93bf6cce8bd93d041d1 100644
--- a/plugins/open_graph/controllers/myprofile/open_graph_plugin/myprofile_controller.rb
+++ b/plugins/open_graph/controllers/myprofile/open_graph_plugin/myprofile_controller.rb
@@ -40,7 +40,7 @@   end
 
   # inherit routes from core skipping use_relative_controller!
   def url_for options
-    options[:controller] = "/#{options[:controller]}" if options.is_a? Hash
+    options[:controller] = "/#{options[:controller]}" if options.is_a? Hash and options[:controller]
     super options
   end
   helper_method :url_for




diff --git a/plugins/social_statistics/config/routes.rb b/plugins/social_statistics/config/routes.rb
index 54dcb70d558792c2409f0d8d515c92b01f00f0e9..2edb42e74029de6fafd706a93ee881a3bf7cd183 100644
--- a/plugins/social_statistics/config/routes.rb
+++ b/plugins/social_statistics/config/routes.rb
@@ -1,4 +1,8 @@
-begin
-  mount Blazer::Engine, at: "stats"
-rescue NameError
+Noosfero::Application.routes.draw do
+
+  begin
+    mount Blazer::Engine, at: "stats"
+  rescue NameError
+  end
+
 end