From 5786930e831cca2ac53b548858aa71df91e93afb Mon Sep 17 00:00:00 2001 From: aycabta Date: Sun, 9 Jun 2019 21:34:12 +0900 Subject: [PATCH] Add --load-ri-dir to generate other format --- lib/rdoc/options.rb | 24 ++++++++++++++++--- lib/rdoc/rdoc.rb | 9 ++++++- test/rdoc/test_rdoc_rdoc.rb | 48 +++++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 4 deletions(-) diff --git a/lib/rdoc/options.rb b/lib/rdoc/options.rb index a607a76d56..9a8e11d280 100644 --- a/lib/rdoc/options.rb +++ b/lib/rdoc/options.rb @@ -105,6 +105,7 @@ class RDoc::Options generator_name generator_options generators + load_ri_dir locale op_dir page_dir @@ -248,6 +249,11 @@ class RDoc::Options attr_accessor :op_dir + ## + # The loading ri directory to generate other format + + attr_accessor :load_ri_dir + ## # The OptionParser for this instance @@ -377,6 +383,7 @@ def init_ivars # :nodoc: @markup = 'rdoc' @coverage_report = false @op_dir = nil + @load_ri_dir = nil @page_dir = nil @pipe = false @output_decoration = true @@ -417,6 +424,7 @@ def init_with map # :nodoc: @main_page = map['main_page'] @markup = map['markup'] @op_dir = map['op_dir'] + @load_ri_dir = map['load_ri_dir'] @show_hash = map['show_hash'] @tab_width = map['tab_width'] @template_dir = map['template_dir'] @@ -477,6 +485,7 @@ def == other # :nodoc: @main_page == other.main_page and @markup == other.markup and @op_dir == other.op_dir and + @load_ri_dir == other.load_ri_dir and @rdoc_include == other.rdoc_include and @show_hash == other.show_hash and @static_path == other.static_path and @@ -582,9 +591,10 @@ def finish @exclude = self.exclude - finish_page_dir - - check_files + unless @load_ri_dir + finish_page_dir + check_files + end # If no template was specified, use the default template for the output # formatter @@ -944,6 +954,14 @@ def parse argv opt.separator nil + opt.on("--load-ri-dir=DIR", Path, + "Specify a ri data directory to generate", + "other format.") do |value| + @load_ri_dir = value + end + + opt.separator nil + opt.on("-d", "Deprecated --diagram option.", "Prevents firing debug mode", diff --git a/lib/rdoc/rdoc.rb b/lib/rdoc/rdoc.rb index 0276d430a9..fbf3b59fa3 100644 --- a/lib/rdoc/rdoc.rb +++ b/lib/rdoc/rdoc.rb @@ -480,7 +480,14 @@ def document options @store.load_cache - file_info = parse_files @options.files + if @options.load_ri_dir + @store.path = @options.load_ri_dir + @store.load_all + @stats = RDoc::Stats.new @store, @store.all_files.length, @options.verbosity + file_info = @store.all_files + else + file_info = parse_files @options.files + end @options.default_title = "RDoc Documentation" diff --git a/test/rdoc/test_rdoc_rdoc.rb b/test/rdoc/test_rdoc_rdoc.rb index 9c94988ffd..45e3d34925 100644 --- a/test/rdoc/test_rdoc_rdoc.rb +++ b/test/rdoc/test_rdoc_rdoc.rb @@ -68,6 +68,54 @@ def test_document_with_dry_run # functional test assert_equal 'title', store.title end + def test_load_ri_dir + temp_dir do + # generate ri files + options = RDoc::Options.new + options.files = [File.expand_path('../xref_test_case.rb', __FILE__)] + options.setup_generator 'ri' + options.main_page = 'MAIN_PAGE.rdoc' + options.root = Pathname File.expand_path('..', __FILE__) + options.title = 'title' + options.op_dir = 'ri' + + rdoc = RDoc::RDoc.new + + capture_io do + rdoc.document options + end + + assert File.directory? 'ri' + assert_equal rdoc, rdoc.store.rdoc + + store = rdoc.store + + assert_equal 'MAIN_PAGE.rdoc', store.main + assert_equal 'title', store.title + + # generate HTML from ri files + options = RDoc::Options.new + options.setup_generator 'darkfish' + options.load_ri_dir = 'ri' + options.op_dir = 'another' + + rdoc = RDoc::RDoc.new + + capture_io do + rdoc.document options + end + + assert File.directory? 'another' + assert_equal rdoc, rdoc.store.rdoc + + store = rdoc.store + + assert_equal 'MAIN_PAGE.rdoc', store.main + assert_equal 'title', store.title + assert_file 'another/XrefTestCase.html' + end + end + def test_gather_files a = File.expand_path __FILE__ b = File.expand_path '../test_rdoc_text.rb', __FILE__