Subclass of the RDoc::Markup::ToHtml class that supports looking up words from a context. Those that are found will be hyperlinked.
Regular expression to match class references
1) There can be a ‘' in front of text to suppress any cross-references 2) There can be a ’::’ in front of class names to reference from the
top-level namespace.
3) The method can be followed by parenthesis
Regular expression to match method references.
See CLASS_REGEXP_STR
Regular expressions matching text that should potentially have cross-reference links generated are passed to add_special. Note that these expressions are meant to pick up text for which cross-references have been suppressed, since the suppression characters are removed by the code that is triggered.
Creates a new crossref resolver that generates links relative to context which lives at from_path in the generated files. ’#’ characters on references are removed unless show_hash is true.
# File lib/rdoc/markup/to_html_crossref.rb, line 83
83: def initialize(from_path, context, show_hash)
84: raise ArgumentError, 'from_path cannot be nil' if from_path.nil?
85: super()
86:
87: @markup.add_special(CROSSREF_REGEXP, :CROSSREF)
88:
89: @from_path = from_path
90: @context = context
91: @show_hash = show_hash
92:
93: @seen = {}
94: end
We’re invoked when any text matches the CROSSREF pattern. If we find the corresponding reference, generate a hyperlink. If the name we’re looking for contains no punctuation, we look for it up the module/class chain.
| For example, HyperlinkHtml is found, even without the Generator | prefix, |
because we look for it in module Generator first.
# File lib/rdoc/markup/to_html_crossref.rb, line 103
103: def handle_special_CROSSREF(special)
104: name = special.text
105:
106: # This ensures that words consisting of only lowercase letters will not
107: # have cross-references generated (to suppress lots of erroneous
108: # cross-references to "new" in text, for instance)
109: return name if name =~ /\A[a-z]*\z/
110:
111: return @seen[name] if @seen.include? name
112: lookup = name
113:
114: name = name[1..1] unless @show_hash if name[0, 1] == '#'
115:
116: # Find class, module, or method in class or module.
117: #
118: # Do not, however, use an if/elsif/else chain to do so. Instead, test
119: # each possible pattern until one matches. The reason for this is that a
120: # string like "YAML.txt" could be the txt() class method of class YAML (in
121: # which case it would match the first pattern, which splits the string
122: # into container and method components and looks up both) or a filename
123: # (in which case it would match the last pattern, which just checks
124: # whether the string as a whole is a known symbol).
125:
126: if /#{CLASS_REGEXP_STR}([.#]|::)#{METHOD_REGEXP_STR}/ =~ lookup then
127: container = $1
128: type = $2
129: type = '#' if type == '.'
130: method = "#{type}#{$3}"
131: ref = @context.find_symbol container, method
132: end
133:
134: ref = @context.find_symbol lookup unless ref
135:
136: out = if lookup == '\' then
137: lookup
138: elsif lookup =~ /^\\/ then
139: $'
140: elsif ref and ref.document_self then
141: "<a href=\"#{ref.as_href @from_path}\">#{name}</a>"
142: else
143: name
144: end
145:
146: @seen[name] = out
147:
148: out
149: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.