Skip to content

Commit a931341

Browse files
committed
Add --load-ri-dir to generate other format
1 parent 5f9603f commit a931341

File tree

3 files changed

+78
-5
lines changed

3 files changed

+78
-5
lines changed

lib/rdoc/options.rb

+22-4
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ class RDoc::Options
106106
generator_options
107107
generators
108108
op_dir
109+
load_ri_dir
109110
option_parser
110111
pipe
111112
rdoc_include
@@ -246,6 +247,11 @@ class RDoc::Options
246247

247248
attr_accessor :op_dir
248249

250+
##
251+
# The loading ri directory to generate other format
252+
253+
attr_accessor :load_ri_dir
254+
249255
##
250256
# The OptionParser for this instance
251257

@@ -364,6 +370,7 @@ def init_ivars # :nodoc:
364370
@markup = 'rdoc'
365371
@coverage_report = false
366372
@op_dir = nil
373+
@load_ri_dir = nil
367374
@page_dir = nil
368375
@pipe = false
369376
@output_decoration = true
@@ -402,6 +409,7 @@ def init_with map # :nodoc:
402409
@main_page = map['main_page']
403410
@markup = map['markup']
404411
@op_dir = map['op_dir']
412+
@load_ri_dir = map['load_ri_dir']
405413
@show_hash = map['show_hash']
406414
@tab_width = map['tab_width']
407415
@template_dir = map['template_dir']
@@ -424,10 +432,11 @@ def == other # :nodoc:
424432
@hyperlink_all == other.hyperlink_all and
425433
@line_numbers == other.line_numbers and
426434
@locale == other.locale and
427-
@locale_dir == other.locale_dir and
435+
@locale_dir == other.locale_dir and
428436
@main_page == other.main_page and
429437
@markup == other.markup and
430438
@op_dir == other.op_dir and
439+
@load_ri_dir == other.load_ri_dir and
431440
@rdoc_include == other.rdoc_include and
432441
@show_hash == other.show_hash and
433442
@static_path == other.static_path and
@@ -524,9 +533,10 @@ def finish
524533

525534
@exclude = self.exclude
526535

527-
finish_page_dir
528-
529-
check_files
536+
unless @load_ri_dir
537+
finish_page_dir
538+
check_files
539+
end
530540

531541
# If no template was specified, use the default template for the output
532542
# formatter
@@ -865,6 +875,14 @@ def parse argv
865875

866876
opt.separator nil
867877

878+
opt.on("--load-ri-dir=DIR", Path,
879+
"Specify a ri data directory to generate",
880+
"other format.") do |value|
881+
@load_ri_dir = value
882+
end
883+
884+
opt.separator nil
885+
868886
opt.on("-d",
869887
"Deprecated --diagram option.",
870888
"Prevents firing debug mode",

lib/rdoc/rdoc.rb

+8-1
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,14 @@ def document options
480480

481481
@store.load_cache
482482

483-
file_info = parse_files @options.files
483+
if @options.load_ri_dir
484+
@store.path = @options.load_ri_dir
485+
@store.load_all
486+
@stats = RDoc::Stats.new @store, @store.all_files.length, @options.verbosity
487+
file_info = @store.all_files
488+
else
489+
file_info = parse_files @options.files
490+
end
484491

485492
@options.default_title = "RDoc Documentation"
486493

test/test_rdoc_rdoc.rb

+48
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,54 @@ def test_document_with_dry_run # functional test
6868
assert_equal 'title', store.title
6969
end
7070

71+
def test_load_ri_dir
72+
temp_dir do
73+
# generate ri files
74+
options = RDoc::Options.new
75+
options.files = [File.expand_path('../xref_test_case.rb', __FILE__)]
76+
options.setup_generator 'ri'
77+
options.main_page = 'MAIN_PAGE.rdoc'
78+
options.root = Pathname File.expand_path('..', __FILE__)
79+
options.title = 'title'
80+
options.op_dir = 'ri'
81+
82+
rdoc = RDoc::RDoc.new
83+
84+
capture_io do
85+
rdoc.document options
86+
end
87+
88+
assert File.directory? 'ri'
89+
assert_equal rdoc, rdoc.store.rdoc
90+
91+
store = rdoc.store
92+
93+
assert_equal 'MAIN_PAGE.rdoc', store.main
94+
assert_equal 'title', store.title
95+
96+
# generate HTML from ri files
97+
options = RDoc::Options.new
98+
options.setup_generator 'darkfish'
99+
options.load_ri_dir = 'ri'
100+
options.op_dir = 'another'
101+
102+
rdoc = RDoc::RDoc.new
103+
104+
capture_io do
105+
rdoc.document options
106+
end
107+
108+
assert File.directory? 'another'
109+
assert_equal rdoc, rdoc.store.rdoc
110+
111+
store = rdoc.store
112+
113+
assert_equal 'MAIN_PAGE.rdoc', store.main
114+
assert_equal 'title', store.title
115+
assert_file 'another/XrefTestCase.html'
116+
end
117+
end
118+
71119
def test_gather_files
72120
a = File.expand_path __FILE__
73121
b = File.expand_path '../test_rdoc_text.rb', __FILE__

0 commit comments

Comments
 (0)