public
Description: Social network platform built with modular, pluggable, and configurable components
Homepage: http://projects.entp.com/tentacle
Clone URL: git://github.com/courtenay/tentacle.git
Search Repo:
Make routes work magically

Adds a Rails.plugin_routes array into which plugins can push a symbol.
Rails' routing will call map.from_plugin on any symbols found here.
This way we can drop in plugins without modifying the core app.
Court3nay (author)
Fri Apr 11 12:59:59 -0700 2008
commit  b6459d8e6ac5e851ef0414b9c5ed75debce434be
tree    f07dd0e867601e2d215e13dda401057bd364e916
parent  eb3772d9059aa0777f9e3389f36e367f39f836f0
...
15
16
17
 
 
 
 
18
19
20
...
15
16
17
18
19
20
21
22
23
24
0
@@ -15,6 +15,10 @@
0
 require File.join(File.dirname(__FILE__), 'boot')
0
 require File.join(File.dirname(__FILE__), '../vendor/plugins/engines/boot')
0
 
0
+# Allow us to define routes in plugins
1
+Rails.mattr_accessor :plugin_routes
0
+Rails.plugin_routes = []
0
+
0
 Rails::Initializer.run do |config|
0
   # Settings in config/environments/* take precedence over those specified here
0
   
...
4
5
6
7
8
9
10
11
 
 
 
 
12
13
14
...
4
5
6
 
 
 
7
8
9
10
11
12
13
14
15
0
@@ -4,11 +4,12 @@
0
 ActionController::Routing::Routes.draw do |map|
0
   map.connect ":asset/:plugin/*paths", :asset => /images|javascripts|stylesheets/, :controller => "assets", :action => "show"
0
   
0
- map.from_plugin :profiles
0
- map.from_plugin :tentacled_beast
0
-
0
   map.with_options :path_prefix => 'admin' do |admin|
0
     admin.resources :users
0
+ end
0
+
0
+ Rails.plugin_routes.each do |plugin|
0
+ map.from_plugin plugin
0
   end
0
   
0
   map.with_options :controller => "sessions" do |s|
...
1
 
 
...
1
2
3
0
@@ -1,2 +1,4 @@
0
 # Include hook code here
0
+
0
+Rails.plugin_routes << :groups
...
1
 
 
...
1
2
3
0
@@ -1,2 +1,4 @@
0
 # Include hook code here
0
+
0
+Rails.plugin_routes << :profiles
...
1
 
 
...
1
2
3
0
@@ -1,2 +1,4 @@
0
 # Include hook code here
0
+
0
+Rails.plugin_routes << :tentacled_beast

Comments

  • lazyatom Sat May 03 16:14:41 -0700 2008 at config/environment.rb L19

    This is really interesting. Do you think it’s worth extracting for general use? Perhaps alongside some kind of map.all_plugin_routes method?

  • courtenay Sat May 03 21:03:41 -0700 2008

    Yes.. actually I think it should work with more of a Rails.plugin_routes do |map| style, rather than just hardcoding map.resources. I’m trying to do something like this for models also, but so far it’s eluded me.