Skip to content

Allow customizing path prefix through options #1330

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

Merged
merged 1 commit into from
Mar 29, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/rdoc/code_object/class_module.rb
Original file line number Diff line number Diff line change
@@ -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

##
4 changes: 3 additions & 1 deletion lib/rdoc/code_object/top_level.rb
Original file line number Diff line number Diff line change
@@ -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:
12 changes: 12 additions & 0 deletions lib/rdoc/options.rb
Original file line number Diff line number Diff line change
@@ -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:
7 changes: 7 additions & 0 deletions test/rdoc/test_rdoc_class_module.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions test/rdoc/test_rdoc_options.rb
Original file line number Diff line number Diff line change
@@ -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
9 changes: 8 additions & 1 deletion test/rdoc/test_rdoc_top_level.rb
Original file line number Diff line number Diff line change
@@ -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
Loading
Oops, something went wrong.