123456789_123456789_123456789_123456789_123456789_

Class: RDoc::Markup::ToTableOfContents

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Formatter
Instance Chain:
self, Formatter
Inherits: RDoc::Markup::Formatter
Defined in: lib/rdoc/markup/to_table_of_contents.rb

Overview

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

Class Method Summary

  • .to_toc

    Singleton for table-of-contents generation.

Formatter - Inherited

.gen_relative_url

Converts a target url to one that is relative to a given path.

.new

Creates a new Formatter.

Instance Attribute Summary

Formatter - Inherited

#in_tt?

Are we currently inside tt tags?

Instance Method Summary

Formatter - Inherited

#accept_document

Adds document to the output.

#add_special_RDOCLINK

Adds a special for links of the form rdoc-…:

#add_special_TIDYLINK

Adds a special for links of the form <text> and <#add_tag

Add a new set of tags for an attribute.

#annotate

Allows tag to be decorated with additional information.

#convert

Marks up content

#convert_flow

Converts flow items flow

#convert_special

Converts added specials.

#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 item on #res

#on_tags

Turns on tags for item on #res

#parse_url

Extracts and a scheme, url and an anchor id from url and returns them.

#tt?

Is tag a tt tag?

Constructor Details

This class inherits a constructor from RDoc::Markup::Formatter

Class Method Details

.to_toc

Singleton for table-of-contents generation

[ GitHub ]

  
# File 'lib/rdoc/markup/to_table_of_contents.rb', line 12

def self.to_toc
  @to_toc ||= new
end

Instance Attribute Details

#omit_headings_below (rw)

Omits headings with a level less than the given level.

[ GitHub ]

  
# File 'lib/rdoc/markup/to_table_of_contents.rb', line 24

attr_accessor :omit_headings_below

#res (readonly)

Output accumulator

[ GitHub ]

  
# File 'lib/rdoc/markup/to_table_of_contents.rb', line 19

attr_reader :res

Instance Method Details

#accept_document(document)

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

[ GitHub ]

  
# 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)

Adds heading to the table of contents

[ GitHub ]

  
# File 'lib/rdoc/markup/to_table_of_contents.rb', line 44

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

#end_accepting

Returns the table of contents

[ GitHub ]

  
# File 'lib/rdoc/markup/to_table_of_contents.rb', line 51

def end_accepting
  @res
end

#start_accepting

Prepares the visitor for text generation

[ GitHub ]

  
# 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

[ GitHub ]

  
# 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