diff --git a/app/controllers/file_controller.rb b/app/controllers/file_controller.rb index 72feb649..006797db 100644 --- a/app/controllers/file_controller.rb +++ b/app/controllers/file_controller.rb @@ -1,4 +1,5 @@ require 'application' + class FileController < ApplicationController layout 'default', :except => [:rss_feed, :rss_with_headlines, :tex, :export_tex, :export_html] diff --git a/libraries/url_rewriting_hack.rb b/libraries/url_rewriting_hack.rb index 2d8ffbc1..f7708f5d 100755 --- a/libraries/url_rewriting_hack.rb +++ b/libraries/url_rewriting_hack.rb @@ -6,7 +6,7 @@ # In Instiki URLs are mapped to the ActionPack actions, possibly performed on a particular # web (sub-wiki) and page within that web. # -# 1. Controller is always 'wiki' +# 1. Controller is determined by action name (default is 'wiki') # 2. '/name1/' maps to action 'name1', unspecified web # Example: http://localhost/new_system/ # 3. Special case of above, URI '/wiki/' maps to action 'index', because Rails sets this address @@ -24,6 +24,16 @@ require 'dispatcher' class DispatchServlet def self.parse_uri(path) + result = parse_path(path) + if result + result[:controller] = ActionMapper.map_to_controller(result[:action]) + result + else + false + end + end + + def self.parse_path(path) ApplicationController.logger.debug "Parsing URI '#{path}'" component = '([-_a-zA-Z0-9]+)' page_name = '(.*)' @@ -48,6 +58,19 @@ class DispatchServlet line end end + + class ActionMapper + + @@action_to_controller_map = { + 'file' => 'file', + 'pic' => 'file' + } + + def self.map_to_controller(action) + @@action_to_controller_map[action] || 'wiki' + end + + end end diff --git a/test/unit/url_rewriting_hack_test.rb b/test/unit/url_rewriting_hack_test.rb index 008fd0d7..cf615727 100755 --- a/test/unit/url_rewriting_hack_test.rb +++ b/test/unit/url_rewriting_hack_test.rb @@ -72,5 +72,21 @@ class UrlRewritingHackTest < Test::Unit::TestCase assert_equal 'http://test.host/', ur.rewrite(:controller => 'wiki') end + + def test_controller_mapping + request = ActionController::TestRequest.new + ur = ActionController::UrlRewriter.new(request, 'wiki', 'show') + + assert_equal 'http://test.host/file', + ur.rewrite(:controller => 'file', :action => 'file') + assert_equal 'http://test.host/pic/abc.jpg', + ur.rewrite(:controller => 'file', :action => 'pic', :id => 'abc.jpg') + assert_equal 'http://test.host/web/pic/abc.jpg', + ur.rewrite(:web => 'web', :controller => 'file', :action => 'pic', :id => 'abc.jpg') + + # default option is wiki + assert_equal 'http://test.host/unknown_action', + ur.rewrite(:controller => 'wiki', :action => 'unknown_action') + end end \ No newline at end of file