Class: 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
document
to the output, using its heading cutoff if present. -
#accept_heading(heading) ⇒ Object
Adds
heading
to 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
heading
is below the display threshold.
Methods inherited from Formatter
#add_special_RDOCLINK, #add_special_TIDYLINK, #add_tag, #annotate, #convert, #convert_flow, #convert_special, #convert_string, gen_relative_url, #ignore, #in_tt?, #off_tags, #on_tags, #parse_url, #tt?
Constructor Details
#initialize ⇒ ToTableOfContents
:nodoc:
26 27 28 29 30 |
# File 'lib/rdoc/markup/to_table_of_contents.rb', line 26 def initialize # :nodoc: super nil @omit_headings_below = nil end |
Instance Attribute Details
#omit_headings_below ⇒ Object
Omits headings with a level less than the given level.
24 25 26 |
# File 'lib/rdoc/markup/to_table_of_contents.rb', line 24 def omit_headings_below @omit_headings_below end |
#res ⇒ Object (readonly)
Output accumulator
19 20 21 |
# File 'lib/rdoc/markup/to_table_of_contents.rb', line 19 def res @res end |
Class Method Details
.to_toc ⇒ Object
Singleton for table-of-contents generation
12 13 14 |
# File 'lib/rdoc/markup/to_table_of_contents.rb', line 12 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
35 36 37 38 39 |
# File 'lib/rdoc/markup/to_table_of_contents.rb', line 35 def accept_document document @omit_headings_below = document.omit_headings_below super end |
#accept_heading(heading) ⇒ Object
Adds heading
to the table of contents
44 45 46 |
# File 'lib/rdoc/markup/to_table_of_contents.rb', line 44 def accept_heading heading @res << heading unless suppressed? heading end |
#end_accepting ⇒ Object
Returns the table of contents
51 52 53 |
# File 'lib/rdoc/markup/to_table_of_contents.rb', line 51 def end_accepting @res end |
#start_accepting ⇒ Object
Prepares the visitor for text generation
58 59 60 61 |
# File 'lib/rdoc/markup/to_table_of_contents.rb', line 58 def start_accepting @omit_headings_below = nil @res = [] end |
#suppressed?(heading) ⇒ Boolean
Returns true if heading
is below the display threshold
66 67 68 69 70 |
# File 'lib/rdoc/markup/to_table_of_contents.rb', line 66 def suppressed? heading return false unless @omit_headings_below heading.level > @omit_headings_below end |