Class: RDoc::Markup::ToTableOfContents
- Inherits:
-
Markup::Formatter
- Object
- Markup::Formatter
- RDoc::Markup::ToTableOfContents
- 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
-
#omit_headings_below ⇒ Object
Omits headings with a level less than the given level.
-
#res ⇒ Object
readonly
Output accumulator.
Class Method Summary collapse
-
.to_toc ⇒ Object
Singleton for table-of-contents generation.
Instance Method Summary collapse
-
#accept_document(document) ⇒ Object
Adds
documentto the output, using its heading cutoff if present. -
#accept_heading(heading) ⇒ Object
Adds
headingto the table of contents. -
#end_accepting ⇒ Object
Returns the table of contents.
-
#initialize ⇒ ToTableOfContents
constructor
:nodoc:.
-
#start_accepting ⇒ Object
Prepares the visitor for text generation.
-
#suppressed?(heading) ⇒ Boolean
Returns true if
headingis below the display threshold.
Constructor Details
#initialize ⇒ ToTableOfContents
:nodoc:
29 30 31 32 33 |
# File 'lib/rdoc/markup/to_table_of_contents.rb', line 29 def initialize # :nodoc: super @omit_headings_below = nil end |
Instance Attribute Details
#omit_headings_below ⇒ Object
Omits headings with a level less than the given level.
27 28 29 |
# File 'lib/rdoc/markup/to_table_of_contents.rb', line 27 def omit_headings_below @omit_headings_below end |
#res ⇒ Object (readonly)
Output accumulator
22 23 24 |
# File 'lib/rdoc/markup/to_table_of_contents.rb', line 22 def res @res end |
Class Method Details
.to_toc ⇒ Object
Singleton for table-of-contents generation
15 16 17 |
# File 'lib/rdoc/markup/to_table_of_contents.rb', line 15 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
38 39 40 41 42 |
# File 'lib/rdoc/markup/to_table_of_contents.rb', line 38 def accept_document(document) @omit_headings_below = document.omit_headings_below super end |
#accept_heading(heading) ⇒ Object
Adds heading to the table of contents
47 48 49 |
# File 'lib/rdoc/markup/to_table_of_contents.rb', line 47 def accept_heading(heading) @res << heading unless suppressed? heading end |
#end_accepting ⇒ Object
Returns the table of contents
54 55 56 |
# File 'lib/rdoc/markup/to_table_of_contents.rb', line 54 def end_accepting @res end |
#start_accepting ⇒ Object
Prepares the visitor for text generation
61 62 63 64 |
# File 'lib/rdoc/markup/to_table_of_contents.rb', line 61 def start_accepting @omit_headings_below = nil @res = [] end |
#suppressed?(heading) ⇒ Boolean
Returns true if heading is below the display threshold
69 70 71 72 73 |
# File 'lib/rdoc/markup/to_table_of_contents.rb', line 69 def suppressed?(heading) return false unless @omit_headings_below heading.level > @omit_headings_below end |