From f2ee056873b84f8917e72d87181e1a9f5f653342 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 27 Nov 2008 18:59:24 +0100 Subject: Added view path support for engines [DHH] --- railties/lib/rails/plugin.rb | 11 ++++++----- railties/lib/rails/plugin/loader.rb | 34 ++++++++++++++++++++++++---------- 2 files changed, 30 insertions(+), 15 deletions(-) (limited to 'railties/lib/rails') diff --git a/railties/lib/rails/plugin.rb b/railties/lib/rails/plugin.rb index 2b1e877e2b..4901abe808 100644 --- a/railties/lib/rails/plugin.rb +++ b/railties/lib/rails/plugin.rb @@ -71,6 +71,11 @@ module Rails File.exist?(routing_file) end + + def view_path + File.join(directory, 'app', 'views') + end + def controller_path File.join(directory, 'app', 'controllers') end @@ -95,11 +100,7 @@ module Rails def app_paths - [ - File.join(directory, 'app', 'models'), - File.join(directory, 'app', 'controllers'), - File.join(directory, 'app', 'helpers') - ] + [ File.join(directory, 'app', 'models'), File.join(directory, 'app', 'helpers'), controller_path ] end def lib_path diff --git a/railties/lib/rails/plugin/loader.rb b/railties/lib/rails/plugin/loader.rb index f08d9b74e2..be81bdf4fa 100644 --- a/railties/lib/rails/plugin/loader.rb +++ b/railties/lib/rails/plugin/loader.rb @@ -39,6 +39,8 @@ module Rails register_plugin_as_loaded(plugin) end + configure_engines + ensure_all_registered_plugins_are_loaded! end @@ -63,19 +65,31 @@ module Rails $LOAD_PATH.uniq! end - # Returns an array of all the controller paths found inside engine-type plugins. - def controller_paths - engines.collect(&:controller_path) - end - - # Returns an array of routing.rb files from all the plugins that include config/routes.rb - def routing_files - plugins.select(&:routed?).collect(&:routing_file) - end - protected + def configure_engines + if engines.any? + add_engine_routing_configurations + add_engine_controller_paths + add_engine_view_paths + end + end + def add_engine_routing_configurations + engines.select(&:routed?).collect(&:routing_file).each do |routing_file| + ActionController::Routing::Routes.add_configuration_file(routing_file) + end + end + + def add_engine_controller_paths + ActionController::Routing.controller_paths += engines.collect(&:controller_path) + end + + def add_engine_view_paths + # reverse it such that the last engine can overwrite view paths from the first, like with routes + ActionController::Base.view_paths += ActionView::PathSet.new(engines.collect(&:view_path).reverse) + end + # The locate_plugins method uses each class in config.plugin_locators to # find the set of all plugins available to this Rails application. def locate_plugins -- cgit v1.2.3