diff --git a/lib/rdoc/code_object/class_module.rb b/lib/rdoc/code_object/class_module.rb index f9af6f309e..f0e79563df 100644 --- a/lib/rdoc/code_object/class_module.rb +++ b/lib/rdoc/code_object/class_module.rb @@ -630,7 +630,9 @@ def parse comment_location # Path to this class or module for use with HTML generator output. def path - http_url + prefix = options.class_module_path_prefix + return http_url unless prefix + File.join(prefix, http_url) end ## diff --git a/lib/rdoc/code_object/top_level.rb b/lib/rdoc/code_object/top_level.rb index c567fec996..c3e54c318b 100644 --- a/lib/rdoc/code_object/top_level.rb +++ b/lib/rdoc/code_object/top_level.rb @@ -226,7 +226,9 @@ def page_name # Path to this file for use with HTML generator output. def path - http_url + prefix = options.file_path_prefix + return http_url unless prefix + File.join(prefix, http_url) end def pretty_print q # :nodoc: diff --git a/lib/rdoc/options.rb b/lib/rdoc/options.rb index a50ea806d7..67b2a070be 100644 --- a/lib/rdoc/options.rb +++ b/lib/rdoc/options.rb @@ -363,6 +363,16 @@ class RDoc::Options # Words to be ignored in autolink cross-references attr_accessor :autolink_excluded_words + ## + # The prefix to use for class and module page paths + + attr_accessor :class_module_path_prefix + + ## + # The prefix to use for file page paths + + attr_accessor :file_path_prefix + def initialize loaded_options = nil # :nodoc: init_ivars override loaded_options if loaded_options @@ -417,6 +427,8 @@ def init_ivars # :nodoc: @charset = @encoding.name @skip_tests = true @apply_default_exclude = true + @class_module_path_prefix = nil + @file_path_prefix = nil end def init_with map # :nodoc: diff --git a/test/rdoc/test_rdoc_class_module.rb b/test/rdoc/test_rdoc_class_module.rb index 7506d04f3c..dec1a4c24b 100644 --- a/test/rdoc/test_rdoc_class_module.rb +++ b/test/rdoc/test_rdoc_class_module.rb @@ -1548,6 +1548,13 @@ def test_fully_qualified_nesting_namespaces assert_equal ["A", "A::B", "A::B::C"], cm3.fully_qualified_nesting_namespaces end + def test_path + assert_equal 'C1.html', @c1.path + + @options.class_module_path_prefix = 'class' + assert_equal 'class/C1.html', @c1.path + end + class RDocClassModuleMixinsTest < XrefTestCase def setup super diff --git a/test/rdoc/test_rdoc_options.rb b/test/rdoc/test_rdoc_options.rb index 7ccf789877..6b880aacd7 100644 --- a/test/rdoc/test_rdoc_options.rb +++ b/test/rdoc/test_rdoc_options.rb @@ -87,6 +87,8 @@ def test_to_yaml 'skip_tests' => true, 'apply_default_exclude' => true, 'autolink_excluded_words' => [], + 'class_module_path_prefix' => nil, + 'file_path_prefix' => nil, } assert_equal expected, coder diff --git a/test/rdoc/test_rdoc_top_level.rb b/test/rdoc/test_rdoc_top_level.rb index ba077b02aa..385860517b 100644 --- a/test/rdoc/test_rdoc_top_level.rb +++ b/test/rdoc/test_rdoc_top_level.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require_relative 'xref_test_case' -class TestRDocTopLevel < XrefTestCase +class RDocTopLevelTest < XrefTestCase def setup super @@ -162,6 +162,13 @@ def test_http_url assert_equal 'path_other/level_rb.html', other_level.http_url end + def test_path + assert_equal 'path/top_level_rb.html', @top_level.path + + @options.file_path_prefix = 'file' + assert_equal 'file/path/top_level_rb.html', @top_level.path + end + def test_marshal_dump page = @store.add_file 'README.txt' page.parser = RDoc::Parser::Simple