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
-
ALL_CROSSREF_REGEXP =
Internal use only
# File 'lib/rdoc/markup/to_html_crossref.rb', line 10RDoc::CrossReference::ALL_CROSSREF_REGEXP
-
CLASS_REGEXP_STR =
Internal use only
# File 'lib/rdoc/markup/to_html_crossref.rb', line 11RDoc::CrossReference::CLASS_REGEXP_STR
-
CROSSREF_REGEXP =
Internal use only
# File 'lib/rdoc/markup/to_html_crossref.rb', line 12RDoc::CrossReference::CROSSREF_REGEXP
-
METHOD_REGEXP_STR =
Internal use only
# File 'lib/rdoc/markup/to_html_crossref.rb', line 13RDoc::CrossReference::METHOD_REGEXP_STR
::RDoc::Text
- Included
MARKUP_FORMAT, SPACE_SEPARATED_LETTER_CLASS, TO_HTML_CHARACTERS
ToHtml
- Inherited
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 |
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 |
#from_path | Path to this document for relative links. |
#in_list_entry, #list, #res |
::RDoc::Text
- Included
#language | The language for this text. |
Formatter
- Inherited
#in_tt? | Are we currently inside tt tags? |
Instance Method Summary
-
#cross_reference(name, text = nil, code = true)
Creates a link to the reference
name
if the name exists. -
#gen_url(url, text)
Generates links for
rdoc-ref:
scheme URLs and allowsToHtml
to handle other schemes. -
#handle_regexp_CROSSREF(target)
We’re invoked when any text matches the CROSSREF pattern.
-
#handle_regexp_HYPERLINK(target)
Handles
rdoc-ref:
scheme links and allowsToHtml
to handle other schemes. -
#handle_regexp_RDOCLINK(target)
target
is an rdoc-schemed link that will be converted into a hyperlink. -
#link(name, text, code = true)
Creates an HTML link to
name
with the giventext
. - #init_link_notation_regexp_handlings Internal use only
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_table | Adds |
#accept_verbatim | Adds |
#convert_string | CGI-escapes |
#end_accepting | Returns the generated output. |
#gen_url | Generate a link to |
#handle_regexp_HARD_BREAK |
|
#handle_regexp_HYPERLINK |
|
#handle_regexp_RDOCLINK |
|
#handle_regexp_TIDYLINK | This |
#html_list_name | Determines the HTML list element for |
#init_link_notation_regexp_handlings | Adds regexp handlings about link notations. |
#init_regexp_handlings | Adds regexp handlings. |
#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 |
#handle_RDOCLINK |
::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_regexp_handling_RDOCLINK | Adds a regexp handling for links of the form rdoc-…: |
#add_regexp_handling_TIDYLINK | Adds a regexp handling for links of the form |
#add_tag | Add a new set of tags for an attribute. |
#annotate | Allows |
#convert | Marks up |
#convert_flow | Converts flow items |
#convert_regexp_handling | Converts added regexp handlings. |
#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 32
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 @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 19
attr_accessor :context
#show_hash (rw)
Should we show ‘#’ characters on method references?
# File 'lib/rdoc/markup/to_html_crossref.rb', line 24
attr_accessor :show_hash
Instance Method Details
#cross_reference(name, text = nil, code = true)
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 61
def cross_reference name, text = nil, code = true lookup = name name = name[1..-1] unless @show_hash if name[0, 1] == '#' if !(name.end_with?('+@', '-@')) and name =~ /(.*[^#:])@/ text ||= "#{CGI.unescape $'} at <code>#{$1}</code>" code = false else text ||= name end link lookup, text, code 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 131
def gen_url url, text return super unless url =~ /\Ardoc-ref:/ name = $' cross_reference name, text, name == text end
#handle_regexp_CROSSREF(target)
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 83
def handle_regexp_CROSSREF(target) name = target.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_regexp_HYPERLINK(target)
Handles rdoc-ref:
scheme links and allows ToHtml
to handle other schemes.
# File 'lib/rdoc/markup/to_html_crossref.rb', line 102
def handle_regexp_HYPERLINK target return cross_reference $' if target.text =~ /\Ardoc-ref:/ super end
#handle_regexp_RDOCLINK(target)
target
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 116
def handle_regexp_RDOCLINK target url = target.text case url when /\Ardoc-ref:/ then cross_reference $' else super end end
#init_link_notation_regexp_handlings
# File 'lib/rdoc/markup/to_html_crossref.rb', line 46
def init_link_notation_regexp_handlings add_regexp_handling_RDOCLINK # The crossref must be linked before tidylink because Klass.method[:sym] # will be processed as a tidylink first and will be broken. crossref_re = @options.hyperlink_all ? ALL_CROSSREF_REGEXP : CROSSREF_REGEXP @markup.add_regexp_handling crossref_re, :CROSSREF add_regexp_handling_TIDYLINK end
#link(name, text, code = true)
Creates an HTML link to name
with the given text
.
# File 'lib/rdoc/markup/to_html_crossref.rb', line 141
def link name, text, code = true if !(name.end_with?('+@', '-@')) and name =~ /(.*[^#:])@/ name = $1 label = $' end ref = @cross_reference.resolve name, text case ref when String then ref else path = ref.as_href @from_path if code and RDoc::CodeObject === ref and !(RDoc::TopLevel === ref) text = "<code>#{CGI.escapeHTML text}</code>" end if path =~ /#/ then path << "-label-#{label}" elsif ref.sections and ref.sections.any? { |section| label == section.title } then path << "##{label}" else if ref.respond_to?(:aref) path << "##{ref.aref}-label-#{label}" else path << "#label-#{label}" end end if label "<a href=\"#{path}\">#{text}</a>" end end