From dbcfd026a82aca2506ed089d5f4be0686efb713e Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Thu, 12 Jun 2025 14:58:41 -0700 Subject: [PATCH 1/3] Allow rdoc-ref to link to non-text files It appears the current behavior of disallowing links to non-text files is deliberate, as it was explicitly added in 3628e196cbbac4767f5b845c5b795c635a671b04. While the commit message explains the change, it doesn't provide a justification for excluding non-text TopLevels. The issue mentioned in the commit message is also unrelated to the change. It's just as useful to link to a non-text file as it is to link to a text file, so I think it should be allowed. --- lib/rdoc/code_object/top_level.rb | 8 -------- lib/rdoc/cross_reference.rb | 2 +- lib/rdoc/store.rb | 2 +- test/rdoc/rdoc_cross_reference_test.rb | 2 +- test/rdoc/rdoc_top_level_test.rb | 7 +------ 5 files changed, 4 insertions(+), 17 deletions(-) diff --git a/lib/rdoc/code_object/top_level.rb b/lib/rdoc/code_object/top_level.rb index eeeff026a1..93d318901b 100644 --- a/lib/rdoc/code_object/top_level.rb +++ b/lib/rdoc/code_object/top_level.rb @@ -114,14 +114,6 @@ def base_name alias name base_name - ## - # Only a TopLevel that contains text file) will be displayed. See also - # RDoc::CodeObject#display? - - def display? - text? and super - end - ## # See RDoc::TopLevel::find_class_or_module #-- diff --git a/lib/rdoc/cross_reference.rb b/lib/rdoc/cross_reference.rb index a942d33c96..1f33538b73 100644 --- a/lib/rdoc/cross_reference.rb +++ b/lib/rdoc/cross_reference.rb @@ -200,7 +200,7 @@ def resolve(name, text) ref = resolve_method name unless ref # Try a page name - ref = @store.page name if not ref and name =~ /^[\w.]+$/ + ref = @store.page name if not ref and name =~ /^[\w.\/]+$/ ref = nil if RDoc::Alias === ref # external alias, can't link to it diff --git a/lib/rdoc/store.rb b/lib/rdoc/store.rb index c6cf7ef27f..376912bee9 100644 --- a/lib/rdoc/store.rb +++ b/lib/rdoc/store.rb @@ -723,7 +723,7 @@ def modules_hash # Returns the RDoc::TopLevel that is a text file and has the given +name+ def page(name) - @text_files_hash.each_value.find do |file| + @files_hash.each_value.find do |file| file.page_name == name or file.base_name == name end end diff --git a/test/rdoc/rdoc_cross_reference_test.rb b/test/rdoc/rdoc_cross_reference_test.rb index 4f24fd7700..e536a67a89 100644 --- a/test/rdoc/rdoc_cross_reference_test.rb +++ b/test/rdoc/rdoc_cross_reference_test.rb @@ -115,7 +115,7 @@ def test_resolve_class end def test_resolve_file - refute_ref 'xref_data.rb' + assert_ref @top_level, 'xref_data.rb' end def test_resolve_method diff --git a/test/rdoc/rdoc_top_level_test.rb b/test/rdoc/rdoc_top_level_test.rb index 385860517b..a785abf06e 100644 --- a/test/rdoc/rdoc_top_level_test.rb +++ b/test/rdoc/rdoc_top_level_test.rb @@ -110,12 +110,7 @@ def test_base_name end def test_display_eh - refute @top_level.display? - - page = @store.add_file 'README.txt' - page.parser = RDoc::Parser::Simple - - assert page.display? + assert @top_level.display? end def test_eql_eh From 376715093d0abe3dcd4fb00789aeee03720e9853 Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Wed, 6 Aug 2025 16:01:35 -0700 Subject: [PATCH 2/3] Add example of using rdoc-ref to link to file --- doc/rdoc/markup_reference.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/rdoc/markup_reference.rb b/doc/rdoc/markup_reference.rb index ee585b2497..03b1e37ffa 100644 --- a/doc/rdoc/markup_reference.rb +++ b/doc/rdoc/markup_reference.rb @@ -991,6 +991,7 @@ # generates baz[rdoc-ref:RDoc::MarkupReference#dummy_attribute]. # - Alias: bad[rdoc-ref:RDoc::MarkupReference#dummy_instance_alias] # generates bad[rdoc-ref:RDoc::MarkupReference#dummy_instance_alias]. +# - File: README[rdoc-ref:README.rdoc] generates README[rdoc-ref:README.rdoc]. # # If the referenced item does not exist, no link is generated # and entire rdoc-ref: square-bracketed clause is removed From 45c45d720a35bc657e2d4ac347206147e10d5bac Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Wed, 6 Aug 2025 16:01:52 -0700 Subject: [PATCH 3/3] Fix comment --- lib/rdoc/store.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rdoc/store.rb b/lib/rdoc/store.rb index 376912bee9..57429e6aad 100644 --- a/lib/rdoc/store.rb +++ b/lib/rdoc/store.rb @@ -720,7 +720,7 @@ def modules_hash end ## - # Returns the RDoc::TopLevel that is a text file and has the given +name+ + # Returns the RDoc::TopLevel that is a file and has the given +name+ def page(name) @files_hash.each_value.find do |file|