class TaskJuggler::TOCEntry

A TOCEntry object is used to store the data of an entry in a TableOfContents object. It stores the section number, the title, the file name and the name of the tag in this file. The tag is optional and may be nil. The object can be turned into an HTML tree.

Attributes

file[R]
number[R]
tag[R]
title[R]

Public Class Methods

new(number, title, file, tag = nil) click to toggle source

Create a TOCEntry object. number: The section number as String, e. g. ‘1.2.3’ or ‘A.3’. title: The section title as String. file: The name of the file. tag: An optional tag within the file.

# File lib/taskjuggler/RichText/TOCEntry.rb, line 32
def initialize(number, title, file, tag = nil)
  @number = number
  @title = title
  @file = file
  @tag = tag
end

Public Instance Methods

to_html() click to toggle source

Return the TOCEntry as equivalent HTML elements. The result is an Array of XMLElement objects.

# File lib/taskjuggler/RichText/TOCEntry.rb, line 41
def to_html
  html = []

  if level == 0
    # A another table line for some extra distance above main chapters.
    html << (tr = XMLElement.new('tr'))
    tr << (td = XMLElement.new('td'))
    td << XMLElement.new('div', 'style' => 'height:10px')
  end

  # Use a different font size depending on the element level.
  fontSizes = [ 20, 17, 15, 14, 14 ]

  tr = XMLElement.new('tr', 'style' => "font-size:#{fontSizes[level]}px;")
  tr << (td = XMLElement.new('td', 'style' => "width:30px;"))
  # Top-level headings have their number in the left column.
  td << XMLText.new(@number) if level == 0

  tr << (td = XMLElement.new('td'))
  if level > 0
    # Lower level headings have their number in the right column with the
    # heading text.
    td << XMLElement.new('span', 'style' => 'padding-right:15px') do
      XMLText.new(@number)
    end
  end
  tag = @tag ? "##{@tag}" : ''
  td << (a = XMLElement.new('a', 'href' => "#{@file}.html#{tag}"))
  a << XMLText.new(@title)
  html << tr

  html
end