Skip to content

Commit b2f18bf

Browse files
committed
RDoc::CrossReference can now look up pages by name
1 parent 5a4f931 commit b2f18bf

File tree

5 files changed

+37
-18
lines changed

5 files changed

+37
-18
lines changed

TODO.rdoc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
Some file contains some things that might happen in RDoc, or might not
22

3-
=== 3.10
4-
5-
* Figure out why README@Bugs does not work here
6-
73
=== 3.11
84

95
* Reload the RDoc tree from an RI store

lib/rdoc/cross_reference.rb

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,6 @@ def initialize context
116116
def resolve name, text
117117
return @seen[name] if @seen.include? name
118118

119-
# Find class, module, or method in class or module.
120-
#
121-
# Do not, however, use an if/elsif/else chain to do so. Instead, test
122-
# each possible pattern until one matches. The reason for this is that a
123-
# string like "YAML.txt" could be the txt() class method of class YAML (in
124-
# which case it would match the first pattern, which splits the string
125-
# into container and method components and looks up both) or a filename
126-
# (in which case it would match the last pattern, which just checks
127-
# whether the string as a whole is a known symbol).
128-
129119
if /#{CLASS_REGEXP_STR}([.#]|::)#{METHOD_REGEXP_STR}/o =~ name then
130120
type = $2
131121
type = '' if type == '.' # will find either #method or ::method
@@ -150,12 +140,15 @@ def resolve name, text
150140

151141
ref = case name
152142
when /^\\(#{CLASS_REGEXP_STR})$/o then
153-
ref = @context.find_symbol $1
143+
@context.find_symbol $1
154144
else
155-
ref = @context.find_symbol name
145+
@context.find_symbol name
156146
end unless ref
157147

158-
ref = nil if RDoc::Alias === ref # external alias: can't link to it
148+
# Try a page name
149+
ref = RDoc::TopLevel.page name if not ref and name =~ /^\w+$/
150+
151+
ref = nil if RDoc::Alias === ref # external alias, can't link to it
159152

160153
out = if name == '\\' then
161154
name

lib/rdoc/top_level.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,12 @@ def self.new file_name
231231
end
232232
end
233233

234+
def self.page page
235+
@all_files_hash.each_value.find do |file|
236+
file.text? and file.page_name == page
237+
end
238+
end
239+
234240
##
235241
# Removes from +all_hash+ the contexts that are nodoc or have no content.
236242
#
@@ -495,7 +501,7 @@ def search_record
495501
# Is this TopLevel from a text file instead of a source code file?
496502

497503
def text?
498-
@parser.ancestors.include? RDoc::Parser::Text
504+
@parser and @parser.ancestors.include? RDoc::Parser::Text
499505
end
500506

501507
def to_s # :nodoc:

test/test_rdoc_cross_reference.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ def refute_ref name
1616
assert_equal name, @xref.resolve(name, name)
1717
end
1818

19+
def test_resolve_page
20+
page = RDoc::TopLevel.new 'README.txt'
21+
page.parser = RDoc::Parser::Simple
22+
23+
assert_ref page, 'README'
24+
end
25+
1926
def test_resolve_C2
2027
@xref = RDoc::CrossReference.new @c2
2128

test/test_rdoc_top_level.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ def test_class_new
8989
refute_same tl1, tl3
9090
end
9191

92+
def test_class_page
93+
page = RDoc::TopLevel.new 'PAGE.txt'
94+
page.parser = RDoc::Parser::Simple
95+
96+
assert_nil RDoc::TopLevel.page 'no such page'
97+
98+
assert_equal page, RDoc::TopLevel.page('PAGE')
99+
end
100+
92101
def test_class_reset
93102
RDoc::TopLevel.reset
94103

@@ -283,5 +292,13 @@ def test_text_eh
283292
assert simple.text?
284293
end
285294

295+
def test_text_eh_no_parser
296+
refute @xref_data.text?
297+
298+
rd = RDoc::TopLevel.new 'rd_format.rd'
299+
300+
refute rd.text?
301+
end
302+
286303
end
287304

0 commit comments

Comments
 (0)