Skip to content

Commit 6639fe1

Browse files
authored
Allow rdoc-ref to link to non-text files (#1376)
It appears the current behavior of disallowing links to non-text files is deliberate, as it was explicitly added in 3628e19. 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. I was surprised when it didn't work. I want to use this feature in tilt's documentation. If there is a reason to disallow it by default, I think this limitation should be documented. I also I think we should add an option to allow it in that case.
1 parent 171120d commit 6639fe1

File tree

6 files changed

+6
-18
lines changed

6 files changed

+6
-18
lines changed

doc/rdoc/markup_reference.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,7 @@
991991
# generates baz[rdoc-ref:RDoc::MarkupReference#dummy_attribute].
992992
# - Alias: <tt>bad[rdoc-ref:RDoc::MarkupReference#dummy_instance_alias]</tt>
993993
# generates bad[rdoc-ref:RDoc::MarkupReference#dummy_instance_alias].
994+
# - File: <tt>README[rdoc-ref:README.rdoc]</tt> generates README[rdoc-ref:README.rdoc].
994995
#
995996
# If the referenced item does not exist, no link is generated
996997
# and entire <tt>rdoc-ref:</tt> square-bracketed clause is removed

lib/rdoc/code_object/top_level.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,6 @@ def base_name
114114

115115
alias name base_name
116116

117-
##
118-
# Only a TopLevel that contains text file) will be displayed. See also
119-
# RDoc::CodeObject#display?
120-
121-
def display?
122-
text? and super
123-
end
124-
125117
##
126118
# See RDoc::TopLevel::find_class_or_module
127119
#--

lib/rdoc/cross_reference.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def resolve(name, text)
200200
ref = resolve_method name unless ref
201201

202202
# Try a page name
203-
ref = @store.page name if not ref and name =~ /^[\w.]+$/
203+
ref = @store.page name if not ref and name =~ /^[\w.\/]+$/
204204

205205
ref = nil if RDoc::Alias === ref # external alias, can't link to it
206206

lib/rdoc/store.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -720,10 +720,10 @@ def modules_hash
720720
end
721721

722722
##
723-
# Returns the RDoc::TopLevel that is a text file and has the given +name+
723+
# Returns the RDoc::TopLevel that is a file and has the given +name+
724724

725725
def page(name)
726-
@text_files_hash.each_value.find do |file|
726+
@files_hash.each_value.find do |file|
727727
file.page_name == name or file.base_name == name
728728
end
729729
end

test/rdoc/rdoc_cross_reference_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def test_resolve_class
115115
end
116116

117117
def test_resolve_file
118-
refute_ref 'xref_data.rb'
118+
assert_ref @top_level, 'xref_data.rb'
119119
end
120120

121121
def test_resolve_method

test/rdoc/rdoc_top_level_test.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,7 @@ def test_base_name
110110
end
111111

112112
def test_display_eh
113-
refute @top_level.display?
114-
115-
page = @store.add_file 'README.txt'
116-
page.parser = RDoc::Parser::Simple
117-
118-
assert page.display?
113+
assert @top_level.display?
119114
end
120115

121116
def test_eql_eh

0 commit comments

Comments
 (0)