[前][次][番号順一覧][スレッド一覧]

ruby-changes:25870

From: drbrain <ko1@a...>
Date: Wed, 28 Nov 2012 16:41:30 +0900 (JST)
Subject: [ruby-changes:25870] drbrain:r37927 (trunk): * lib/rdoc/servlet.rb: Add support for serving documentation from a

drbrain	2012-11-28 16:41:19 +0900 (Wed, 28 Nov 2012)

  New Revision: 37927

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=37927

  Log:
    * lib/rdoc/servlet.rb:  Add support for serving documentation from a
      subdirectory.
    * lib/rdoc/generator/darkfish.rb:  ditto
    * test/rdoc/test_rdoc_servlet.rb:  Test for above
    * test/rdoc/test_rdoc_servlet.rb:  ditto

  Modified files:
    trunk/ChangeLog
    trunk/lib/rdoc/generator/darkfish.rb
    trunk/lib/rdoc/servlet.rb
    trunk/test/rdoc/test_rdoc_servlet.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 37926)
+++ ChangeLog	(revision 37927)
@@ -1,3 +1,11 @@
+Wed Nov 28 16:41:04 2012  Eric Hodel  <drbrain@s...>
+
+	* lib/rdoc/servlet.rb:  Add support for serving documentation from a
+	  subdirectory.
+	* lib/rdoc/generator/darkfish.rb:  ditto
+	* test/rdoc/test_rdoc_servlet.rb:  Test for above
+	* test/rdoc/test_rdoc_servlet.rb:  ditto
+
 Wed Nov 28 15:37:17 2012  NARUSE, Yui  <naruse@r...>
 
 	* configure.in: fix r37294: run only on i[3-6]86-linux.
Index: lib/rdoc/generator/darkfish.rb
===================================================================
--- lib/rdoc/generator/darkfish.rb	(revision 37926)
+++ lib/rdoc/generator/darkfish.rb	(revision 37927)
@@ -467,7 +467,7 @@
     render_template template_file do |io| binding end
   rescue => e
     error = RDoc::Error.new \
-      "error generating servlet_root: #{e.message} (#{e.class})"
+      "error generating servlet_not_found: #{e.message} (#{e.class})"
     error.set_backtrace e.backtrace
 
     raise error
@@ -484,13 +484,10 @@
 
     debug_msg 'Rendering the servlet root page...'
 
-    rel_prefix = rel_prefix = ''
+    rel_prefix = asset_rel_prefix = '.'
     search_index_rel_prefix = rel_prefix
     search_index_rel_prefix += @asset_rel_path if @file_output
 
-    # suppress 1.9.3 warning
-    asset_rel_prefix = asset_rel_prefix = ''
-
     @title = 'Local RDoc Documentation'
 
     render_template template_file do |io| binding end
Index: lib/rdoc/servlet.rb
===================================================================
--- lib/rdoc/servlet.rb	(revision 37926)
+++ lib/rdoc/servlet.rb	(revision 37927)
@@ -17,11 +17,13 @@
     new server, stores, @cache, *options
   end
 
-  def initialize server, stores, cache
+  def initialize server, stores, cache, mount_path = nil
     super server
 
-    @stores  = stores
-    @cache   = cache
+    @cache      = cache
+    @mount_path = mount_path
+    @stores     = stores
+
     @options = RDoc::Options.new
     @options.op_dir = '.'
 
@@ -59,6 +61,8 @@
   end
 
   def do_GET req, res
+    req.path.sub!(/^#{Regexp.escape @mount_path}/o, '') if @mount_path
+
     case req.path
     when '/' then
       root req, res
@@ -128,7 +132,7 @@
 
 <title>Error - #{ERB::Util.html_escape e.class}</title>
 
-<link type="text/css" media="screen" href="/rdoc.css" rel="stylesheet">
+<link type="text/css" media="screen" href="#{@mouth_path}/rdoc.css" rel="stylesheet">
 </head>
 <body>
 <h1>Error</h1>
Index: test/rdoc/test_rdoc_servlet.rb
===================================================================
--- test/rdoc/test_rdoc_servlet.rb	(revision 37926)
+++ test/rdoc/test_rdoc_servlet.rb	(revision 37927)
@@ -1,4 +1,5 @@
 require 'rdoc/test_case'
+
 class TestRDocServlet < RDoc::TestCase
 
   def setup
@@ -16,13 +17,13 @@
     Gem::Specification.reset
     Gem::Specification.all = [@spec]
 
-    server = {}
-    def server.mount(*) end
+    @server = {}
+    def @server.mount(*) end
 
     @stores = {}
     @cache  = Hash.new { |hash, store| hash[store] = {} }
 
-    @s = RDoc::Servlet.new server, @stores, @cache
+    @s = RDoc::Servlet.new @server, @stores, @cache
 
     @req = WEBrick::HTTPRequest.new :Logger => nil
     @res = WEBrick::HTTPResponse.new :HTTPVersion => '1.0'
@@ -126,6 +127,22 @@
     assert_equal 500, @res.status
   end
 
+  def test_do_GET_mount_path
+    @s = RDoc::Servlet.new @server, @stores, @cache, '/mount/path'
+
+    temp_dir do
+      FileUtils.touch 'rdoc.css'
+
+      @s.asset_dirs[:darkfish] = '.'
+
+      @req.path = '/mount/path/rdoc.css'
+
+      @s.do_GET @req, @res
+
+      assert_equal 'text/css', @res.content_type
+    end
+  end
+
   def test_do_GET_not_modified
     touch_system_cache_path
     @req.header['if-modified-since'] = [(Time.now + 10).httpdate]

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]