Class: RDoc::Markup::ToTableOfContents

Inherits:
Formatter
  • Object
show all
Defined in:
lib/rdoc/markup/to_table_of_contents.rb

Overview

Extracts just the RDoc::Markup::Heading elements from a RDoc::Markup::Document to help build a table of contents

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Formatter

#add_regexp_handling_RDOCLINK, #add_regexp_handling_TIDYLINK, #add_tag, #annotate, #convert, #convert_flow, #convert_regexp_handling, #convert_string, #each_attr_tag, gen_relative_url, #ignore, #in_tt?, #off_tags, #on_tags, #parse_url, #tt?, #tt_tag?

Constructor Details

#initializeToTableOfContents

:nodoc:



27
28
29
30
31
# File 'lib/rdoc/markup/to_table_of_contents.rb', line 27

def initialize # :nodoc:
  super nil

  @omit_headings_below = nil
end

Instance Attribute Details

#omit_headings_belowObject

Omits headings with a level less than the given level.



25
26
27
# File 'lib/rdoc/markup/to_table_of_contents.rb', line 25

def omit_headings_below
  @omit_headings_below
end

#resObject (readonly)

Output accumulator



20
21
22
# File 'lib/rdoc/markup/to_table_of_contents.rb', line 20

def res
  @res
end

Class Method Details

.to_tocObject

Singleton for table-of-contents generation



13
14
15
# File 'lib/rdoc/markup/to_table_of_contents.rb', line 13

def self.to_toc
  @to_toc ||= new
end

Instance Method Details

#accept_document(document) ⇒ Object

Adds document to the output, using its heading cutoff if present



36
37
38
39
40
# File 'lib/rdoc/markup/to_table_of_contents.rb', line 36

def accept_document document
  @omit_headings_below = document.omit_headings_below

  super
end

#accept_heading(heading) ⇒ Object

Adds heading to the table of contents



45
46
47
# File 'lib/rdoc/markup/to_table_of_contents.rb', line 45

def accept_heading heading
  @res << heading unless suppressed? heading
end

#end_acceptingObject

Returns the table of contents



52
53
54
# File 'lib/rdoc/markup/to_table_of_contents.rb', line 52

def end_accepting
  @res
end

#start_acceptingObject

Prepares the visitor for text generation



59
60
61
62
# File 'lib/rdoc/markup/to_table_of_contents.rb', line 59

def start_accepting
  @omit_headings_below = nil
  @res = []
end

#suppressed?(heading) ⇒ Boolean

Returns true if heading is below the display threshold

Returns:

  • (Boolean)


67
68
69
70
71
# File 'lib/rdoc/markup/to_table_of_contents.rb', line 67

def suppressed? heading
  return false unless @omit_headings_below

  heading.level > @omit_headings_below
end