Class: RDoc::Markup::ToHtmlCrossref
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
|
|
Instance Chain:
|
|
Inherits: |
RDoc::Markup::ToHtml
|
Defined in: | lib/rdoc/markup/to_html_crossref.rb |
Overview
Subclass of the ToHtml class that supports looking up method names, classes, etc to create links. ::RDoc::CrossReference is used to generate those links based on the current context.
Constant Summary
Class Method Summary
-
.new(options, from_path, context, markup = nil) ⇒ ToHtmlCrossref
constructor
Creates a new crossref resolver that generates links relative to #context which lives at
from_path
in the generated files.
ToHtml - Inherited
.new | Creates a new formatter that will output HTML. |
Formatter - Inherited
.gen_relative_url | Converts a target url to one that is relative to a given path. |
.new | Creates a new Formatter. |
Instance Attribute Summary
-
#context
rw
::RDoc::CodeObject for generating references.
-
#show_hash
rw
Should we show '#' characters on method references?
ToHtml - Inherited
#code_object | The ::RDoc::CodeObject HTML is being generated for. |
#from_path | Path to this document for relative links. |
Formatter - Inherited
#in_tt? | Are we currently inside tt tags? |
Instance Method Summary
-
#cross_reference(name, text = nil)
Creates a link to the reference
name
if the name exists. -
#gen_url(url, text)
Generates links for
rdoc-ref:
scheme URLs and allows ToHtml to handle other schemes. -
#handle_special_CROSSREF(special)
We're invoked when any text matches the CROSSREF pattern.
-
#handle_special_HYPERLINK(special)
Handles
rdoc-ref:
scheme links and allows ToHtml to handle other schemes. -
#handle_special_RDOCLINK(special)
special
is an rdoc-schemed link that will be converted into a hyperlink. -
#link(name, text)
Creates an HTML link to
name
with the giventext
.
ToHtml - Inherited
#accept_blank_line | Adds |
#accept_block_quote | Adds |
#accept_heading | Adds |
#accept_list_end | Finishes consumption of |
#accept_list_item_end | Finishes consumption of |
#accept_list_item_start | Prepares the visitor for consuming |
#accept_list_start | Prepares the visitor for consuming |
#accept_paragraph | Adds |
#accept_raw | Adds |
#accept_rule | Adds |
#accept_verbatim | Adds |
#convert_string | CGI-escapes |
#end_accepting | Returns the generated output. |
#gen_url | Generate a link to |
#handle_special_HARD_BREAK |
|
#handle_special_HYPERLINK |
|
#handle_special_RDOCLINK |
|
#handle_special_TIDYLINK | This |
#html_list_name | Determines the HTML list element for |
#init_tags | Maps attributes to HTML tags. |
#list_end_for | Returns the HTML end-tag for |
#list_item_start | Returns the HTML tag for |
#parseable? | Returns true if text is valid ruby syntax. |
#start_accepting | Prepares the visitor for HTML generation. |
#to_html | Converts |
::RDoc::Text - Included
#expand_tabs | Expands tab characters in |
#flush_left | Flush |
#markup | Convert a string in markup format into HTML. |
#normalize_comment | Strips hashes, expands tabs then flushes |
#parse | Normalizes |
#snippet | The first |
#strip_hashes | Strips leading # characters from |
#strip_newlines | Strips leading and trailing n characters from |
#strip_stars | Strips /* */ style comments. |
#to_html | Converts ampersand, dashes, ellipsis, quotes, copyright and registered trademark symbols in |
#wrap | Wraps |
Formatter - Inherited
#accept_document | Adds |
|
#add_special_RDOCLINK | Adds a special for links of the form rdoc-…: |
|
#add_special_TIDYLINK | Adds a special for links of the form |
Add a new set of tags for an attribute. |
#annotate | Allows |
|
#convert | Marks up |
|
#convert_flow | Converts flow items |
|
#convert_special | Converts added specials. |
|
#convert_string | Converts a string to be fancier if desired. |
|
#ignore | Use ignore in your subclass to ignore the content of a node. |
|
#off_tags | Turns off tags for |
|
#on_tags | Turns on tags for |
|
#parse_url | Extracts and a scheme, url and an anchor id from |
|
#tt? | Is |
Constructor Details
.new(options, from_path, context, markup = nil) ⇒ ToHtmlCrossref
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. Only method names preceded by '#' or '::' are linked, unless hyperlink_all
is true.
# File 'lib/rdoc/markup/to_html_crossref.rb', line 31
def initialize(, from_path, context, markup = nil) raise ArgumentError, 'from_path cannot be nil' if from_path.nil? super , markup @context = context @from_path = from_path @hyperlink_all = @options.hyperlink_all @show_hash = @options.show_hash crossref_re = @hyperlink_all ? ALL_CROSSREF_REGEXP : CROSSREF_REGEXP @markup.add_special crossref_re, :CROSSREF @cross_reference = RDoc::CrossReference.new @context end
Instance Attribute Details
#context (rw)
::RDoc::CodeObject for generating references
# File 'lib/rdoc/markup/to_html_crossref.rb', line 18
attr_accessor :context
#show_hash (rw)
Should we show '#' characters on method references?
# File 'lib/rdoc/markup/to_html_crossref.rb', line 23
attr_accessor :show_hash
Instance Method Details
#cross_reference(name, text = nil)
Creates a link to the reference name
if the name exists. If text
is given it is used as the link text, otherwise name
is used.
# File 'lib/rdoc/markup/to_html_crossref.rb', line 51
def cross_reference name, text = nil lookup = name name = name[1..-1] unless @show_hash if name[0, 1] == '#' name = "#{CGI.unescape $'} at #{$1}" if name =~ /(.*[^#:])@/ text = name unless text link lookup, text end
#gen_url(url, text)
Generates links for rdoc-ref:
scheme URLs and allows ToHtml to handle other schemes.
# File 'lib/rdoc/markup/to_html_crossref.rb', line 118
def gen_url url, text return super unless url =~ /\Ardoc-ref:/ cross_reference $', text end
#handle_special_CROSSREF(special)
We're invoked when any text matches the CROSSREF pattern. If we find the corresponding reference, generate a link. If the name we're looking for contains no punctuation, we look for it up the module/class chain. For example, ToHtml is found, even without the RDoc::Markup::
prefix, because we look for it in module ::RDoc::Markup first.
# File 'lib/rdoc/markup/to_html_crossref.rb', line 70
def handle_special_CROSSREF(special) name = special.text return name if name =~ /@[\w-]+\.[\w-]/ # labels that look like emails unless @hyperlink_all then # This ensures that words entirely consisting of lowercase letters will # not have cross-references generated (to suppress lots of erroneous # cross-references to "new" in text, for instance) return name if name =~ /\A[a-z]*\z/ end cross_reference name end
#handle_special_HYPERLINK(special)
Handles rdoc-ref:
scheme links and allows ToHtml to handle other schemes.
# File 'lib/rdoc/markup/to_html_crossref.rb', line 89
def handle_special_HYPERLINK special return cross_reference $' if special.text =~ /\Ardoc-ref:/ super end
#handle_special_RDOCLINK(special)
special
is an rdoc-schemed link that will be converted into a hyperlink. For the rdoc-ref scheme the cross-reference will be looked up and the given name will be used.
All other contents are handled by the superclass
# File 'lib/rdoc/markup/to_html_crossref.rb', line 103
def handle_special_RDOCLINK special url = special.text case url when /\Ardoc-ref:/ then cross_reference $' else super end end
#link(name, text)
Creates an HTML link to name
with the given text
.
# File 'lib/rdoc/markup/to_html_crossref.rb', line 127
def link name, text original_name = name if name =~ /(.*[^#:])@/ then name = $1 label = $' end ref = @cross_reference.resolve name, text text = ref.output_name @context if RDoc::MethodAttr === ref and text == original_name case ref when String then ref else path = ref.as_href @from_path if path =~ /#/ then path << "-label-#{label}" elsif ref.sections and ref.sections.any? { |section| label == section.title } then path << "##{label}" else path << "#label-#{label}" end if label "<a href=\"#{path}\">#{text}</a>" end end