summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--lib/rdoc/options.rb37
-rw-r--r--lib/rdoc/rdoc.rb6
-rw-r--r--test/rdoc/test_rdoc_options.rb38
-rw-r--r--test/rdoc/test_rdoc_rdoc.rb19
5 files changed, 107 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 473c2fb43f7..23e4a0430c1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Tue Dec 11 16:44:37 2012 Eric Hodel <drbrain@segment7.net>
+
+ * 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@segment7.net>
* ext/pathname/lib/pathname.rb: Hide private methods from RDoc.
diff --git a/lib/rdoc/options.rb b/lib/rdoc/options.rb
index 57d457a8303..7be43ca776b 100644
--- a/lib/rdoc/options.rb
+++ b/lib/rdoc/options.rb
@@ -229,6 +229,12 @@ class RDoc::Options
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 @@ class RDoc::Options
@markup = 'rdoc'
@coverage_report = false
@op_dir = nil
+ @page_dir = nil
@pipe = false
@rdoc_include = []
@root = Pathname(Dir.pwd)
@@ -468,6 +475,8 @@ class RDoc::Options
@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 @@ class RDoc::Options
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 @@ Usage: #{opt.program_name} [options] [names...]
opt.separator nil
- opt.on("--pipe",
+ opt.on("--pipe", "-p",
"Convert RDoc on stdin to HTML") do
@pipe = true
end
@@ -709,6 +732,18 @@ Usage: #{opt.program_name} [options] [names...]
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
diff --git a/lib/rdoc/rdoc.rb b/lib/rdoc/rdoc.rb
index eabf4fd3f70..76da5b42890 100644
--- a/lib/rdoc/rdoc.rb
+++ b/lib/rdoc/rdoc.rb
@@ -349,6 +349,12 @@ option)
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
diff --git a/test/rdoc/test_rdoc_options.rb b/test/rdoc/test_rdoc_options.rb
index 723a2dccfd6..d53acf2a6cf 100644
--- a/test/rdoc/test_rdoc_options.rb
+++ b/test/rdoc/test_rdoc_options.rb
@@ -76,6 +76,7 @@ class TestRDocOptions < RDoc::TestCase
'line_numbers' => false,
'main_page' => nil,
'markup' => 'rdoc',
+ 'page_dir' => nil,
'rdoc_include' => [],
'show_hash' => false,
'static_path' => [],
@@ -430,6 +431,43 @@ rdoc_include:
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
diff --git a/test/rdoc/test_rdoc_rdoc.rb b/test/rdoc/test_rdoc_rdoc.rb
index 643f1eff774..e29363a47af 100644
--- a/test/rdoc/test_rdoc_rdoc.rb
+++ b/test/rdoc/test_rdoc_rdoc.rb
@@ -158,6 +158,25 @@ class TestRDocRDoc < RDoc::TestCase
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