123456789_123456789_123456789_123456789_123456789_

Class: RDoc::Markup::ToHtmlCrossref

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, ToHtml, Formatter
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

::RDoc::Text - Included

MARKUP_FORMAT, TO_HTML_CHARACTERS

ToHtml - Inherited

LIST_TYPE_TO_HTML

Class Method Summary

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

ToHtml - Inherited

#code_object

The ::RDoc::CodeObject HTML is being generated for.

#from_path

Path to this document for relative links.

#in_list_entry, #list, #res

Formatter - Inherited

#in_tt?

Are we currently inside tt tags?

Instance Method Summary

ToHtml - Inherited

#accept_blank_line

Adds blank_line to the output.

#accept_block_quote

Adds block_quote to the output.

#accept_heading

Adds heading to the output.

#accept_list_end

Finishes consumption of list

#accept_list_item_end

Finishes consumption of list_item

#accept_list_item_start

Prepares the visitor for consuming list_item

#accept_list_start

Prepares the visitor for consuming list

#accept_paragraph

Adds paragraph to the output.

#accept_raw

Adds raw to the output.

#accept_rule

Adds rule to the output.

#accept_verbatim

Adds verbatim to the output.

#convert_string

CGI-escapes text

#end_accepting

Returns the generated output.

#gen_url

Generate a link to url with content text.

#handle_special_HARD_BREAK

special is a <br>.

#handle_special_HYPERLINK

special is a potential link.

#handle_special_RDOCLINK

special is an rdoc-schemed link that will be converted into a hyperlink.

#handle_special_TIDYLINK

This special is a link where the label is different from the URL label[url] or {url long label}.

#html_list_name

Determines the HTML list element for list_type and open_tag

#init_tags

Maps attributes to HTML tags.

#list_end_for

Returns the HTML end-tag for list_type

#list_item_start

Returns the HTML tag for list_type, possible using a label from list_item

#parseable?

Returns true if text is valid ruby syntax.

#start_accepting

Prepares the visitor for HTML generation.

#to_html

Converts item to HTML using Text#to_html

#handle_RDOCLINK

These methods handle special markup added by #add_special.

::RDoc::Text - Included

#expand_tabs

Expands tab characters in text to eight spaces.

#flush_left

Flush text left based on the shortest line.

#markup

Convert a string in markup format into HTML.

#normalize_comment

Strips hashes, expands tabs then flushes text to the left.

#parse

Normalizes text then builds a Document from it.

#snippet

The first limit characters of text as HTML.

#strip_hashes

Strips leading # characters from text

#strip_newlines

Strips leading and trailing n characters from text

#strip_stars

Strips /* */ style comments.

#to_html

Converts ampersand, dashes, ellipsis, quotes, copyright and registered trademark symbols in text to properly encoded characters.

#wrap

Wraps txt to line_len

Formatter - Inherited

#accept_document

Adds document to the output.

#add_special_RDOCLINK

Adds a special for links of the form rdoc-…:

#add_special_TIDYLINK

Adds a special for links of the form <text> and <#add_tag

Add a new set of tags for an attribute.

#annotate

Allows tag to be decorated with additional information.

#convert

Marks up content

#convert_flow

Converts flow items flow

#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 item on res

#on_tags

Turns on tags for item on res

#parse_url

Extracts and a scheme, url and an anchor id from url and returns them.

#tt?

Is tag a tt tag?

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.

Raises:

  • (ArgumentError)
[ GitHub ]

  
# File 'lib/rdoc/markup/to_html_crossref.rb', line 32

def initialize(options, from_path, context, markup = nil)
  raise ArgumentError, 'from_path cannot be nil' if from_path.nil?

  super options, 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

[ GitHub ]

  
# File 'lib/rdoc/markup/to_html_crossref.rb', line 19

attr_accessor :context

#show_hash (rw)

Should we show '#' characters on method references?

[ GitHub ]

  
# File 'lib/rdoc/markup/to_html_crossref.rb', line 24

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.

[ GitHub ]

  
# File 'lib/rdoc/markup/to_html_crossref.rb', line 52

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.

[ GitHub ]

  
# File 'lib/rdoc/markup/to_html_crossref.rb', line 119

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.

[ GitHub ]

  
# File 'lib/rdoc/markup/to_html_crossref.rb', line 71

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