mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38311 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d5ba73e0d9
commit
b65b75bf2c
5 changed files with 107 additions and 1 deletions
|
@ -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.
|
||||
|
|
|
@ -228,6 +228,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?
|
||||
|
||||
|
@ -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
|
||||
|
@ -481,6 +490,20 @@ class RDoc::Options
|
|||
self
|
||||
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.
|
||||
|
||||
|
@ -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
|
||||
|
@ -708,6 +731,18 @@ Usage: #{opt.program_name} [options] [names...]
|
|||
@root = Pathname(root)
|
||||
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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue