Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --load-ri-dir to generate other format #723

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 22 additions & 4 deletions lib/rdoc/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class RDoc::Options
generator_options
generators
op_dir
load_ri_dir
option_parser
pipe
rdoc_include
Expand Down Expand Up @@ -246,6 +247,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

Expand Down Expand Up @@ -364,6 +370,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
Expand Down Expand Up @@ -402,6 +409,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']
Expand All @@ -424,10 +432,11 @@ def == other # :nodoc:
@hyperlink_all == other.hyperlink_all and
@line_numbers == other.line_numbers and
@locale == other.locale and
@locale_dir == other.locale_dir and
@locale_dir == other.locale_dir and
@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
Expand Down Expand Up @@ -524,9 +533,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
Expand Down Expand Up @@ -865,6 +875,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",
Expand Down
9 changes: 8 additions & 1 deletion lib/rdoc/rdoc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
48 changes: 48 additions & 0 deletions test/test_rdoc_rdoc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down