public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Added that config/routes.rb files in engine plugins are automatically loaded 
(and reloaded when they change in dev mode) [DHH]
dhh (author)
Wed Nov 26 11:03:25 -0800 2008
commit  4999d52e08a02ebba344f6c318f0af4b5b18f0e5
tree    f0d2af329fb961b6619ee5f2c21666168f8bb321
parent  40b40c487040d9c721d486e8ec8cfbc53a8cd79a
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 *2.3.0 [Edge]*
0
 
0
+* Added that config/routes.rb files in engine plugins are automatically loaded (and reloaded when they change in dev mode) [DHH]
0
+
0
 * Added app/[models|controllers|helpers] to the load path for plugins that has an app directory (go engines ;)) [DHH]
0
 
0
 * Add config.preload_frameworks to load all frameworks at startup. Default to false so Rails autoloads itself as it's used. Turn this on for Passenger and JRuby. Also turned on by config.threadsafe!  [Jeremy Kemper]
...
486
487
488
489
490
 
 
 
 
 
 
 
491
492
493
...
486
487
488
 
 
489
490
491
492
493
494
495
496
497
498
0
@@ -486,8 +486,13 @@ Run `rake gems:install` to install the missing gems.
0
     # loading module used to lazily load controllers (Configuration#controller_paths).
0
     def initialize_routing
0
       return unless configuration.frameworks.include?(:action_controller)
0
-      ActionController::Routing.controller_paths = configuration.controller_paths
0
-      ActionController::Routing::Routes.configuration_file = configuration.routes_configuration_file
0
+
0
+      ActionController::Routing.controller_paths = configuration.controller_paths + plugin_loader.controller_paths
0
+
0
+      ([ configuration.routes_configuration_file ] + plugin_loader.routing_files).each do |routing_file|
0
+        ActionController::Routing::Routes.add_configuration_file(routing_file)
0
+      end
0
+
0
       ActionController::Routing::Routes.reload
0
     end
0
 
...
40
41
42
43
 
44
45
46
...
60
61
62
 
 
 
 
 
63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
65
66
...
82
83
84
85
 
86
87
88
...
40
41
42
 
43
44
45
46
...
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
...
101
102
103
 
104
105
106
107
0
@@ -40,7 +40,7 @@ module Rails
0
         load_paths << app_paths if has_app_directory?
0
       end.flatten
0
     end
0
-
0
+    
0
     # Evaluates a plugin's init.rb file.
0
     def load(initializer)
0
       return if loaded?
0
@@ -60,7 +60,26 @@ module Rails
0
     def about
0
       @about ||= load_about_information
0
     end
0
+
0
+    # Engines are plugins with an app/ directory.
0
+    def engine?
0
+      has_app_directory?
0
+    end
0
     
0
+    # Returns true if the engine ships with a routing file
0
+    def routed?
0
+      File.exist?(routing_file)
0
+    end
0
+
0
+    def controller_path
0
+      File.join(directory, 'app', 'controllers')
0
+    end
0
+
0
+    def routing_file
0
+      File.join(directory, 'config', 'routes.rb')
0
+    end
0
+    
0
+
0
     private
0
       def load_about_information
0
         about_yml_path = File.join(@directory, "about.yml")
0
@@ -82,7 +101,7 @@ module Rails
0
           File.join(directory, 'app', 'helpers')
0
         ]
0
       end
0
-    
0
+      
0
       def lib_path
0
         File.join(directory, 'lib')
0
       end
...
22
23
24
 
 
 
 
 
25
26
27
...
56
57
58
59
 
 
 
 
 
 
 
 
 
 
 
60
61
62
...
22
23
24
25
26
27
28
29
30
31
32
...
61
62
63
 
64
65
66
67
68
69
70
71
72
73
74
75
76
77
0
@@ -22,6 +22,11 @@ module Rails
0
         @plugins ||= all_plugins.select { |plugin| should_load?(plugin) }.sort { |p1, p2| order_plugins(p1, p2) }
0
       end
0
 
0
+      # Returns the plugins that are in engine-form (have an app/ directory)
0
+      def engines
0
+        @engines ||= plugins.select(&:engine?)
0
+      end
0
+
0
       # Returns all the plugins that could be found by the current locators.
0
       def all_plugins
0
         @all_plugins ||= locate_plugins
0
@@ -56,7 +61,17 @@ module Rails
0
         end
0
 
0
         $LOAD_PATH.uniq!
0
-      end      
0
+      end
0
+      
0
+      # Returns an array of all the controller paths found inside engine-type plugins.
0
+      def controller_paths
0
+        engines.collect(&:controller_path)
0
+      end
0
+      
0
+      def routing_files
0
+        engines.select(&:routed?).collect(&:routing_file)
0
+      end
0
+      
0
       
0
       protected
0
       
...
252
253
254
 
255
256
257
...
252
253
254
255
256
257
258
0
@@ -252,6 +252,7 @@ uses_mocha "Initializer plugin loading tests" do
0
       assert $LOAD_PATH.include?(File.join(plugin_fixture_path('default/acts/acts_as_chunky_bacon'), 'lib'))
0
     end
0
 
0
+
0
     private
0
 
0
       def load_plugins!
...
47
48
49
50
 
51
52
53
...
47
48
49
 
50
51
52
53
0
@@ -47,7 +47,7 @@ uses_mocha "Plugin Locator Tests" do
0
     end
0
   
0
     def test_should_return_all_plugins_found_under_the_set_plugin_paths
0
-      assert_equal ["a", "acts_as_chunky_bacon", "gemlike", "plugin_with_no_lib_dir", "stubby"].sort, @locator.plugins.map(&:name).sort
0
+      assert_equal ["a", "acts_as_chunky_bacon", "engine", "gemlike", "plugin_with_no_lib_dir", "stubby"].sort, @locator.plugins.map(&:name).sort
0
     end
0
   
0
     def test_should_find_plugins_only_under_the_plugin_paths_set_in_configuration

Comments

moklett Tue Feb 03 18:45:28 -0800 2009

So, engines routes are currently placed before main app routes… is thought being given to a way of inserting engine routes at other points in the route set order?