Class: RDoc::Markup::ToLaTeX_Crossref

Inherits:
ToLaTeX
  • Object
show all
Defined in:
lib/rdoc/markup/to_latex_crossref.rb

Overview

Class adding cross-referencing facility to the RDoc::Markup::ToLaTeX class. If using this class instead of RDoc::Markup::ToLaTeX, names of classes and modules inside descriptions are recognized as well as rdoc-ref links, which have the following form:

rdoc-ref: WhatYouWantToReference

For information on how to use this class, see it’s superclass RDoc::Markup::ToLaTeX.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, heading_level = 0, inputencoding = "UTF-8", show_hash = false, show_pages = true, hyperlink_all = false, markup = nil) ⇒ ToLaTeX_Crossref

Creates a new instance of this class.

Parameters

context

The RDoc::Context from which references will be

resolved relatively.
show_hash

Wheather or not to show hash signs # in front of

methods if present.
heading_level

(0) Base level for LaTeX headings. This is useful

to ensure logical smaller parts get smaller
headings; see also RDoc::Markup::ToLaTeX for
more information.
hyperlink_all

(false) If true, tries to hyperlink everything that

looks like a method name. If false, just hyperlink
references with mixed-case or uppercase words or
references starting with # or ::.
markup

TODO.

Return value

The newly created instance.

Example

f = RDoc::Markup::ToLaTeX_Crossref.new(a_rdoc_toplevel, false)


59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/rdoc/markup/to_latex_crossref.rb', line 59

def initialize(context, heading_level = 0, inputencoding = "UTF-8", show_hash = false, show_pages = true, hyperlink_all = false, markup = nil)
  super(heading_level, inputencoding, markup)

  @context           = context
  @show_hash         = show_hash
  @show_pages        = show_pages
  @hyperlink_all     = hyperlink_all
  @crossref_resolver = RDoc::CrossReference.new(@context)
  
  if @hyperlink_all
    @markup.add_special(RDoc::CrossReference::ALL_CROSSREF_REGEXP, :CROSSREF)
  else
    @markup.add_special(RDoc::CrossReference::CROSSREF_REGEXP, :CROSSREF)
  end
  
  @markup.add_special(/rdoc-ref:\S\w/, :HYPERLINK)
end

Instance Attribute Details

#contextObject

RDoc::Context this formatter resolves it’s references from.



38
39
40
# File 'lib/rdoc/markup/to_latex_crossref.rb', line 38

def context
  @context
end

Instance Method Details

#handle_special_CROSSREF(special) ⇒ Object

Handles encountered cross references.



105
106
107
108
109
110
111
112
113
114
# File 'lib/rdoc/markup/to_latex_crossref.rb', line 105

def handle_special_CROSSREF(special)
  #If we aren’t instructed to try resolving all possibilities,
  #we won’t resolve all-lowercase words (which may be false
  #positives not meant to be a reference).
  if !@hyperlink_all and special.text =~ /^[a-z]+$/
    return escape(enc(special.text))
  end

  make_crossref(enc(special.text))
end

Adds handling of encountered rdoc-ref links to the HYPERLINK handler of the ToLaTeX formatter.



118
119
120
121
# File 'lib/rdoc/markup/to_latex_crossref.rb', line 118

def handle_special_HYPERLINK(special)
  return make_crossref($') if enc(special.text) =~ /^rdoc-ref:/
  super
end

Wheather or not this formatter tries to resolve even words that may not be references (such as “new”), i.e. those with no method prefix # or :: in front and all in lowercase.

Return value

Either true or false.

Example

f.hyperlink_all? #=> false

Returns:

  • (Boolean)


100
101
102
# File 'lib/rdoc/markup/to_latex_crossref.rb', line 100

def hyperlink_all?
  @hyperlink_all
end

#show_hash?Boolean Also known as: show_hashes?

call-seq:

show_hash?()   ==> bool
show_hashes?() ==> bool

Wheather or not the hash signs # are shown in front of methods.

Return value

Either true or false.

Example

f.show_hashes? #=> true

Returns:

  • (Boolean)


87
88
89
# File 'lib/rdoc/markup/to_latex_crossref.rb', line 87

def show_hash?
  @show_hash
end