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

ruby-changes:26254

From: drbrain <ko1@a...>
Date: Tue, 11 Dec 2012 16:45:07 +0900 (JST)
Subject: [ruby-changes:26254] drbrain:r38311 (trunk): * lib/rdoc/options.rb: Added --page-dir option for moving pages in

drbrain	2012-12-11 16:44:56 +0900 (Tue, 11 Dec 2012)

  New Revision: 38311

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

  Log:
    * lib/rdoc/options.rb:  Added --page-dir option for moving pages in
      doc/ to the top-level.
    * lib/rdoc/rdoc.rb:  ditto.
    * test/rdoc/test_rdoc_options.rb:  Test for the above.
    * test/rdoc/test_rdoc_rdoc.rb:  ditto.

  Modified files:
    trunk/ChangeLog
    trunk/lib/rdoc/options.rb
    trunk/lib/rdoc/rdoc.rb
    trunk/test/rdoc/test_rdoc_options.rb
    trunk/test/rdoc/test_rdoc_rdoc.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 38310)
+++ ChangeLog	(revision 38311)
@@ -1,3 +1,11 @@
+Tue Dec 11 16:44:37 2012  Eric Hodel  <drbrain@s...>
+
+	* lib/rdoc/options.rb:  Added --page-dir option for moving pages in
+	  doc/ to the top-level.
+	* lib/rdoc/rdoc.rb:  ditto.
+	* test/rdoc/test_rdoc_options.rb:  Test for the above.
+	* test/rdoc/test_rdoc_rdoc.rb:  ditto.
+
 Tue Dec 11 15:24:05 2012  Eric Hodel  <drbrain@s...>
 
 	* ext/pathname/lib/pathname.rb:  Hide private methods from RDoc.
Index: lib/rdoc/rdoc.rb
===================================================================
--- lib/rdoc/rdoc.rb	(revision 38310)
+++ lib/rdoc/rdoc.rb	(revision 38311)
@@ -349,6 +349,12 @@
     filename_path = Pathname(filename).expand_path
     relative_path = filename_path.relative_path_from @options.root
 
+    if @options.page_dir and
+       relative_path.to_s.start_with? @options.page_dir.to_s then
+      relative_path =
+        relative_path.relative_path_from @options.page_dir
+    end
+
     top_level = @store.add_file filename, relative_path.to_s
 
     parser = RDoc::Parser.for top_level, filename, content, @options, @stats
Index: lib/rdoc/options.rb
===================================================================
--- lib/rdoc/options.rb	(revision 38310)
+++ lib/rdoc/options.rb	(revision 38311)
@@ -229,6 +229,12 @@
   attr_accessor :option_parser
 
   ##
+  # Directory where guides, FAQ, and other pages not associated with a class
+  # live.  You may leave this unset if these are at the root of your project.
+
+  attr_accessor :page_dir
+
+  ##
   # Is RDoc in pipe mode?
 
   attr_accessor :pipe
@@ -317,6 +323,7 @@
     @markup = 'rdoc'
     @coverage_report = false
     @op_dir = nil
+    @page_dir = nil
     @pipe = false
     @rdoc_include = []
     @root = Pathname(Dir.pwd)
@@ -468,6 +475,8 @@
       @exclude = Regexp.new(@exclude.join("|"))
     end
 
+    finish_page_dir
+
     check_files
 
     # If no template was specified, use the default template for the output
@@ -482,6 +491,20 @@
   end
 
   ##
+  # Fixes the page_dir to be relative to the root_dir and adds the page_dir to
+  # the files list.
+
+  def finish_page_dir
+    return unless @page_dir
+
+    @files << @page_dir.to_s
+
+    page_dir = @page_dir.expand_path.relative_path_from @root
+
+    @page_dir = page_dir
+  end
+
+  ##
   # Returns a properly-space list of generators and their descriptions.
 
   def generator_descriptions
@@ -665,7 +688,7 @@
 
       opt.separator nil
 
-      opt.on("--pipe",
+      opt.on("--pipe", "-p",
              "Convert RDoc on stdin to HTML") do
         @pipe = true
       end
@@ -709,6 +732,18 @@
       end
 
       opt.separator nil
+
+      opt.on("--page-dir=DIR", Directory,
+             "Directory where guides, your FAQ or",
+             "other pages not associated with a class",
+             "live.  Set this when you don't store",
+             "such files at your project root.",
+             "NOTE: Do not use the same file name in",
+             "the page dir and the root of your project") do |page_dir|
+        @page_dir = Pathname(page_dir)
+      end
+
+      opt.separator nil
       opt.separator "Common generator options:"
       opt.separator nil
 
Index: test/rdoc/test_rdoc_rdoc.rb
===================================================================
--- test/rdoc/test_rdoc_rdoc.rb	(revision 38310)
+++ test/rdoc/test_rdoc_rdoc.rb	(revision 38311)
@@ -158,6 +158,25 @@
     end
   end
 
+  def test_parse_file_page_dir
+    @rdoc.store = RDoc::Store.new
+
+    temp_dir do |dir|
+      FileUtils.mkdir 'pages'
+      @rdoc.options.page_dir = Pathname('pages')
+      @rdoc.options.root = Pathname(Dir.pwd)
+
+      open 'pages/test.txt', 'w' do |io|
+        io.puts 'hi'
+      end
+
+      top_level = @rdoc.parse_file 'pages/test.txt'
+
+      assert_equal 'pages/test.txt', top_level.absolute_name
+      assert_equal 'test.txt',       top_level.relative_name
+    end
+  end
+
   def test_parse_file_relative
     pwd = Dir.pwd
 
Index: test/rdoc/test_rdoc_options.rb
===================================================================
--- test/rdoc/test_rdoc_options.rb	(revision 38310)
+++ test/rdoc/test_rdoc_options.rb	(revision 38311)
@@ -76,6 +76,7 @@
       'line_numbers'   => false,
       'main_page'      => nil,
       'markup'         => 'rdoc',
+      'page_dir'       => nil,
       'rdoc_include'   => [],
       'show_hash'      => false,
       'static_path'    => [],
@@ -430,6 +431,43 @@
     assert_equal 'tomdoc', @options.markup
   end
 
+  def test_parse_page_dir
+    assert_nil @options.page_dir
+
+    out, err = capture_io do
+      @options.parse %W[--page-dir #{Dir.tmpdir}]
+    end
+
+    assert_empty out
+    assert_empty err
+
+    expected =
+      Pathname(Dir.tmpdir).expand_path.relative_path_from @options.root
+
+    assert_equal expected,     @options.page_dir
+    assert_equal [Dir.tmpdir], @options.files
+  end
+
+  def test_parse_page_dir_root
+    assert_nil @options.page_dir
+
+    Dir.mktmpdir do |dir|
+      abs_root     = dir
+      abs_page_dir = File.join dir, 'pages'
+      FileUtils.mkdir abs_page_dir
+
+      out, err = capture_io do
+        @options.parse %W[--page-dir #{abs_page_dir} --root #{abs_root}]
+      end
+
+      assert_empty out
+      assert_empty err
+
+      assert_equal Pathname('pages'), @options.page_dir
+      assert_equal [abs_page_dir],    @options.files
+    end
+  end
+
   def test_parse_root
     assert_equal Pathname(Dir.pwd), @options.root
 

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

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