Skip to content
Browse files

First draft.

  • Loading branch information...
0 parents commit ac84d3f6d4e212eb80f11a2ab8609cb189a9b8a5 @airblade committed Dec 12, 2007
Showing with 92 additions and 0 deletions.
  1. +20 −0 MIT-LICENSE
  2. +13 −0 README
  3. +22 −0 Rakefile
  4. +1 −0 init.rb
  5. +1 −0 install.rb
  6. +11 −0 lib/air_blade/plugin_routing/routing.rb
  7. +11 −0 routes.rb
  8. +4 −0 tasks/engine_routing_tasks.rake
  9. +8 −0 test/engine_routing_test.rb
  10. +1 −0 uninstall.rb
20 MIT-LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2007 [name of plugin creator]
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
13 README
@@ -0,0 +1,13 @@
+PluginRouting
+=============
+
+This plugin is a port of James Adam's RailsEngine routing extension[1].
+
+It allows plugins loaded subsequently to define their own routes in a familiar routes.rb file (see the example with this plugin). Users of the plugin can then add the plugin's routes in their application's routes at the appropriate location in config/routes.rb using:
+
+ map.from_plugin(name_of_plugin)
+
+[1] http://api.rails-engines.org/files/lib/engines/rails_extensions/routing_rb.html
+
+
+Copyright (c) 2007 [Andrew Stewart], released under the MIT license
22 Rakefile
@@ -0,0 +1,22 @@
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+
+desc 'Default: run unit tests.'
+task :default => :test
+
+desc 'Test the engine_routing plugin.'
+Rake::TestTask.new(:test) do |t|
+ t.libs << 'lib'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = true
+end
+
+desc 'Generate documentation for the engine_routing plugin.'
+Rake::RDocTask.new(:rdoc) do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'EngineRouting'
+ rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.rdoc_files.include('README')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
1 init.rb
@@ -0,0 +1 @@
+ActionController::Routing::RouteSet::Mapper.send :include, AirBlade::PluginRouting::Routing
1 install.rb
@@ -0,0 +1 @@
+# Install hook code here
11 lib/air_blade/plugin_routing/routing.rb
@@ -0,0 +1,11 @@
+module AirBlade
+ module PluginRouting
+ module Routing
+ def from_plugin(name)
+ plugin_root = File.join(RAILS_ROOT, 'vendor', 'plugins')
+ routes_path = File.join(plugin_root, name.to_s, 'routes.rb')
+ eval(IO.read(routes_path), binding, routes_path) if File.file?(routes_path)
+ end
+ end
+ end
+end
11 routes.rb
@@ -0,0 +1,11 @@
+# Examples of the routes your (other) plugins can define.
+
+# Add an anonymous route
+connect "/login", :controller => "my_plugin/account", :action => "login"
+# Add a named route
+logout "/logout", :controller => "my_plugin/account", :action => "logout"
+
+# Some restful stuff
+resources :things do |t|
+ t.resources :other_things
+end
4 tasks/engine_routing_tasks.rake
@@ -0,0 +1,4 @@
+# desc "Explaining what the task does"
+# task :engine_routing do
+# # Task goes here
+# end
8 test/engine_routing_test.rb
@@ -0,0 +1,8 @@
+require 'test/unit'
+
+class EngineRoutingTest < Test::Unit::TestCase
+ # Replace this with your real tests.
+ def test_this_plugin
+ flunk
+ end
+end
1 uninstall.rb
@@ -0,0 +1 @@
+# Uninstall hook code here

0 comments on commit ac84d3f

Please sign in to comment.
Something went wrong with that request. Please try again.