Skip to content

Commit 76f604c

Browse files
committed
Allow customizing path prefix through options
In #1304, I removed the ability to set path prefix through patching Darkfish generator. But it turns out that it's used in `sdoc`. See #1304 (comment) But the original implementation was brittle and confusing. So instead of just restoring it, I think allowing the customization through options is a better approach.
1 parent d5ec331 commit 76f604c

File tree

6 files changed

+37
-3
lines changed

6 files changed

+37
-3
lines changed

lib/rdoc/code_object/class_module.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,9 @@ def parse comment_location
630630
# Path to this class or module for use with HTML generator output.
631631

632632
def path
633-
http_url
633+
prefix = options.class_module_path_prefix
634+
return http_url unless prefix
635+
File.join(prefix, http_url)
634636
end
635637

636638
##

lib/rdoc/code_object/top_level.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,9 @@ def page_name
226226
# Path to this file for use with HTML generator output.
227227

228228
def path
229-
http_url
229+
prefix = options.file_path_prefix
230+
return http_url unless prefix
231+
File.join(prefix, http_url)
230232
end
231233

232234
def pretty_print q # :nodoc:

lib/rdoc/options.rb

+12
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,16 @@ class RDoc::Options
363363
# Words to be ignored in autolink cross-references
364364
attr_accessor :autolink_excluded_words
365365

366+
##
367+
# The prefix to use for class and module page paths
368+
369+
attr_accessor :class_module_path_prefix
370+
371+
##
372+
# The prefix to use for file page paths
373+
374+
attr_accessor :file_path_prefix
375+
366376
def initialize loaded_options = nil # :nodoc:
367377
init_ivars
368378
override loaded_options if loaded_options
@@ -417,6 +427,8 @@ def init_ivars # :nodoc:
417427
@charset = @encoding.name
418428
@skip_tests = true
419429
@apply_default_exclude = true
430+
@class_module_path_prefix = nil
431+
@file_path_prefix = nil
420432
end
421433

422434
def init_with map # :nodoc:

test/rdoc/test_rdoc_class_module.rb

+8
Original file line numberDiff line numberDiff line change
@@ -1548,6 +1548,14 @@ def test_fully_qualified_nesting_namespaces
15481548
assert_equal ["A", "A::B", "A::B::C"], cm3.fully_qualified_nesting_namespaces
15491549
end
15501550

1551+
def test_path
1552+
assert_equal 'C1.html', @c1.path
1553+
1554+
# Note: @options != @store.options
1555+
@store.options.class_module_path_prefix = 'class'
1556+
assert_equal 'class/C1.html', @c1.path
1557+
end
1558+
15511559
class RDocClassModuleMixinsTest < XrefTestCase
15521560
def setup
15531561
super

test/rdoc/test_rdoc_options.rb

+2
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ def test_to_yaml
8787
'skip_tests' => true,
8888
'apply_default_exclude' => true,
8989
'autolink_excluded_words' => [],
90+
'class_module_path_prefix' => nil,
91+
'file_path_prefix' => nil,
9092
}
9193

9294
assert_equal expected, coder

test/rdoc/test_rdoc_top_level.rb

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22
require_relative 'xref_test_case'
33

4-
class TestRDocTopLevel < XrefTestCase
4+
class RDocTopLevelTest < XrefTestCase
55

66
def setup
77
super
@@ -162,6 +162,14 @@ def test_http_url
162162
assert_equal 'path_other/level_rb.html', other_level.http_url
163163
end
164164

165+
def test_path
166+
assert_equal 'path/top_level_rb.html', @top_level.path
167+
168+
# Note: @options != @store.options
169+
@store.options.file_path_prefix = 'file'
170+
assert_equal 'file/path/top_level_rb.html', @top_level.path
171+
end
172+
165173
def test_marshal_dump
166174
page = @store.add_file 'README.txt'
167175
page.parser = RDoc::Parser::Simple

0 commit comments

Comments
 (0)