Class: TaskJuggler::TOCEntry

Inherits:
Object
  • Object
show all
Defined in:
lib/taskjuggler/RichText/TOCEntry.rb

Overview

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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(number, title, file, tag = nil) ⇒ TOCEntry

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.



32
33
34
35
36
37
# File 'lib/taskjuggler/RichText/TOCEntry.rb', line 32

def initialize(number, title, file, tag = nil)
  @number = number
  @title = title
  @file = file
  @tag = tag
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



25
26
27
# File 'lib/taskjuggler/RichText/TOCEntry.rb', line 25

def file
  @file
end

#numberObject (readonly)

Returns the value of attribute number.



25
26
27
# File 'lib/taskjuggler/RichText/TOCEntry.rb', line 25

def number
  @number
end

#tagObject (readonly)

Returns the value of attribute tag.



25
26
27
# File 'lib/taskjuggler/RichText/TOCEntry.rb', line 25

def tag
  @tag
end

#titleObject (readonly)

Returns the value of attribute title.



25
26
27
# File 'lib/taskjuggler/RichText/TOCEntry.rb', line 25

def title
  @title
end

Instance Method Details

#to_htmlObject

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



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# 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